Skip to content

Commit

Permalink
[platform] GitHub Actions workflow to deploy TDA
Browse files Browse the repository at this point in the history
  • Loading branch information
realkosty committed Mar 20, 2024
1 parent 3505bc2 commit 2fab772
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/deploy_tda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: deploy_tda.yml
run-name: triggered by ${{ github.actor }}

on:
push:
workflow_dispatch:

# Only run 1 workflow at a time. If new one starts abort any that are already running.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
default-job:
if: github.repository_owner == 'sentry-demos' # don't run in forks
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-22.04

steps:
- run: echo "Triggered by ${{ github.event_name }} event."
- run: echo "Branch is ${{ github.ref }}"

- name: Check out this repository code
uses: actions/checkout@v3
with:
path: empower
fetch-depth: 0

- name: Check out `empower-config` to get GCP identity provider and account name
uses: actions/checkout@v3
with:
repository: sentry-demos/empower-config
path: empower-config
token: ${{ secrets.KOSTY_PERSONAL_ACCESS_TOKEN_FOR_SYNC_DEPLOY_FORK }}
# See https://github.com/actions/checkout/issues/347#issuecomment-963586784

- name: Get GCP_ env variables from empower-config/.gcloudrc
run: |
source empower-config/.gcloudrc
echo "GCP_WORKLOAD_IDENTITY_PROVIDER=$GCP_WORKLOAD_IDENTITY_PROVIDER" >> $GITHUB_OUTPUT
echo "GCP_SERVICE_ACCOUNT=$GCP_SERVICE_ACCOUNT" >> $GITHUB_OUTPUT
id: gcloudrc

- name: Copy .sauce_credentials from empower-config repo
run: cp empower-config/.sauce_credentials empower/tda/

- id: 'auth'
name: 'Authenticate Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: ${{ steps.gcloudrc.outputs.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ steps.gcloudrc.outputs.GCP_SERVICE_ACCOUNT }}

- name: 'Set up Google Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'

- name: Run deploy_tda.sh
run: gcloud compute config-ssh && ./deploy_tda.sh
working-directory: ./empower/tda

- run: echo "Job status is ${{ job.status }}."

6 changes: 4 additions & 2 deletions tda/deploy_tda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function cleanup {
trap cleanup EXIT

echo "Checking ssh connection can be established..."
ssh $HOST exit
ssh -o StrictHostKeyChecking=accept-new $HOST exit
if [ $? != "0" ]; then
echo "[ERROR] Can't ssh into destination host. Please run 'gcloud compute config-ssh; ssh $HOST exit' to fix"
exit 5
Expand All @@ -30,11 +30,13 @@ fi

echo "Copying code to remote directory..."
# for whatever reason can't delete or chmod __pycache__ directories
rsync -rz --delete --force-delete --exclude env/ --exclude __pycache__ * .sauce_credentials $HOST:$DIR/
rsync -rz --delete --force-delete --exclude env/ --exclude __pycache__ --exclude .pytest_cache * .sauce_credentials $HOST:$DIR/
ret="$?"

echo "Re-attempting with --delete instead of --force-delete..."
if [ $ret == 1 ]; then # some versions of rsync don't recognize --force-delete option
rsync -rz --delete --force --exclude env/ --exclude __pycache__ * .sauce_credentials $HOST:$DIR/
ret="$?"
fi
if [ $ret != 0 ]; then
echo "[ERROR] Failed to rsync code to remote directory."
Expand Down

0 comments on commit 2fab772

Please sign in to comment.