Skip to content

databases

databases #970

Workflow file for this run

---
name: databases
on:
workflow_dispatch: {}
schedule:
- cron: '0 1 * * *'
jobs:
init:
name: init
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
-
name: Build
run: go build -o bin/apppack
-
uses: actions/upload-artifact@v3
with:
name: apppack
path: bin
-
name: AppPack Init
run: |
./bin/apppack create region --region us-east-2 \
--aws-credentials \
--dockerhub-username $DOCKERHUB_USERNAME \
--dockerhub-access-token $DOCKERHUB_ACCESS_TOKEN \
--non-interactive
./bin/apppack create cluster --region us-east-2 \
--aws-credentials \
--domain testclusters.apppack.io \
--non-interactive
timeout-minutes: 15
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
standard-mysql:
runs-on: ubuntu-latest
needs: ["init"]
steps:
-
uses: actions/download-artifact@v3
with:
name: apppack
path: bin
-
name: Create standard MySQL
run: |
chmod +x ./bin/apppack
./bin/apppack create database --region us-east-2 \
--aws-credentials \
--non-interactive \
--cluster apppack \
--instance-class db.t4g.micro \
--engine mysql \
--allocated-storage 10 \
--max-allocated-storage 20 \
standard-mysql
timeout-minutes: 30
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Destroy standard MySQL
run: |
yes apppack-database-standard-mysql | ./bin/apppack destroy database standard-mysql \
--aws-credentials --region us-east-2
if: always()
timeout-minutes: 35
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
standard-postgres:
runs-on: ubuntu-latest
needs: ["init"]
steps:
-
uses: actions/download-artifact@v3
with:
name: apppack
path: bin
-
name: Create standard Postgres
run: |
chmod +x ./bin/apppack
./bin/apppack create database --region us-east-2 \
--aws-credentials \
--non-interactive \
--cluster apppack \
--instance-class db.t4g.micro \
--engine postgres \
--allocated-storage 10 \
--max-allocated-storage 20 \
standard-postgres
timeout-minutes: 25
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Destroy standard Postgres
run: |
yes apppack-database-standard-postgres | ./bin/apppack destroy database standard-postgres \
--aws-credentials --region us-east-2
if: always()
timeout-minutes: 35
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aurora-mysql:
runs-on: ubuntu-latest
needs: ["init"]
steps:
-
uses: actions/download-artifact@v3
with:
name: apppack
path: bin
-
name: Create Aurora MySQL
run: |
chmod +x ./bin/apppack
./bin/apppack create database --region us-east-2 \
--aws-credentials \
--non-interactive \
--cluster apppack \
--instance-class db.t4g.medium \
--engine aurora-mysql \
--allocated-storage 10 \
--max-allocated-storage 20 \
aurora-mysql
timeout-minutes: 35
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Destroy Aurora MySQL
run: |
yes apppack-database-aurora-mysql | ./bin/apppack destroy database aurora-mysql \
--aws-credentials --region us-east-2
if: always()
timeout-minutes: 35
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aurora-postgres:
runs-on: ubuntu-latest
needs: ["init"]
steps:
-
uses: actions/download-artifact@v3
with:
name: apppack
path: bin
-
name: Create Aurora Postgres
run: |
chmod +x ./bin/apppack
./bin/apppack create database --region us-east-2 \
--aws-credentials \
--non-interactive \
--cluster apppack \
--instance-class db.t4g.medium \
--engine aurora-postgresql \
aurora-postgres
timeout-minutes: 25
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Destroy Aurora Postgres
run: |
yes apppack-database-aurora-postgres | ./bin/apppack destroy database aurora-postgres \
--aws-credentials --region us-east-2
if: always()
timeout-minutes: 35
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
redis:
runs-on: ubuntu-latest
needs: ["init"]
steps:
-
name: Checkout
uses: actions/checkout@v3
-
uses: actions/download-artifact@v3
with:
name: apppack
path: bin
-
name: Create Redis
run: |
chmod +x ./bin/apppack
./bin/apppack create redis --region us-east-2 \
--aws-credentials \
--non-interactive \
--cluster apppack
timeout-minutes: 35
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Destroy Redis
# Redis clusters fail to destroy occassionally when there were just created
# The error is:
# Cache cluster xxx-001 is not in a valid state to be deleted. (Service: AmazonElastiCache; Status Code: 400; Error Code: InvalidReplicationGroupState
# The state during this time is "available", so there's nothing we can do but retry the operation :P
# Amazon support's recommendation is to wait 5-10 minutes after creation to delete it
run: |
yes apppack-redis-apppack | ./bin/apppack destroy redis apppack \
--aws-credentials --region us-east-2 || \
yes apppack-redis-apppack | ./bin/apppack destroy redis apppack \
--aws-credentials --region us-east-2
if: always()
timeout-minutes: 25
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-2
destroy:
runs-on: ubuntu-latest
if: always()
needs:
- standard-mysql
- standard-postgres
- aurora-mysql
- aurora-postgres
- redis
steps:
-
uses: actions/download-artifact@v3
with:
name: apppack
path: bin
-
name: Destroy cluster
run: |
chmod +x ./bin/apppack
yes apppack-cluster-apppack | ./bin/apppack destroy cluster apppack --aws-credentials --region us-east-2
if: always()
timeout-minutes: 8
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Destroy region
run: |
yes apppack-region-us-east-2 | ./bin/apppack destroy region --aws-credentials --region us-east-2
if: always()
timeout-minutes: 3
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
name: Cleanup database snapshots
run: |
for d in $(aws rds describe-db-snapshots --snapshot-type manual --query 'DBSnapshots[].DBSnapshotIdentifier' --output text); do
aws rds delete-db-snapshot --db-snapshot-identifier "$d"
done
for d in $(aws rds describe-db-cluster-snapshots --snapshot-type manual --query 'DBClusterSnapshots[].DBClusterSnapshotIdentifier' --output text); do
aws rds delete-db-cluster-snapshot --db-cluster-snapshot-identifier "$d"
done
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-2