Skip to content

Instantly share code, notes, and snippets.

@reaperes
Created January 13, 2022 00:37
Show Gist options
  • Save reaperes/af21e4462ed467adee866cf13f551f55 to your computer and use it in GitHub Desktop.
Save reaperes/af21e4462ed467adee866cf13f551f55 to your computer and use it in GitHub Desktop.
Github deploy workflow vis CodeDeploy with S3 bucket
name: Deploy main branch to production
on:
push:
branches: [ main ]
env:
DEPLOY_IAM_ROLE: arn:aws:iam::1234567890:role/deployer
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Assume IAM role
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ env.DEPLOY_IAM_ROLE }}
aws-region: ap-northeast-2
- name: Set current date as env variable
run: echo "NOW=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Set bundle name
run: echo "BUNDLE_NAME=${NOW}-${GITHUB_SHA:0:7}.tar.gz" >> $GITHUB_ENV
- name: Compress bundle
run: |
touch $BUNDLE_NAME # disable "tar: file changed as we read it" error
tar --exclude .git --exclude $BUNDLE_NAME -X .gitignore -cvzf $BUNDLE_NAME ./
- name: Upload to S3
run: aws s3api put-object --bucket bucket.deploy --key $BUNDLE_NAME --body $BUNDLE_NAME
- name: Create code deploy
run: aws deploy create-deployment --application-name app --deployment-group-name group --s3-location bucket=bucket.deploy,key=$BUNDLE_NAME,bundleType=tgz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment