From a06a56361bffc6d71921f6736b132b15df04b373 Mon Sep 17 00:00:00 2001 From: sellnat77 Date: Sun, 8 Mar 2020 10:41:30 -0700 Subject: [PATCH] Backend image deploys to heroku on master dpeloyment Docker tag/push instead of heroku push Added port overrides in backed Backend images are pushed to a heroku app on master deployment --- .github/workflows/Publish_Backend_Package.yml | 14 ++++++++++++++ server/Dockerfile | 3 ++- server/src/app.py | 13 ++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Publish_Backend_Package.yml b/.github/workflows/Publish_Backend_Package.yml index ef711bfb5..8cacd800c 100644 --- a/.github/workflows/Publish_Backend_Package.yml +++ b/.github/workflows/Publish_Backend_Package.yml @@ -29,3 +29,17 @@ jobs: dockerfile: server/Dockerfile context: server tags: "latest, ${{github.sha}}" + - name: Login to heroku + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + run: heroku container:login + - name: Build and push heroku + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + run: | + docker tag docker.pkg.github.com/hackforla/311-data/backend:${{github.sha}} registry.heroku.com/hackforla-311-data/web + docker push registry.heroku.com/hackforla-311-data/web + - name: Release + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + run: heroku container:release -a hackforla-311-data web diff --git a/server/Dockerfile b/server/Dockerfile index ad017ac57..e97570ca4 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -5,6 +5,7 @@ RUN apt-get update && apt-get install -yq \ gfortran musl-dev ENV DB_CONNECTION_STRING=REDACTED +ENV PORT=5000 COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt @@ -13,6 +14,6 @@ COPY src/ /app WORKDIR /app -EXPOSE 5000 +EXPOSE $PORT CMD ["python", "app.py"] diff --git a/server/src/app.py b/server/src/app.py index 36313f1fd..c2cfb77b7 100644 --- a/server/src/app.py +++ b/server/src/app.py @@ -20,15 +20,22 @@ compress = Compress() +def environment_overrides(): + if os.environ.get('DB_CONNECTION_STRING', None): + app.config['Settings']['Database']['DB_CONNECTION_STRING'] =\ + os.environ.get('DB_CONNECTION_STRING') + if os.environ.get('PORT', None): + app.config['Settings']['Server']['PORT'] =\ + os.environ.get('PORT') + + def configure_app(): # Settings initialization config = ConfigParser() settings_file = os.path.join(os.getcwd(), 'settings.cfg') config.read(settings_file) app.config['Settings'] = config - if os.environ.get('DB_CONNECTION_STRING', None): - app.config['Settings']['Database']['DB_CONNECTION_STRING'] =\ - os.environ.get('DB_CONNECTION_STRING') + environment_overrides() app.config["STATIC_DIR"] = os.path.join(os.getcwd(), "static") os.makedirs(os.path.join(app.config["STATIC_DIR"], "temp"), exist_ok=True)