Dev Environment
Basic dev environment for python/javascript apps.
Currently supports:
- Python
- Flask
- Flake8
- Pytest
- Javascript
- ES6
- Flow
- Jest
- React
- ESLint
- Packaging
- Flow removal
- ES5 transpiling
- Bundling
- Minification
- Continuous integration
- Travis
Docker containers are used for development, testing and deployment. Containers can be built locally that mimic test and production environments.
Work flow
An example contribution work flow is:
git clone https://github.com/robschlub/dev_environment/
- Create branch
- Use local environments for development:
./start_env.sh dev
- Interactive dev environment to do manual type and lint checking, testing, building and manually running flask app
- To run app, use
flask run --host=0.0.0.0
and access it through a browser atlocalhost:5002
.
./start_env.sh dev-server
- Automatic environment that hosts app at
localhost:5003
- Automatically rebuilds and rehosts app each time a source file is changed
- Browser cache might need to be cleared each time
- Safari: CMD+OPT+e, then CMD+r
- Chrome: Hold click the refresh icon and select
Empty Cache and Reload
(only works in developer mode)
- Automatic environment that hosts app at
./start_env.sh stage
- Automatic environment that runs flask and hosts app at
localhost:5001
- Container has no npm packages installed, and only the python packages needed for production.
- Automatic environment that runs flask and hosts app at
./start_env.sh prod
- Automatic environment that runs nginx and hosts app at
localhost:5000
- Container has no npm packages installed, and only the python packages needed for production.
- Automatic environment that runs nginx and hosts app at
- Contribute to source code
- Javascript, HTML and CSS are in dev_environment/src
- Python is in dev_environment/app
- Most app source contributions should also include test contributions
- In interactive dev environment (
./start_env.sh dev
):- Perform type and linting checks:
- Javascript:
npm run flow
npm run lint
- Python:
flake8
- Javascript:
- Perform unit testing:
- Javascript:
npm run jest
- Python:
pytest
- Javascript:
- Package Javascript:
npm run webpack -- --env.mode=dev
- similar to
./build.sh dev
below
- similar to
npm run webpack -- --env.mode=stage
- similar to
./build.sh stage
below
- similar to
npm run webpack -- --env.mode=prod
ornpm run build
- similar to
./build.sh prod
below
- similar to
- Perform type and linting checks:
- All type and lint checking, testing and building can also be tested at once using the
build.sh
script. This is the same script as is used in Travis CI- In a terminal window:
./build.sh dev
- Lint, test and build app where:- JS is not minified
- Reac is in development mode
./build.sh stage
- Lint, test and build app where:- JS is minified
- JS source maps are included
- React is in production mode
./build.sh prod
- Lint, test and build app where:- JS is minified
- JS source maps are not included
- React is in production mode
- This same script is run in CI and deployment
- In a terminal window:
- If all is passing, then create pull request to merge into branch
release-candidate
- Once merged, the new app will be hosted on a dev website
- If all is ok, create pull request to merge
release-candidate
intomaster
- Once merged in master, the new app will be deployed to the production site
Setting up sublime
Setting up port forwarding:
forward port external 4000 to local 5000
echo " rdr pass inet proto tcp from any to any port 4000 -> 127.0.0.1 port 5003 " | sudo pfctl -ef -
To stop port forwarding:
sudo pfctl -F all -f /etc/pf.conf
To see all current rules:
sudo pfctl -s nat
How to run a production build locally:
Start dev container and run production webpack script
./start_env.sh dev
webpack --env.mode=prod
Exit container
Start production container
./start_env.sh prod
Can be accessed from localhost:5000/ in the browser