diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..144172a --- /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 sgttabouret --password-stdin + 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 diff --git a/migrations/env.py b/migrations/env.py index 79b8174..9452179 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -23,8 +23,8 @@ logger = logging.getLogger('alembic.env') # target_metadata = mymodel.Base.metadata from flask import current_app config.set_main_option( - 'sqlalchemy.url', current_app.config.get( - 'SQLALCHEMY_DATABASE_URI').replace('%', '%%')) + 'sqlalchemy.url', + str(current_app.extensions['migrate'].db.engine.url).replace('%', '%%')) target_metadata = current_app.extensions['migrate'].db.metadata # other values from the config, defined by the needs of env.py, diff --git a/migrations/versions/2267f00a4594_.py b/migrations/versions/ddd6dd49baff_.py similarity index 97% rename from migrations/versions/2267f00a4594_.py rename to migrations/versions/ddd6dd49baff_.py index 3b7f481..9ba8232 100644 --- a/migrations/versions/2267f00a4594_.py +++ b/migrations/versions/ddd6dd49baff_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 2267f00a4594 +Revision ID: ddd6dd49baff Revises: -Create Date: 2020-01-04 15:20:33.461410 +Create Date: 2021-01-12 14:38:07.982541 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '2267f00a4594' +revision = 'ddd6dd49baff' down_revision = None branch_labels = None depends_on = None