You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.7 KiB
133 lines
3.7 KiB
version: 2.1
|
|
|
|
commands:
|
|
restore_cache_cmd:
|
|
description: "Restore cache from a previous workflow"
|
|
steps:
|
|
- restore_cache:
|
|
keys:
|
|
- deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }}
|
|
- deps1-{{ .Branch }}-
|
|
|
|
save_cache_cmd:
|
|
description: "save cache with workflow new state"
|
|
steps:
|
|
- save_cache:
|
|
key: deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }}
|
|
paths:
|
|
- "venv"
|
|
|
|
executors:
|
|
docker-python-executor:
|
|
docker:
|
|
- image: circleci/python:3.7.9-stretch
|
|
auth:
|
|
username: morganlmd
|
|
password: $DOCKERHUB_PASSWORD
|
|
environment:
|
|
CONDUIT_SECRET: "something-really-secret"
|
|
FLASK_APP: /home/circleci/repo/autoapp.py
|
|
FLASK_DEBUG: 1
|
|
|
|
docker-postgres-executor:
|
|
docker:
|
|
- image: circleci/python:3.7.9-stretch
|
|
environment:
|
|
CONDUIT_SECRET: "something-really-secret"
|
|
FLASK_APP: autoapp.py
|
|
FLASK_DEBUG: 1
|
|
DATABASE_URL: postgresql://myUsr:somePwd@localhost:5432/myUsr
|
|
|
|
- image: circleci/postgres:9.6.5-alpine
|
|
environment:
|
|
POSTGRES_USER: myUsr
|
|
POSTGRES_DB: myUsr
|
|
POSTGRES_PASSWORD: somePwd
|
|
|
|
dockerhub-publisher:
|
|
environment:
|
|
IMAGE_NAME: morganlmd/devops-tp-final-back-docker
|
|
IMAGE_NAME_TMP: app
|
|
docker:
|
|
- image: circleci/buildpack-deps:stretch
|
|
|
|
jobs:
|
|
initial-build:
|
|
executor: docker-python-executor
|
|
steps:
|
|
- checkout
|
|
- restore_cache_cmd
|
|
- run:
|
|
name: setup environment and install python dependencies in a venv
|
|
command: |
|
|
python3 -m venv venv
|
|
. venv/bin/activate
|
|
pip install -r requirements/dev.txt
|
|
- save_cache_cmd
|
|
|
|
setup-and-test-db:
|
|
executor: docker-postgres-executor
|
|
steps:
|
|
- checkout
|
|
- restore_cache_cmd
|
|
- run:
|
|
name: testing connection between database and backend
|
|
command: |
|
|
. venv/bin/activate
|
|
sleep 1
|
|
flask db upgrade
|
|
# flask test
|
|
- save_cache_cmd
|
|
|
|
dockerhub-publishing:
|
|
working_directory: /dockerapp
|
|
executor: dockerhub-publisher
|
|
steps:
|
|
- checkout
|
|
- setup_remote_docker
|
|
- run:
|
|
name: Building docker image
|
|
command: |
|
|
docker build --cache-from=app -t app .
|
|
- deploy:
|
|
name: publishing docker image to dockerhub
|
|
command: |
|
|
docker login -e $DOCKERHUB_EMAIL -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
|
|
docker tag $IMAGE_NAME_TMP $IMAGE_NAME:$CIRCLE_BUILD_NUM
|
|
docker tag $IMAGE_NAME_TMP $IMAGE_NAME:latest
|
|
docker push $IMAGE_NAME:$CIRCLE_BUILD_NUM
|
|
docker push $IMAGE_NAME:latest
|
|
|
|
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 HEAD:main
|
|
- run:
|
|
name: Smoke Test
|
|
command: |-
|
|
HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://$HEROKU_APP_NAME.herokuapp.com/`
|
|
if [ "$HTTPCODE" -ne 200 ];then
|
|
echo "heroku app not responding, failing deploy"
|
|
exit 1
|
|
fi
|
|
|
|
workflows:
|
|
version: 2
|
|
build-test-back-and-db:
|
|
jobs:
|
|
- initial-build
|
|
- setup-and-test-db:
|
|
requires:
|
|
- initial-build
|
|
- dockerhub-publishing:
|
|
requires:
|
|
- initial-build
|
|
- setup-and-test-db
|
|
- back-deploy-heroku:
|
|
requires:
|
|
- initial-build
|
|
- setup-and-test-db
|