Skip to content

Commit

Permalink
Merge branch 'task/TEC-1417/adjust-backup-strategy-and-access' into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
luca-vari committed Nov 29, 2024
2 parents 1895562 + d70908b commit 3aa2854
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ jobs:
run: ./infra/backup.sh
shell: bash
env:
CLERK_PRIVATE_SSH_KEY: ${{ secrets.CLERK_PRIVATE_SSH_KEY }}

CLERK_PRIVATE_SSH_KEY: ${{ secrets.CLERK_PRIVATE_SSH_KEY }}
16 changes: 16 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Staging
on:
workflow_dispatch:
schedule:
# Update staging environment at 0415 AEST (18:15 UTC) each Saturday
- cron: "15 18 * * SAT"
jobs:
update_staging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run backup script
run: ./infra/staging/database-restore.sh
shell: bash
env:
CLERK_PRIVATE_SSH_KEY: ${{ secrets.CLERK_PRIVATE_SSH_KEY }}
25 changes: 21 additions & 4 deletions infra/staging/database-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@ HOST='13.55.250.149'
PROJECT='staging'
RESTORE_DIR="/srv/restore/clerk_test/$(date +%s)"

if [[ -z "$CLERK_PRIVATE_SSH_KEY" ]]; then
echo -e "\n>>> Error: Clerk private key not found in CLERK_PRIVATE_SSH_KEY"
exit 1
fi
echo -e "\n>>> Updating staging environment on Clerk EC2 instance at $HOST"

echo -e "\n>>> Setting up SSH"
mkdir ~/.ssh
echo -e "$CLERK_PRIVATE_SSH_KEY" > ~/.ssh/private.key
chmod 600 ~/.ssh/private.key
cat >> ~/.ssh/config <<END
Host ec2
HostName $HOST
User root
IdentityFile ~/.ssh/private.key
StrictHostKeyChecking no
END

echo -e "\n>>> Copying staging compose & env file to clerk at $HOST"
ssh -o StrictHostKeyChecking=no root@$HOST /bin/bash << EOF
ssh ec2 /bin/bash <<EOF
set -e
mkdir -p ${RESTORE_DIR}
EOF
scp -o StrictHostKeyChecking=no docker/docker-compose.staging.yml root@${HOST}:$RESTORE_DIR
scp -o StrictHostKeyChecking=no env/staging.env root@${HOST}:$RESTORE_DIR
scp docker/docker-compose.staging.yml env/staging.env ec2:$RESTORE_DIR

echo -e "\n>>> SSHing into clerk at $HOST."
ssh -o StrictHostKeyChecking=no root@$HOST /bin/bash << EOF
ssh ec2 /bin/bash <<EOF
set -e
cd ${RESTORE_DIR}
docker pull anikalaw/clerk:staging
Expand Down

0 comments on commit 3aa2854

Please sign in to comment.