version: 2 jobs: build: docker: - image: circleci/python:3.7.9-stretch-browsers steps: - checkout - restore_cache: key: deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} - run: name: Install dependencies in a python venv command: | python3 -m venv venv . venv/bin/activate pip install -r requirements/dev.txt - save_cache: key: deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} paths: - "venv" deploy_heroku: docker: - image: buildpack-deps:trusty steps: - checkout - run: name: Heroku deploy command: | git config --global push.default matching git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_PROJECT_NAME.git main - run: name: Smoke test command: | HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://$HEROKU_PROJECT_NAME.herokuapp.com/api/articles` if [ "$HTTPCODE" -ne 200 ];then echo "heroku app not responding, failing deploy" exit 1 fi test: docker: - image: circleci/python:3.7.9-stretch-browsers environment: FLASK_APP: autoapp.py CONDUIT_SECRET: $CONDUIT_SECRET FLASK_DEBUG: 1 DATABASE_URL: postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/$POSTGRES_DB - image: circleci/postgres:9.5.19-alpine environment: POSTGRES_USER: $POSTGRES_USER POSTGRES_DB: $POSTGRES_DB POSTGRES_PASSWORD: $POSTGRES_PASSWORD steps: - checkout - restore_cache: key: deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} - run: name: Wait for postgres command: dockerize -wait tcp://localhost:5432 -timeout 1m - run: name: running test command: | . venv/bin/activate flask db upgrade flask test push_docker: environment: IMAGE_NAME: grennrich/devoptpfinal-back docker: - image: circleci/buildpack-deps:stretch steps: - attach_workspace: at: /tmp/workspace - setup_remote_docker - run: docker load -i /tmp/workspace/image.tar - run: name: Login and push to DockerHub command: | docker login -u grennrich -p $DOCKER_HUB_PASSWORD docker tag $IMAGE_NAME:app $IMAGE_NAME:$CIRCLE_BUILD_NUM docker tag $IMAGE_NAME:app $IMAGE_NAME:latest docker push $IMAGE_NAME:$CIRCLE_BUILD_NUM docker push $IMAGE_NAME:latest build_docker: environment: IMAGE_NAME: grennrich/devoptpfinal-back docker: - image: circleci/buildpack-deps:stretch steps: - checkout - setup_remote_docker - run: docker image build --tag $IMAGE_NAME:app . - run: docker save -o image.tar $IMAGE_NAME - persist_to_workspace: root: . paths: - ./image.tar workflows: version: 2 build-test: jobs: - build - test: requires: - build - build_docker: context: Docker requires: # - test - build - push_docker: requires: - build_docker context: Docker - deploy_heroku: requires: # - test - build context: heroku