Skip to content

Commit

Permalink
Ready for testing in preview
Browse files Browse the repository at this point in the history
Adds grabbing sling into the mix
  • Loading branch information
jadudm committed Oct 9, 2024
1 parent 1be0b83 commit a809bea
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 146 deletions.
263 changes: 135 additions & 128 deletions .github/workflows/deploy-application.yml
Original file line number Diff line number Diff line change
@@ -1,128 +1,135 @@
---
name: Deploy application to cloud.gov
on:
workflow_call:
inputs:
environment:
required: true
type: string

jobs:
push-with-creds:
name: Deploy to cloud.gov with updated credentials
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
space: ${{ inputs.environment }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore npm cache
uses: actions/cache@v4
id: cache-npm
with:
path: ~/.npm
key: fac-build-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
fac-build-npm-
fac-build-
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Restore pip cache
uses: actions/cache@v4
id: cache-pip
with:
path: |
~/.cache/pip
/opt/hostedtoolcache/Python/
key: fac-build-pip-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/dev-requirements.txt') }}
restore-keys: |
fac-build-pip-${{ hashFiles('**/requirements.txt') }}-
fac-build-pip-
fac-build-
- name: Install npm dependencies
working-directory: ./backend
run: npm ci --production

- name: Compile JS/CSS assets
working-directory: ./backend
run: npm run build

- name: Update service keys
uses: cloud-gov/cg-cli-tools@main
env:
SAM_API_KEY: ${{ secrets.SAM_API_KEY }}
DJANGO_SECRET_LOGIN_KEY: $${{ secrets.DJANGO_SECRET_LOGIN_KEY }}
LOGIN_CLIENT_ID: $${{ secrets.LOGIN_CLIENT_ID }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
cf_command: update-user-provided-service fac-key-service -p '"{\"SAM_API_KEY\":\"${{ secrets.SAM_API_KEY }}\", \"DJANGO_SECRET_LOGIN_KEY\":\"${{ secrets.DJANGO_SECRET_LOGIN_KEY }}\", \"LOGIN_CLIENT_ID\":\"${{ secrets.LOGIN_CLIENT_ID }}\", \"SECRET_KEY\":\"${{ secrets.SECRET_KEY}}\"}"'

- name: Backup the database
# if: startsWith(github.ref, 'refs/tags/v1.')
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 7G -m 3G --name deploy_backup --command "./fac-backup-util.sh v0.1.5 deploy_backup"

- name: Deploy Preview to cloud.gov
if: ${{ inputs.environment == 'preview' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
cf_manifest: backend/manifests/manifest-preview.yml
cf_vars_file: backend/manifests/vars/vars-${{ env.space }}.yml
command: bin/ops/deploy_preview.sh

- name: Deploy fac to cloud.gov
if: ${{ inputs.environment != 'preview' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
cf_manifest: backend/manifests/manifest-fac.yml
cf_vars_file: backend/manifests/vars/vars-${{ env.space }}.yml
command: bin/ops/deploy.sh

- name: Load historical data
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 6G -m 1G --name load_data --command "./load_data.sh"

# This has to happen after an application deployment because the manifest (currently) is responsible
# for binding the "logdrain service" to the "gsa-fac application". This also needs to be done
# based on the suspicion that fluentbit cannot register the incoming logs when it is initially
# created, resulting in a 502. Restarting the application after everything is configured results
# in a 201, or, the expected status when transmitting logs.
- name: Restart the logshipper application
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf restart logshipper

---
name: Deploy application to cloud.gov
on:
workflow_call:
inputs:
environment:
required: true
type: string

jobs:
push-with-creds:
name: Deploy to cloud.gov with updated credentials
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
space: ${{ inputs.environment }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore npm cache
uses: actions/cache@v4
id: cache-npm
with:
path: ~/.npm
key: fac-build-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
fac-build-npm-
fac-build-
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Restore pip cache
uses: actions/cache@v4
id: cache-pip
with:
path: |
~/.cache/pip
/opt/hostedtoolcache/Python/
key: fac-build-pip-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/dev-requirements.txt') }}
restore-keys: |
fac-build-pip-${{ hashFiles('**/requirements.txt') }}-
fac-build-pip-
fac-build-
- name: Install npm dependencies
working-directory: ./backend
run: npm ci --production

- name: Compile JS/CSS assets
working-directory: ./backend
run: npm run build

- name: Grab sling for copying data from DB1 to DB2
working-directory: ./backend
run: |
curl -L -O https://github.com/slingdata-io/sling-cli/releases/download/v1.2.20/sling_linux_amd64.tar.gz
tar xzf sling_linux_amd64.tar.gz
chmod 755 sling
- name: Update service keys
uses: cloud-gov/cg-cli-tools@main
env:
SAM_API_KEY: ${{ secrets.SAM_API_KEY }}
DJANGO_SECRET_LOGIN_KEY: $${{ secrets.DJANGO_SECRET_LOGIN_KEY }}
LOGIN_CLIENT_ID: $${{ secrets.LOGIN_CLIENT_ID }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
cf_command: update-user-provided-service fac-key-service -p '"{\"SAM_API_KEY\":\"${{ secrets.SAM_API_KEY }}\", \"DJANGO_SECRET_LOGIN_KEY\":\"${{ secrets.DJANGO_SECRET_LOGIN_KEY }}\", \"LOGIN_CLIENT_ID\":\"${{ secrets.LOGIN_CLIENT_ID }}\", \"SECRET_KEY\":\"${{ secrets.SECRET_KEY}}\"}"'

- name: Backup the database
# if: startsWith(github.ref, 'refs/tags/v1.')
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 7G -m 3G --name deploy_backup --command "./fac-backup-util.sh v0.1.5 deploy_backup"

- name: Deploy Preview to cloud.gov
if: ${{ inputs.environment == 'preview' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
cf_manifest: backend/manifests/manifest-preview.yml
cf_vars_file: backend/manifests/vars/vars-${{ env.space }}.yml
command: bin/ops/deploy_preview.sh

- name: Deploy fac to cloud.gov
if: ${{ inputs.environment != 'preview' }}
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
cf_manifest: backend/manifests/manifest-fac.yml
cf_vars_file: backend/manifests/vars/vars-${{ env.space }}.yml
command: bin/ops/deploy.sh

- name: Load historical data
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 6G -m 1G --name load_data --command "./load_data.sh"

# This has to happen after an application deployment because the manifest (currently) is responsible
# for binding the "logdrain service" to the "gsa-fac application". This also needs to be done
# based on the suspicion that fluentbit cannot register the incoming logs when it is initially
# created, resulting in a 502. Restarting the application after everything is configured results
# in a 201, or, the expected status when transmitting logs.
- name: Restart the logshipper application
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf restart logshipper

2 changes: 1 addition & 1 deletion .github/workflows/fac-backup-and-sling-scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ jobs:
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 7G -m 3G --name backup_util_scheduled --command "./tools/fac-backup-and-sling.sh ${{ inputs.util_version }} ${{ inputs.backup_operation }}"
command: cf run-task gsa-fac -k 7G -m 3G --name backup_and_sling_scheduled --command "./util/fac-backup-and-sling-scheduled.sh ${{ inputs.util_version }} ${{ inputs.backup_operation }}"

7 changes: 7 additions & 0 deletions backend/.profile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ if [[ "$CF_INSTANCE_INDEX" == 0 ]]; then
migrate_app_tables
gonogo "migrate_app_tables"

#####
# PREP API TABLES
# This runs sling and preps tables in the snapshot DB.
# Only runs if the tables are not present (e.g. first deploy)
sling_first_run
gonogo "sling_first_run"

#####
# API STANDUP
# Standup the API, which may depend on migration changes
Expand Down
1 change: 0 additions & 1 deletion backend/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ source tools/util_startup.sh
source tools/setup_env.sh
source tools/api_teardown.sh
source tools/migrate_app_tables.sh
source tools/sling_support_functions.sh
source tools/sling_first_run.sh
source tools/api_standup.sh
source tools/build_indexes.sh
Expand Down
3 changes: 3 additions & 0 deletions backend/tools/remove_api_from_fac_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# run this once in each env
# after we deploy the new API and everything
# is happy.
2 changes: 1 addition & 1 deletion backend/tools/sling_first_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function sling_first_run() {
$SLING_EXE run -r dissemination/sql/sling/public_data_v1_0_0/tribal_data_v1_0_0.yaml
gonogo "sling tribal data for API tables"
$SLING_EXE run -r dissemination/sql/sling/public_data_v1_0_0/public_metadata_v1_0_0.yaml
gonogo "sling tribal data for API tables"
gonogo "sling metadata table"
startup_log "SLING_FIRST_RUN" "Successfully ran sling to generate tables."
else
startup_log "SLING_FIRST_RUN" "API tables exist; skipping sling."
Expand Down
15 changes: 0 additions & 15 deletions backend/tools/sling_support_functions.sh

This file was deleted.

0 comments on commit a809bea

Please sign in to comment.