diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..b73c233 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,121 @@ +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" + 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 + build_docker: + environment: + IMAGE_NAME: sgttabouret/devops-final-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 + push_docker: + environment: + IMAGE_NAME: sgttabouret/devops-final-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: | + echo "$DOCKERHUB_PASS" | docker login --username skinkan --password-159753 + 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 + 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 +workflows: + version: 2 + build-test: + jobs: + - build + # - test: + # context: + # - back_final + # requires: + # - build + - build_docker: + requires: + # - test + - build + context: + - back_final + - push_docker: + requires: + - build_docker + context: + - back_final + filters: + branches: + only: + - main + - deploy_heroku: + requires: + # - test + - build + context: + - back_final + filters: + branches: + only: + - main \ No newline at end of file