Link (allow 20 seconds for it to load if server has idled) https://boilerplate-dj-react.herokuapp.com/#/login
- Docker
- Django
- React
- Redux
- Webpack
- SQLite3 / Postgres
- Knox (auth)
- Axios (api calls)
- /frontend <- contains all of the React frontend code
- /app <- main python application
- /accounts <- code related to users/auth
- All of the other files should be self explanatory - reach out if you get stuck though
Note: The code will change between local/deployed version in the following files:
Dockerfile
heroku is: CMD python3 manage.py runserver 0.0.0.0:$PORT
local is: CMD python3 manage.py runserver
docker-compose.yaml
heroku is: command: python manage.py runserver 0.0.0.0:$PORT --noreload
local is: command: python manage.py runserver
- Follow the steps here to spin up a local docker container running Django https://docs.docker.com/compose/django/
- Replace the contents of your project folder with the contents of this repository
- Because your code has changed, run
docker-compose build
docker-compose up
- The latest build is ready and should be running locally on localhost:8000
- Run the following commands to deploy to Heroku
(you will need Heroku CLI installed https://devcenter.heroku.com/articles/heroku-cli#download-and-install)
heroku container:login
heroku create your-app-name-goes-here
heroku container:push web -a your-app-name-goes-here
heroku container:release web -a your-app-name-goes-here
- The app will push to Heroku and deploy successfully but it won't work. The reason for this is we need to provision Postgres as an addon
- Install Postgres from your Apps Heroku page > Resources > Search for add ons > Heroku Postgres
- Once provisioned, the app still doesn't work as we will need to run migrations
- Jump into the console More > Run Console and type python manage.py migrate
- Once the migrations have completed, the app is ready to go!
You will need to run webpack locally before pushing to Heroku as the main.js file will contain code relating to your app when webpack was last run.
npm run dev
Check the requirements.txt file and ensure the Docker file has
COPY requirements.txt /code/
RUN pip install -r requirements.txt
Ensure you push and release the latest container to Heroku so your changes are live.
No. Heroku documentation doesn't recommend running a Django web server in Production - you should use something such as NGINX. You'll also need to set the SECRET_KEY in Django to an environment variable.
Sure thing, Fork it over and deploy in <5 minutes 🐳 🐱