diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..052a922 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,132 @@ +version: 2 # use CircleCI 2.0 +jobs: # A basic unit of work in a run + build: # runs not using Workflows must have a `build` job as entry point + # directory where steps are run + working_directory: ~/repo + docker: # run the steps with Docker + # CircleCI Python images available at: https://hub.docker.com/r/circleci/python/ + - image: circleci/python:3.9.1 + auth: + username: $DOCKERHUB_USERNAME + password: $DOCKERHUB_PASSWORD # context / project UI env-var reference + environment: # environment variables for primary container + PIPENV_VENV_IN_PROJECT: true + DATABASE_URL: postgresql://circle_test:pwd@localhost:5432/circle_test + # CircleCI PostgreSQL images available at: https://hub.docker.com/r/circleci/postgres/ + - image: circleci/postgres:9.6.9-alpine + auth: + username: $DOCKERHUB_USERNAME + password: $DOCKERHUB_PASSWORD # context / project UI env-var reference + environment: # environment variables for the Postgres container. + POSTGRES_USER: circle_test + POSTGRES_PASSOWRD: pwd + POSTGRES_DB: circle_test + steps: # steps that comprise the `build` job + - checkout # check out source code to working directory + # - run: sudo chown -R circleci:circleci /usr/local/bin + # - run: sudo chown -R circleci:circleci /usr/local/lib/python3.8/site-packages + - restore_cache: + # Read about caching dependencies: https://circleci.com/docs/2.0/caching/ + key: deps10-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} + - run: + command: | + python3 -m venv venv + . venv/bin/activate + pip install -r requirements/dev.txt + environment: + CONDUIT_SECRET: "something-really-secret" + FLASK_APP: autoapp.py + FLASK_DEBUG: 1 + DATABASE_URL: postgresql://circle_test:pwd@localhost:5432/circle_test + - save_cache: # cache Python dependencies using checksum of Pipfile as the cache-key + key: deps10-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} + + paths: + - "venv" + + - store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/ + path: test-results + - store_artifacts: # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/ + path: test-results + destination: tr1 + + test: + docker: + - image: circleci/python:3.9.1 + - image: circleci/postgres:9.6.9-alpine + environment: + POSTGRES_USER: circle_test + POSTGRES_PASSOWRD: pwd + POSTGRES_DB: circle_test + working_directory: ~/repo + steps: + - checkout + - restore_cache: + keys: + - deps10-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} + - deps10-{{ .Branch }}- + - run: + command: | + . venv/bin/activate + sleep 1 + flask db stamp head + flask db migrate + flask db upgrade + # flask db test + environment: + CONDUIT_SECRET: "something-really-secret" + FLASK_APP: autoapp.py + FLASK_DEBUG: 1 + DATABASE_URL: postgresql://circle_test:pwd@localhost:5432/circle_test + + - save_cache: # cache Python dependencies using checksum of Pipfile as the cache-key + key: deps10-{{ .Branch }}-{{ checksum "requirements/dev.txt" }} + paths: + - "venv" + heroku: + docker: + - image: buildpack-deps:trusty + working_directory: ~/repo + steps: + - checkout + + - run: + name: Heroku Deploy + command: git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git main + + docker_build_push: + working_directory: /dockerapp + docker: + - image: docker:17.05.0-ce-git + steps: + - checkout + - setup_remote_docker + - run: + name: Build application Docker image + command: | + docker build --cache-from=app -t app . + - deploy: + name: Publish application to docker hub + command: | + docker login -e $DOCKER_HUB_EMAIL -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD + docker tag app $DOCKERHUB_USERNAME/dev_ops_back_container:$CIRCLE_BUILD_NUM + docker tag app $DOCKERHUB_USERNAME/dev_ops_back_container:latest + docker push $DOCKERHUB_USERNAME/dev_ops_back_container:$CIRCLE_BUILD_NUM + docker push $DOCKERHUB_USERNAME/dev_ops_back_container:latest + +workflows: + version: 2 + build-test: + jobs: + - build + - test: + requires: + - build + - heroku: + requires: + - build + - test + - docker_build_push: + requires: + - build + - test \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5e72b99 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9.1 + +COPY . /app + +ENV FLASK_APP=autoapp.py + +RUN pip install -r /app/requirements/dev.txt + +CMD python /app/autoapp.py \ No newline at end of file diff --git a/Pipfile.lock b/Pipfile.lock index 815e162..e0e665b 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -168,11 +168,13 @@ }, "jinja2": { "hashes": [ + dependabot/pip/jinja2-2.10.1 "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b" ], "index": "pypi", "version": "==2.10.1" + main }, "mako": { "hashes": [ @@ -302,10 +304,10 @@ }, "sqlalchemy": { "hashes": [ - "sha256:e21e5561a85dcdf16b8520ae4daec7401c5c24558e0ce004f9b60be75c4b6957" + "sha256:11ead7047ff3f394ed0d4b62aded6c5d970a9b718e1dc6add9f5e79442cc5b14" ], "index": "pypi", - "version": "==1.2.9" + "version": "==1.3.0" }, "unicode-slugify": { "hashes": [ @@ -330,11 +332,11 @@ }, "werkzeug": { "hashes": [ - "sha256:c3fd7a7d41976d9f44db327260e263132466836cef6f91512889ed60ad26557c", - "sha256:d5da73735293558eb1651ee2fddc4d0dedcfa06538b8813a2e20011583c9e49b" + "sha256:97660b282aa7e29f94f3fe378e5c7162d7ab9d601a8dbb1cbb2ffc8f0e54607d", + "sha256:cfd1281b1748288e59762c0e174d64d8bcb2b70e7c57bc4a1203c8825af24ac3" ], "index": "pypi", - "version": "==0.14.1" + "version": "==0.15.3" } }, "develop": { diff --git a/Procfile b/Procfile index 60df632..a96c523 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn autoapp:app -b 0.0.0.0:$PORT -w 3 +web: flask db upgrade;gunicorn autoapp:app -b 0.0.0.0:$PORT -w 3 diff --git a/conduit/settings.py b/conduit/settings.py index b838a6d..9579273 100644 --- a/conduit/settings.py +++ b/conduit/settings.py @@ -25,6 +25,7 @@ class Config(object): 'http://localhost:4200', 'http://0.0.0.0:4000', 'http://localhost:4000', + 'https://super-cool-site-by-pierredarcas.netlify.app/#/', ] JWT_HEADER_TYPE = 'Token'