|
|
|
@ -14,80 +14,38 @@ workflows: |
|
|
|
jobs: |
|
|
|
install: |
|
|
|
docker: |
|
|
|
- image: cimg/python:3.9.1 |
|
|
|
- image: circleci/postgres:9.6.2 |
|
|
|
- image: circleci/python:3.9.1 |
|
|
|
- image: circleci/postgres:9.6.5 |
|
|
|
environment: |
|
|
|
POSTGRES_DB: example |
|
|
|
POSTGRES_USER: circleci |
|
|
|
POSTGRES_PASSWORD: somePwd |
|
|
|
POSTGRES_PORT: 5432 |
|
|
|
DATABASE_URL: postgresql://circleci:somePwd@localhost:5432/example |
|
|
|
working_directory: ~/repo |
|
|
|
steps: |
|
|
|
- checkout |
|
|
|
- setup_remote_docker |
|
|
|
- restore_cache: |
|
|
|
keys: |
|
|
|
- dependencies-{{ checksum "requirements/dev.txt" }}-{{ checksum "requirements/prod.txt" }} |
|
|
|
- dependencies- |
|
|
|
- run: |
|
|
|
name: install python and dependencies |
|
|
|
command: | |
|
|
|
python3 -m venv venv |
|
|
|
. venv/bin/activate |
|
|
|
pip install -r requirements/dev.txt |
|
|
|
|
|
|
|
- run: docker container run --name flask_db_test -e POSTGRES_PASSWORD=somePwd -e POSTGRES_USER=myUsr -p 5432:5432 -d postgres |
|
|
|
- run: sleep 1 |
|
|
|
name: Install dependencies |
|
|
|
command: pip install -r requirements/dev.txt |
|
|
|
- run: |
|
|
|
command: pip install sqlalchemy --upgrade && pip install Flask-SQLAlchemy --upgrade |
|
|
|
- run: |
|
|
|
name: db migration |
|
|
|
name: Setup dababase |
|
|
|
environment: |
|
|
|
FLASK_APP: /home/circleci/repo/autoapp.py |
|
|
|
FLASK_DEBUG: 0 |
|
|
|
POSTGRES_USER: postgres |
|
|
|
POSTGRES_DB: bdtest |
|
|
|
POSTGRES_PASSWORD: somePwd |
|
|
|
POSTGRES_PORT: 5432 |
|
|
|
DATABASE_URL: postgresql://postgres:somePwd@localhost:5432/postgres |
|
|
|
command: | |
|
|
|
. venv/bin/activate |
|
|
|
flask db stamp head |
|
|
|
command: flask db upgrade |
|
|
|
- run: |
|
|
|
name: db migration |
|
|
|
name: Flask test |
|
|
|
environment: |
|
|
|
FLASK_APP: /home/circleci/repo/autoapp.py |
|
|
|
FLASK_DEBUG: 0 |
|
|
|
POSTGRES_USER: postgres |
|
|
|
POSTGRES_DB: bdtest |
|
|
|
POSTGRES_PASSWORD: somePwd |
|
|
|
POSTGRES_PORT: 5432 |
|
|
|
DATABASE_URL: postgresql://postgres:somePwd@localhost:5432/postgres |
|
|
|
command: | |
|
|
|
. venv/bin/activate |
|
|
|
flask db migrate |
|
|
|
# - run: |
|
|
|
# name: db upgrade |
|
|
|
# environment: |
|
|
|
# FLASK_APP: /home/circleci/repo/autoapp.py |
|
|
|
# FLASK_DEBUG: 0 |
|
|
|
# POSTGRES_USER: postgres |
|
|
|
# POSTGRES_DB: bdtest |
|
|
|
# POSTGRES_PASSWORD: somePwd |
|
|
|
# POSTGRES_PORT: 5432 |
|
|
|
# DATABASE_URL: postgresql://postgres:somePwd@localhost:5432/postgres |
|
|
|
# command: | |
|
|
|
# . venv/bin/activate |
|
|
|
# flask db upgrade |
|
|
|
# - run: |
|
|
|
# name: flask test |
|
|
|
# environment: |
|
|
|
# FLASK_APP: /home/circleci/repo/autoapp.py |
|
|
|
# FLASK_DEBUG: 0 |
|
|
|
# POSTGRES_USER: postgres |
|
|
|
# POSTGRES_DB: bdtest |
|
|
|
# POSTGRES_PASSWORD: somePwd |
|
|
|
# POSTGRES_PORT: 5432 |
|
|
|
# DATABASE_URL: postgresql://postgres:somePwd@localhost:5432/postgres |
|
|
|
# command: | |
|
|
|
# . venv/bin/activate |
|
|
|
# flask test |
|
|
|
- run: docker container stop flask_db_test |
|
|
|
- run: docker container rm flask_db_test |
|
|
|
- run: unset DATABASE_URL |
|
|
|
command: flask test |
|
|
|
back-deploy-heroku: |
|
|
|
docker: |
|
|
|
- image: buildpack-deps:trusty |
|
|
|
@ -95,11 +53,11 @@ jobs: |
|
|
|
- checkout |
|
|
|
- run: |
|
|
|
name: Heroku Deploy |
|
|
|
command: git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:main |
|
|
|
command: git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:main -f |
|
|
|
- run: |
|
|
|
name: Smoke Test |
|
|
|
command: | |
|
|
|
HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://devops-back-final.herokuapp.com//` |
|
|
|
HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://devops-back-final.herokuapp.com/api/articles` |
|
|
|
if [[ "$HTTPCODE" -ne 200 ]]; then |
|
|
|
echo "heroku app not responding, failing deploy" \ |
|
|
|
exit 1; \ |
|
|
|
|