version: 2.1 jobs: build: docker: - image: circleci/python:3.7.4 steps: - checkout - run: name: install pyth dependencies command: | python3 -m venv venv . venv/bin/activate pip install -r requirements/dev.txt environment: CONDUIT_SECRET: 'something-really-secret' FLASK_APP: autoapp.py FLASK_DEBUG: 1 - save_cache: paths: - ./venv key: v3-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} - store_artifacts: path: test-reports/ destination: tr1 - store_test_results: path: test-reports/ start_test: docker: - image: circleci/python:3.7.4 environment: DATABASE_URL: postgresql://myuser:somePwd@localhost:5432/mydb - image: circleci/postgres:9.6.5 environment: POSTGRES_DB: mydb POSTGRES_USER: myuser POSTGRES_PASSWORD: somePwd steps: - checkout - restore_cache: keys: - v3-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} - v3-dependencies- - run: name: Run unit tests command: | python3 -m venv venv . venv/bin/activate python3 autoapp.py back-deploy-heroku: docker: - image: buildpack-deps:trusty steps: - checkout - run: name: Heroku Deploy command: | git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:main - run: name: Smoke test command: ./testbackend.sh buildandpush_dockerhub: docker: - image: docker:17.05.0-ce-git steps: - checkout - setup_remote_docker - run: name: Build application Docker image command: | docker build --cache-from=app -t app . - deploy: name: Publish application to docker hub command: | docker login -e $DOCKER_HUB_EMAIL -u $DOCKER_HUB_USER -p $DOCKER_HUB_PWD docker tag app $DOCKER_HUB_USER/$DOCKER_HUB_APP:$CIRCLE_BUILD_NUM docker tag app $DOCKER_HUB_USER/$DOCKER_HUB_APP:latest docker push $DOCKER_HUB_USER/$DOCKER_HUB_APP:$CIRCLE_BUILD_NUM docker push $DOCKER_HUB_USER/$DOCKER_HUB_APP:latest - store_artifacts: path: test-reports/ destination: tr1 - store_test_results: path: test-reports/ workflows: version: 2.1 build_circleci: jobs: - build - start_test: requires: - build - back-deploy-heroku: requires: - start_test - buildandpush_dockerhub: requires: - back-deploy-heroku