# Python CircleCI 2.0 configuration file # # Check https://circleci.com/docs/2.0/language-python/ for more details # version: 2 jobs: build: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - image: circleci/python:3.6.4 environment: # environment variables for primary container PIPENV_VENV_IN_PROJECT: true DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ # - image: circleci/postgres:9.4 - image: circleci/python:3.6.4 environment: # environment variables for the Postgres container. POSTGRES_USER: root POSTGRES_DB: circle_test working_directory: ~/repo steps: - checkout # Download and cache dependencies - restore_cache: keys: - v6-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} - v6-dependencies- # fallback to using the latest cache if no exact match is found - run: name: install dependencies command: | export FLASK_APP=autoapp.py pip install -r requirements/dev.txt flask db upgrade flask test - save_cache: paths: - venv key: v6-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} test: docker: # specify the version you desire here # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ - image: postgres:9.6.2-alpine environment: PIPENV_VENV_IN_PROJECT: true DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable POSTGRES_USER: myUsr POSTGRES_PASSOWRD: somePwd POSTGRES_DB: myUsr working_directory: ~/repo steps: - checkout - run: sudo chown -R circleci:circleci /usr/local/bin - run: sudo chown -R circleci:circleci /usr/local/lib/python3.8/site-packages # Download and cache dependencies - restore_cache: keys: - v6-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} - v6-dependencies- # fallback to using the latest cache if no exact match is found - run: name: bd upgrade command: | export FLASK_APP=autoapp.py . venv/bin/activate sleep 1 flask db upgrade environment: CONDUIT_SECRET: 'something-really-secret' FLASK_APP: /home/circleci/repo/autoapp.py DATABASE_URL: postgresql://myUsr:somePwd@localhost:5432/myUsr?sslmode=disable FLASK_DEBUG: 1 # run tests! # this example uses Django's built-in test-runner # other common Python testing frameworks include pytest and nose # https://pytest.org # https://nose.readthedocs.io - run: name: run tests command: | . venv/bin/activate flask test environment: CONDUIT_SECRET: 'something-really-secret' FLASK_APP: /home/circleci/repo/autoapp.py FLASK_DEBUG: 1 DATABASE_URL: postgresql://myUsr:somePwd@localhost:5432/myUsr?sslmode=disable - save_cache: paths: - venv key: v6-dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} 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 main docker-build-and-push: working_directory: /dockerapp docker: - image: docker:17.05.0-ce-git steps: - checkout - setup_remote_docker - run: name: build app for docker command: | docker build --cache-from=app -t app . - deploy: name: we publish the app on my docker hub environment: CIRCLE_BUILD_NUM: 1 command: | docker login -e $DOCKER_HUB_EMAIL -u $DOCKER_HUB_USER_ID -p $DOCKER_HUB_PWD docker tag app $DOCKER_HUB_USER_ID/backend_final:$CIRCLE_BUILD_NUM docker tag app $DOCKER_HUB_USER_ID/backend_final:latest docker push $DOCKER_HUB_USER_ID/backend_final:$CIRCLE_BUILD_NUM docker push $DOCKER_HUB_USER_ID/backend_final:latest workflows: version: 2 build-back-deploy: jobs: - build - back-deploy-heroku: requires: - build - docker-build-and-push: requires: - back-deploy-heroku