From f681a521d2bdefef83d0e435e783f5c274e13ae3 Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Wed, 28 Aug 2024 12:07:43 +0200 Subject: [PATCH 1/2] Temporarily add herokuapp.com to the ALLOWED_HOSTS --- metaculus_web/settings.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/metaculus_web/settings.py b/metaculus_web/settings.py index 2f2e68dd0c..e25f7962e5 100644 --- a/metaculus_web/settings.py +++ b/metaculus_web/settings.py @@ -337,7 +337,13 @@ FAB_CREDITS_OPENAI_API_KEY = os.environ.get("FAB_CREDITS_OPENAI_API_KEY") -ALLOWED_HOSTS = [".metaculus.com", "localhost", "127.0.0.1"] +ALLOWED_HOSTS = [ + ".metaculus.com", + "localhost", + "127.0.0.1", + "dev-metaculus-web-023b332df454.herokuapp.com/", #remove after we have a DNS entry for dev environment +] + CSRF_TRUSTED_ORIGINS = [FRONTEND_BASE_URL] INTERNAL_IPS = ["127.0.0.1"] From 3bc60fe0ac600ebeb96cb082ffc42617a6dcb163 Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Wed, 28 Aug 2024 12:33:37 +0200 Subject: [PATCH 2/2] Add a Github action to deploy to dev --- .github/workflows/deploy_dev.yml | 36 +++++++++++--------------------- scripts/deploy_to_heroku.sh | 19 ++++++++++------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/.github/workflows/deploy_dev.yml b/.github/workflows/deploy_dev.yml index cc6b40140c..1948cd22dd 100644 --- a/.github/workflows/deploy_dev.yml +++ b/.github/workflows/deploy_dev.yml @@ -1,32 +1,20 @@ -name: Deploy Dev +name: Deploy to dev Heroku on: workflow_dispatch: jobs: deploy: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest + env: + HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} + HEROKU_APP: dev-metaculus-web steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Install SSH key - run: | - mkdir -p ~/.ssh - echo "${{ secrets.DEV_SERVER_SSH_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - - - name: Run deployment script on dev server - run: | - ssh -o StrictHostKeyChecking=no ubuntu@107.20.216.39 << 'EOF' - bash -il << 'ENDBASH' - echo "Starting interactive shell" - chmod +x /home/ubuntu/rewrite/deploy.sh - /home/ubuntu/rewrite/deploy.sh > /home/ubuntu/deploy.log 2>&1 - echo "Finished executing commands" - exit - ENDBASH - EOF - env: - DEV_SERVER_SSH_KEY: ${{ secrets.DEV_SERVER_SSH_KEY }} + - name: Checkout code + uses: actions/checkout@v4 + - name: Build and deploy to Heroku + run: | + heroku container:login # uses the HEROKU_API_KEY + docker buildx build --cache-to=type=gha --cache-from type=gha . # used only for caching + ./scripts/deploy_to_heroku.sh diff --git a/scripts/deploy_to_heroku.sh b/scripts/deploy_to_heroku.sh index 80ecfbeb70..808c351c7c 100755 --- a/scripts/deploy_to_heroku.sh +++ b/scripts/deploy_to_heroku.sh @@ -1,13 +1,16 @@ #! /bin/bash +set -x + +[ -z "$HEROKU_APP" ] && { echo "Error: HEROKU_APP env varible is not set."; exit 1; } # Push container -heroku container:push release --arg ENTRY_SCRIPT_ARG="scripts/prod/release.sh" -heroku container:push web --arg ENTRY_SCRIPT_ARG="scripts/prod/startapp.sh" -heroku container:push dramatiq_worker --arg ENTRY_SCRIPT_ARG="scripts/prod/run_dramatiq.sh" -heroku container:push django_cron --arg ENTRY_SCRIPT_ARG="scripts/prod/django_cron.sh" +heroku container:push release --arg ENTRY_SCRIPT_ARG="scripts/prod/release.sh" -a $HEROKU_APP +heroku container:push web --arg ENTRY_SCRIPT_ARG="scripts/prod/startapp.sh" -a $HEROKU_APP +heroku container:push dramatiq_worker --arg ENTRY_SCRIPT_ARG="scripts/prod/run_dramatiq.sh" -a $HEROKU_APP +heroku container:push django_cron --arg ENTRY_SCRIPT_ARG="scripts/prod/django_cron.sh" -a $HEROKU_APP # Release them -heroku container:release release -heroku container:release web -heroku container:release dramatiq_worker -heroku container:release django_cron \ No newline at end of file +heroku container:release release -a $HEROKU_APP +heroku container:release web -a $HEROKU_APP +heroku container:release dramatiq_worker -a $HEROKU_APP +heroku container:release django_cron -a $HEROKU_APP