After completing the test stage, we next run the release stage, which requires us to perform the following actions:
- Run database migrations
- Collect static files
- Start the application
- Run acceptance tests
The following demonstrates creating a target, called release, in the Makefile:
.PHONY: test release
test:
docker-compose build --pull release
docker-compose build
docker-compose run test
release:
docker-compose up --abort-on-container-exit migrate
docker-compose run app python3 manage.py collectstatic --no-input
docker-compose up --abort-on-container-exit acceptance
Notice that we execute each of the required commands with one minor variation, which is to add the --abort-on-container-exit command to each of the docker-compose up commands. By default, the docker-compose up command will not return a non-zero exit code should any of the container(s) started by the command fail. This flag allows you to override this and specify should any service fail that was started by the docker-compose up command, then Docker Compose should exit with an error. Setting this flag is important if you want your make commands to fail whenever there is an error.