|
| 1 | +name: Deploy on LocalStack |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + schedule: |
| 11 | + # “At 00:00 on Sunday.” |
| 12 | + - cron: "0 0 * * 0" |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + cdk: |
| 20 | + name: Setup infrastructure using CDK |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v3 |
| 25 | + |
| 26 | + - uses: gautamkrishnar/keepalive-workflow@v1 |
| 27 | + |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@v3 |
| 30 | + with: |
| 31 | + node-version: 18 |
| 32 | + |
| 33 | + - name: Install CDK |
| 34 | + run: | |
| 35 | + npm install -g aws-cdk-local aws-cdk |
| 36 | + cdklocal --version |
| 37 | +
|
| 38 | + - name: Install Python |
| 39 | + uses: actions/setup-python@v4 |
| 40 | + with: |
| 41 | + python-version: '3.9' |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + pip install -r requirements.txt |
| 46 | +
|
| 47 | + - name: Start LocalStack |
| 48 | + env: |
| 49 | + LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }} |
| 50 | + run: | |
| 51 | + pip install localstack awscli-local[ver1] |
| 52 | + docker pull localstack/localstack-pro:latest |
| 53 | + # Start LocalStack in the background |
| 54 | + DEBUG=1 localstack start -d |
| 55 | + # Wait 30 seconds for the LocalStack container to become ready before timing out |
| 56 | + echo "Waiting for LocalStack startup..." |
| 57 | + localstack wait -t 15 |
| 58 | + echo "Startup complete" |
| 59 | +
|
| 60 | + - name: Deploy using CDK |
| 61 | + run: | |
| 62 | + cdklocal bootstrap aws://000000000000/us-east-1 |
| 63 | + cdklocal deploy --require-approval never |
| 64 | +
|
| 65 | + - name: Send a Slack notification |
| 66 | + if: failure() || github.event_name != 'pull_request' |
| 67 | + uses: ravsamhq/notify-slack-action@v2 |
| 68 | + with: |
| 69 | + status: ${{ job.status }} |
| 70 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + notification_title: "{workflow} has {status_message}" |
| 72 | + message_format: "{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>" |
| 73 | + footer: "Linked Repo <{repo_url}|{repo}> | <{run_url}|View Workflow run>" |
| 74 | + notify_when: "failure" |
| 75 | + env: |
| 76 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 77 | + |
| 78 | + - name: Generate a Diagnostic Report |
| 79 | + if: failure() |
| 80 | + run: | |
| 81 | + curl -s localhost:4566/_localstack/diagnose | gzip -cf > diagnose.json.gz |
| 82 | +
|
| 83 | + - name: Upload the Diagnostic Report |
| 84 | + if: failure() |
| 85 | + uses: actions/upload-artifact@v3 |
| 86 | + with: |
| 87 | + name: diagnose.json.gz |
| 88 | + path: ./diagnose.json.gz |
0 commit comments