Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
Browse files Browse the repository at this point in the history
alukach committed Nov 5, 2024
1 parent 6758230 commit ec0f7f4
Showing 3 changed files with 79 additions and 85 deletions.
51 changes: 2 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ jobs:
with:
environment: Space2Stats API Dev
stage: pr-${{ github.event.pull_request.number }}
pr_number: ${{ github.event.pull_request.number }}
secrets: inherit

deploy-to-production:
@@ -66,59 +67,11 @@ jobs:
stage: prod
secrets: inherit

post-url-to-slack:
needs: deploy-to-dev
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "PR Deployment Details:"

- name: Create or update comment with URL
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
PR Deployment Details:
🚀 PR deployed to ${{ needs.deploy-to-dev.outputs.api_url }}
edit-mode: replace

destroy-pr-preview:
if: ${{ github.event.action == 'closed' }}
uses: "./.github/workflows/deploy.yml"
with:
environment: Space2Stats API Dev
stage: pr-${{ github.event.pull_request.number }}
secrets: inherit

post-cleanup-message-to-slack:
needs: destroy-pr-preview
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "PR Deployment Details:"

- name: Create or update comment with URL
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
Removed PR Preview Environment.
edit-mode: append
secrets: inherit
62 changes: 40 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -6,25 +6,23 @@ on:
environment:
type: string
required: true
stage:
stage:
type: string
required: true
outputs:
api_url:
description: "The URL of the API Gateway"
value: ${{ jobs.build.outputs.api_url }}
pr-number:
type: number
required: false

permissions:
id-token: write
contents: read
pull-requests: write

jobs:
build:
concurrency: ${{ inputs.environment }}
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
outputs:
api_url: ${{ steps.get_api_url.outputs.api_url }}

steps:
- name: Check out repository code
@@ -38,30 +36,50 @@ jobs:
with:
role-to-assume: arn:aws:iam::017820688988:role/Space2Stats-Deploy-Role
aws-region: ${{ vars.CDK_DEFAULT_REGION }}

- name: Install CDK dependencies
working-directory: ./space2stats_api/cdk
run: |
pip install -r requirements-cdk.txt
pip install -r requirements-cdk.txt
- name: Deploy CDK stack to staging
working-directory: ./space2stats_api/cdk
env:
STAGE: ${{ inputs.stage }}
PGHOST: ${{ secrets.PGHOST }}
PGPORT: ${{ secrets.PGPORT }}
PGDATABASE: ${{ secrets.PGDATABASE }}
PGUSER: ${{ secrets.PGUSER }}
PGPASSWORD: ${{ secrets.PGPASSWORD }}
PGTABLENAME: ${{ secrets.PGTABLENAME }}
CDK_CERTIFICATE_ARN: ${{ vars.CDK_CERTIFICATE_ARN }}
CDK_DEFAULT_ACCOUNT: ${{ vars.CDK_DEFAULT_ACCOUNT }}
CDK_DEFAULT_REGION: ${{ vars.CDK_DEFAULT_REGION }}
CDK_DOMAIN_NAME: ${{ vars.CDK_DOMAIN_NAME }}
STAGE: ${{ inputs.stage }}
PGHOST: ${{ secrets.PGHOST }}
PGPORT: ${{ secrets.PGPORT }}
PGDATABASE: ${{ secrets.PGDATABASE }}
PGUSER: ${{ secrets.PGUSER }}
PGPASSWORD: ${{ secrets.PGPASSWORD }}
PGTABLENAME: ${{ secrets.PGTABLENAME }}
CDK_CERTIFICATE_ARN: ${{ vars.CDK_CERTIFICATE_ARN }}
CDK_DEFAULT_ACCOUNT: ${{ vars.CDK_DEFAULT_ACCOUNT }}
CDK_DEFAULT_REGION: ${{ vars.CDK_DEFAULT_REGION }}
CDK_DOMAIN_NAME: ${{ vars.CDK_DOMAIN_NAME }}
run: cdk deploy --require-approval never --outputs-file outputs.json

- name: Get API URL
id: get_api_url
id: get-api-url
working-directory: ./space2stats_api/cdk
run: |
echo "api_url=$(jq -r '."Space2Stats-${{ inputs.stage }}".ApiGatewayUrl' outputs.json)" >> $GITHUB_OUTPUT
echo "api-url=$(jq -r '."Space2Stats-${{ inputs.stage }}".ApiGatewayUrl' outputs.json)" >> $GITHUB_OUTPUT
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
if: ${{ inputs.pr-number }}
with:
issue-number: ${{ inputs.pr-number }}
comment-author: "github-actions[bot]"
body-includes: "PR Deployment Details:"

- name: Create or update comment with URL
uses: peter-evans/create-or-update-comment@v4
if: ${{ inputs.pr-number }}
with:
issue-number: ${{ inputs.pr-number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
PR Deployment Details:
🚀 PR deployed to ${{ steps.get-api-url.outputs.api-url }}
edit-mode: replace
51 changes: 37 additions & 14 deletions .github/workflows/destroy.yml
Original file line number Diff line number Diff line change
@@ -6,13 +6,17 @@ on:
environment:
type: string
required: true
stage:
stage:
type: string
required: true
pr-number:
type: number
required: false

permissions:
id-token: write
contents: read
pull-requests: write

jobs:
build:
@@ -32,24 +36,43 @@ jobs:
with:
role-to-assume: arn:aws:iam::017820688988:role/Space2Stats-Deploy-Role
aws-region: ${{ vars.CDK_DEFAULT_REGION }}

- name: Install CDK dependencies
working-directory: ./space2stats_api/cdk
run: |
pip install -r requirements-cdk.txt
pip install -r requirements-cdk.txt
- name: Deploy CDK stack to staging
working-directory: ./space2stats_api/cdk
env:
STAGE: ${{ inputs.stage }}
PGHOST: ${{ secrets.PGHOST }}
PGPORT: ${{ secrets.PGPORT }}
PGDATABASE: ${{ secrets.PGDATABASE }}
PGUSER: ${{ secrets.PGUSER }}
PGPASSWORD: ${{ secrets.PGPASSWORD }}
PGTABLENAME: ${{ secrets.PGTABLENAME }}
CDK_CERTIFICATE_ARN: ${{ vars.CDK_CERTIFICATE_ARN }}
CDK_DEFAULT_ACCOUNT: ${{ vars.CDK_DEFAULT_ACCOUNT }}
CDK_DEFAULT_REGION: ${{ vars.CDK_DEFAULT_REGION }}
CDK_DOMAIN_NAME: ${{ vars.CDK_DOMAIN_NAME }}
STAGE: ${{ inputs.stage }}
PGHOST: ${{ secrets.PGHOST }}
PGPORT: ${{ secrets.PGPORT }}
PGDATABASE: ${{ secrets.PGDATABASE }}
PGUSER: ${{ secrets.PGUSER }}
PGPASSWORD: ${{ secrets.PGPASSWORD }}
PGTABLENAME: ${{ secrets.PGTABLENAME }}
CDK_CERTIFICATE_ARN: ${{ vars.CDK_CERTIFICATE_ARN }}
CDK_DEFAULT_ACCOUNT: ${{ vars.CDK_DEFAULT_ACCOUNT }}
CDK_DEFAULT_REGION: ${{ vars.CDK_DEFAULT_REGION }}
CDK_DOMAIN_NAME: ${{ vars.CDK_DOMAIN_NAME }}
run: cdk destroy --require-approval never

- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
if: ${{ inputs.pr-number }}
with:
issue-number: ${{ inputs.pr-number }}
comment-author: "github-actions[bot]"
body-includes: "PR Deployment Details:"

- name: Create or update comment with URL
uses: peter-evans/create-or-update-comment@v4
if: ${{ inputs.pr-number }}
with:
issue-number: ${{ inputs.pr-number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
Removed PR Preview Environment.
edit-mode: append

0 comments on commit ec0f7f4

Please sign in to comment.