Skip to content

Commit

Permalink
πŸ‘· Test deployment CI
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed May 28, 2024
1 parent fff3efd commit a4c7dcc
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/deploy-submodule-via-ec2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "πŸš€ Deploy submodule"

on:
workflow_call:
inputs:
ami-image-id:
required: false
type: string
instance-type:
required: true
type: string
folder:
required: true
type: string
pr-sha:
required: true
type: string
ref:
required: true
type: string
stage-override:
required: false
type: string

jobs:
start-runner:
name: "πŸ”§ Start EC2 runner"
runs-on: ubuntu-latest
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: "πŸ‘₯ Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role
aws-region: eu-west-1
retry-max-attempts: 5
- name: "πŸš€ Start EC2 runner"
id: start-ec2-runner
uses: machulav/ec2-github-runner@v2
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
with:
mode: start
github-token: ${{ env.GH_PERSONAL_ACCESS_TOKEN }}
ec2-image-id: ${{ inputs.ami-image-id || 'ami-034dddee671b5c88b' }}
ec2-instance-type: ${{ inputs.instance-type }}
subnet-id: subnet-008e0d55cc46af9a2
security-group-id: sg-07012408d5797f987
runner-home-dir: "/home/ubuntu/action-runner-2.311.0"

deploy-module:
needs: start-runner
uses: ./.github/workflows/deploy-submodule.yml
with:
runner-label: ${{ needs.start-runner.outputs.label }}
folder: ${{ inputs.folder }}
pr-sha: ${{ inputs.pr-sha }}
ref: ${{ inputs.ref }}

stop-runner:
name: "πŸ”§ Stop EC2 runner"
runs-on: ubuntu-latest
needs: [start-runner, deploy-module]
if: "success() || failure()"
steps:
- name: "πŸ‘₯ Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role
aws-region: eu-west-1
retry-max-attempts: 5
- name: "⚰️ Stop EC2 runner"
uses: machulav/ec2-github-runner@v2
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
68 changes: 68 additions & 0 deletions .github/workflows/deploy-submodule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "πŸš€ Deploy submodule"

on:
workflow_call:
inputs:
runner-label:
required: false
type: string
folder:
required: true
type: string
pr-sha:
required: true
type: string
ref:
required: true
type: string
stage-override:
required: false
type: string

jobs:
deploy-aws:
runs-on: ${{ inputs.runner-label || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.pr-sha }}

- name: "πŸ”¨ Setup pnpm"
uses: pnpm/action-setup@v3
with:
run_install: false

- name: "πŸ”¨ Setup Node.js"
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"

- name: "πŸ”§ Setup environment"
shell: bash
run: |
if [[ "${{ inputs.ref }}" == "refs/heads/main" ]]; then
echo "STAGE=prod" >> $GITHUB_ENV
elif [[ "${{ inputs.ref }}" == "refs/heads/staging" ]]; then
echo "STAGE=dev" >> $GITHUB_ENV
fi
- name: "πŸ”¨ Install dependencies"
run: pnpm install --frozen-lockfile

- name: "πŸ‘₯ Configure AWS Credentials"
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::262732185023:role/github-action-deploy-role
aws-region: eu-west-1
retry-max-attempts: 5

- name: "πŸš€ SST Deploy"
working-directory: ${{ inputs.folder }}
env:
STAGE_OVERRIDE: ${{ inputs.stage-override }}
run: |
STAGE=${STAGE_OVERRIDE:-$STAGE}
echo "Deploying with stage: $STAGE"
pnpm sst deploy --stage $STAGE
37 changes: 37 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: πŸš€ Deploy

on:
workflow_dispatch:
push:
branches:
- main
- staging
- ci/setup

concurrency:
group: ${{ github.ref }}-deploy

env:
CI: true

permissions:
id-token: write
contents: write

defaults:
run:
shell: bash

jobs:
# Independent step, deploying all the tools infrastructure
deploy-indexer:
name: "πŸš€ Deploy Indexer"
uses: ./.github/workflows/deploy-submodule-via-ec2.yml
secrets: inherit
with:
# Need a custom ami image id since it's needing docker for the build process
ami-image-id: ami-0e2a787a966f10c15
instance-type: t4g.small
folder: ./tools
pr-sha: ${{ github.event.pull_request.head.sha }}
ref: ${{ github.ref }}

0 comments on commit a4c7dcc

Please sign in to comment.