Skip to content

Commit

Permalink
Add CICD pipeline for automated deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Jun 28, 2024
1 parent 2c66fa1 commit cfdb772
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 28 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI/CD ⚙️

on:
push:
release:
types:
- published
workflow_dispatch:
inputs:
environment:
description: 'Environment to run deploy'
type: environment
required: true
force:
description: 'Deploy even if tests fail'
type: boolean
required: false
default: false

jobs:
test:
name: Test 🧪
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha || github.sha}}

- name: Docker API Build
run: docker build -t test -f Dockerfile-test .

- name: Docker API Test Run
run: docker run -e CHECK_CODEGEN=true test

deploy-to-dev:
name: Deploy to Development 🚧
needs: test
if: github.event_name == 'push' && github.ref_name == 'main'
concurrency: dev
uses: './.github/workflows/deploy.yml'
with:
environment: dev
secrets: inherit

deploy-to-prod:
name: Deploy to Production 🌟
needs: test
if: github.event_name == 'release'
concurrency: prod
uses: './.github/workflows/deploy.yml'
with:
environment: prod
secrets: inherit

manual-deployment:
name: Manual Deployment ‼️
needs: test
if: github.event_name == 'workflow_dispatch' && (success() || inputs.force == true)
concurrency: ${{ inputs.environment }}
uses: './.github/workflows/deploy.yml'
with:
environment: ${{ inputs.environment }}
secrets: inherit
38 changes: 38 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# A reusable workflow that deploys the contents of a repository to a target environment.
# https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow

on:
workflow_call:
inputs:
environment:
type: string
required: true

jobs:
deploy:
name: 🚀
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}

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

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'

- name: Install dependencies
run: npm install --no-save

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.DEPLOYMENT_ROLE_ARN }}
role-session-name: ${{ github.actor }}
aws-region: ${{ vars.AWS_REGION || 'us-west-2' }}

- name: Deploy
run: npm run deploy-${{ inputs.environment }}
28 changes: 0 additions & 28 deletions .github/workflows/test.yml

This file was deleted.

0 comments on commit cfdb772

Please # to comment.