Skip to content

Instantly share code, notes, and snippets.

@noinarisak
Last active March 14, 2024 15:25
Show Gist options
  • Save noinarisak/c665f18bdd343880ab2e49253d085b0c to your computer and use it in GitHub Desktop.
Save noinarisak/c665f18bdd343880ab2e49253d085b0c to your computer and use it in GitHub Desktop.
GitHub Actions Deploy by Git Tag to AWS Elastic Beanstalk

GitHub Actions Deploy by Git Tag to AWS Elastic Beanstalk

Example workflow assuming you are using git tags to deploy to AWS EBS. Leveraging the following flow with GH Releases:

  1. Draft Release and manually set Sematic version (eg. Major.Minor.Patch) Using the Release Drafter to automate it.
  2. Reveiw and Publish that version.
  3. Run the DEPLOY TO EBS.
  4. Profit! 🎉
# Author: Noi Narisak
# Verision: v1.0.0
# Desc: Multiple deployment to EBS instances.
name: CD (All) - DEPLOY TO ALL EBS
on:
workflow_dispatch:
inputs:
deployTagVersion:
description: 'Deploy Tag Version'
required: true
default: 'v1.0.0'
ebApplicationName:
description: 'EB Application Name'
required: true
default: 'udp-zartan'
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
ebEnvironment: [admin, credit, dealer, ecommerce, finance, healthcare, hospitality, streamingservice, travelagency] # Names of the EBS environment.
max-parallel: 1 # Fix to only single Job instance due EBS api throttling.
steps:
- name: Output inputs
run: |
echo "Deploy Tag Version: ${{ github.event.inputs.deployTagVersion }}"
echo "EB Application Name: ${{ github.event.inputs.ebApplicationName }}"
echo "EB Environment Name: ${{ matrix.ebEnvironment }}"
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout version tag
run: |
git tag --list
git checkout tags/${{ github.event.inputs.deployTagVersion }} -b ${{ github.event.inputs.deployTagVersion }}-branch
- name: Generate deployment package
if: ${{ success() }}
run: |
zip -r deploy.zip . \
-x '*.git*' \
-x '*__pycache__/*' \
-x '*.pytest_cache/*' \
-x 'venv/*' \
-x '*node_modules/*' \
-x '*env*'
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v11
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
region: us-east-2
application_name: ${{ github.event.inputs.ebApplicationName }}
environment_name: ${{ matrix.ebEnvironment }}
version_label: ${{ github.event.inputs.deployTagVersion }}
version_description: ${{ github.SHA }}
deployment_package: deploy.zip
use_existing_version_if_available: true
# Author: Noi Narisak
# Verision: v1.0.0
# Desc: Single deployment to EBS instances.
name: CD (Single) - DEPLOY TO SINGLE EBS
on:
workflow_dispatch:
inputs:
deployTagVersion:
description: 'Deploy Tag Version'
required: true
default: 'v0.0.1'
ebApplicationName:
description: 'EB Application Name'
required: true
default: 'flask-tutorial'
ebEnvironmentName:
description: 'EB Environment Name'
required: true
default: 'flask-env'
jobs:
deploy:
if: github.actor == 'noinarisak' # Only allow particular users to excute the workflow.
runs-on: ubuntu-latest
steps:
- name: Output inputs
run: |
echo "Deploy Tag Version: ${{ github.event.inputs.deployTagVersion }}"
echo "EB Application Name: ${{ github.event.inputs.ebApplicationName }}"
echo "EB Environment Name: ${{ github.event.inputs.ebEnvironmentName }}"
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout verision tag
run: |
git tag --list
git checkout tags/${{ github.event.inputs.deployTagVersion }} -b ${{ github.event.inputs.deployTagVersion }}-branch
- name: Generate deployment package
if: ${{ success() }}
run: zip -r deploy.zip . -x '*.git*' -x 'venv/*'
- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v11
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ github.event.inputs.ebApplicationName }}
environment_name: ${{ github.event.inputs.ebEnvironmentName }}
version_label: ${{ github.event.inputs.deployTagVersion }}
region: us-east-1
deployment_package: deploy.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment