version: 2.1 jobs: build: docker: - image: circleci/python:3.9-buster-node-browsers steps: - checkout - restore_cache: key: deps-{{ checksum "requirements/dev.txt"}}-{{ .Environment.CACHE_VERSION }} - run: name: Install dependencies command: | python3 -m venv venv . venv/bin/activate pip install -r requirements/dev.txt - save_cache: key: deps-{{ checksum "requirements/dev.txt"}}-{{ .Environment.CACHE_VERSION }} paths: - "venv" test: docker: - image: circleci/python:3.9-stretch-browsers environment: DATABASE_URL: postgresql://myUsr:somePwd@localhost:5432/psdb FLASK_APP: autoapp.py CONDUIT_SECRET: 'something-really-secret' FLASK_DEBUG: 1 - image: circleci/postgres:9.6.2-alpine environment: POSTGRES_USER: myUsr POSTGRES_DB: psdb POSTGRES_PASSWORD: somePwd steps: - checkout - restore_cache: key: deps-{{ checksum "requirements/dev.txt"}}-{{ .Environment.CACHE_VERSION }} - run: name: Waiting for postgresql command : dockerize -wait tcp://localhost:5432 -timeout 1m - run: name: Launching tests command: | . venv/bin/activate flask db upgrade flask test Heroku: docker: - image : buildpack-deps:trusty steps: - checkout - run: name: Deploy main to heroku command: | git config --global push.default matching git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git main - run: name: Smoke test command: | HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://$HEROKU_APP_NAME.herokuapp.com/api/articles` if [ "$HTTPCODE" -ne 200 ];then echo "heroku app not responding, failing deploy" exit 1 fi Docker: docker: - image: circleci/buildpack-deps:stretch steps: - checkout - setup_remote_docker - run: name: dockerize the app command: | docker build --cache-from=app -t app . - persist_to_workspace: root: . paths: - ./image.tar - attach_workspace: at: /tmp/workspace - run: docker load -i /tmp/workspace/image.tar - run: name: Publish app to docker hub command: | docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD docker tag app $DOCKER_HUB_USERNAME/TP_FINAL_DEVOPS:$CIRCLE_BUILD_NUM docker tag app $DOCKER_HUB_USERNAME/TP_FINAL_DEVOPS:latest docker push $DOCKER_HUB_USERNAME/TP_FINAL_DEVOPS:$CIRCLE_BUILD_NUM docker push $DOCKER_HUB_USERNAME/TP_FINAL_DEVOPS:latest workflows: build_test_deploy: jobs: - build - test: requires: - build - Heroku: context: Heroku requires: - build # - test - Docker: context: Docker requires: - build # - test