Skip to content

Commit

Permalink
cd workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Jun 29, 2024
1 parent 02c4b4a commit 8774c9f
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Deploy to Production

on:
release:
types:
- published
push:
tags:
- prod

concurrency:
group: ${{ github.workflow }}

env:
APP_NAME: ionic8-playground.leanstacks.net
AWS_CFN_STACK_NAME: ls-ui-ionic8playground-resources-prod
AWS_CFN_TEMPLATE: template.yml
AWS_ENV_CODE: prod
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN_PROD }}
ENV_FILE: ${{ secrets.ENV_PROD }}

jobs:
deploy:
name: Deploy

runs-on: ubuntu-latest
timeout-minutes: 20

permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: npm

- name: Install Dependencies
run: npm ci

- name: Create Environment Configuration
run: |
echo "${{ env.ENV_FILE }}" > .env
echo "VITE_BUILD_DATE=$(date +'%Y-%m-%d')" >> .env
echo "VITE_BUILD_TIME=$(date +'%H:%M:%S%z')" >> .env
echo "VITE_BUILD_TS=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> .env
echo "VITE_BUILD_COMMIT_SHA=${{ github.sha }}" >> .env
echo "VITE_BUILD_ENV_CODE=${{ env.AWS_ENV_CODE }}" >> .env
echo "VITE_BUILD_WORKFLOW_NAME=${{ github.workflow }}" >> .env
echo "VITE_BUILD_WORKFLOW_RUN_NUMBER=${{ github.run_number }}" >> .env
echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=${{ github.run_attempt }}" >> .env
- name: Build
run: npm run build

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: Deploy AWS CloudFormation Stack
run: |-
aws cloudformation deploy \
--stack-name ${{ env.AWS_CFN_STACK_NAME }} \
--template-file ${{ env.AWS_CFN_TEMPLATE }} \
--parameter-overrides EnvironmentCode=${{ env.AWS_ENV_CODE }} \
--tags App=${{ env.APP_NAME }} Env=${{ env.AWS_ENV_CODE }} OU=leanstacks Owner='Matthew Warman'
- name: Get CloudFormation Stack Outputs
id: cloudformation
run: |-
APP_BUCKET_NAME=$(
aws cloudformation describe-stacks \
--stack-name ${{ env.AWS_CFN_STACK_NAME }} \
--query "Stacks[0].Outputs[?OutputKey=='AppBucketName'].OutputValue | [0]"
)
echo "APP_BUCKET_NAME=$APP_BUCKET_NAME" >> "$GITHUB_OUTPUT"
- name: Deploy to AWS S3
run: |
aws s3 sync dist s3://${{ steps.cloudformation.outputs.APP_BUCKET_NAME }} --delete
87 changes: 87 additions & 0 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy to QA

on:
push:
branches:
- release/*
tags:
- qa

concurrency:
group: ${{ github.workflow }}

env:
APP_NAME: ionic8-playground.leanstacks.net
AWS_CFN_STACK_NAME: ls-ui-ionic8playground-resources-qa
AWS_CFN_TEMPLATE: template.yml
AWS_ENV_CODE: qa
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ROLE_ARN: ${{ vars.AWS_ROLE_ARN_QA }}
ENV_FILE: ${{ secrets.ENV_QA }}

jobs:
deploy:
name: Deploy

runs-on: ubuntu-latest
timeout-minutes: 20

permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js Environment
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: npm

- name: Install Dependencies
run: npm ci

- name: Create Environment Configuration
run: |
echo "${{ env.ENV_FILE }}" > .env
echo "VITE_BUILD_DATE=$(date +'%Y-%m-%d')" >> .env
echo "VITE_BUILD_TIME=$(date +'%H:%M:%S%z')" >> .env
echo "VITE_BUILD_TS=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> .env
echo "VITE_BUILD_COMMIT_SHA=${{ github.sha }}" >> .env
echo "VITE_BUILD_ENV_CODE=${{ env.AWS_ENV_CODE }}" >> .env
echo "VITE_BUILD_WORKFLOW_NAME=${{ github.workflow }}" >> .env
echo "VITE_BUILD_WORKFLOW_RUN_NUMBER=${{ github.run_number }}" >> .env
echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=${{ github.run_attempt }}" >> .env
- name: Build
run: npm run build

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: Deploy AWS CloudFormation Stack
run: |-
aws cloudformation deploy \
--stack-name ${{ env.AWS_CFN_STACK_NAME }} \
--template-file ${{ env.AWS_CFN_TEMPLATE }} \
--parameter-overrides EnvironmentCode=${{ env.AWS_ENV_CODE }} \
--tags App=${{ env.APP_NAME }} Env=${{ env.AWS_ENV_CODE }} OU=leanstacks Owner='Matthew Warman'
- name: Get CloudFormation Stack Outputs
id: cloudformation
run: |-
APP_BUCKET_NAME=$(
aws cloudformation describe-stacks \
--stack-name ${{ env.AWS_CFN_STACK_NAME }} \
--query "Stacks[0].Outputs[?OutputKey=='AppBucketName'].OutputValue | [0]"
)
echo "APP_BUCKET_NAME=$APP_BUCKET_NAME" >> "$GITHUB_OUTPUT"
- name: Deploy to AWS S3
run: |
aws s3 sync dist s3://${{ steps.cloudformation.outputs.APP_BUCKET_NAME }} --delete

0 comments on commit 8774c9f

Please sign in to comment.