Skip to content

Instantly share code, notes, and snippets.

@t04glovern
Created May 3, 2022 02:41
Show Gist options
  • Save t04glovern/d20b485380f7f4297f608e678a52ebee to your computer and use it in GitHub Desktop.
Save t04glovern/d20b485380f7f4297f608e678a52ebee to your computer and use it in GitHub Desktop.
Github Action Deploy AWS Greengrass v2
name: Component deploy
on:
repository_dispatch:
push:
branches:
- main
jobs:
publish:
name: Component publish
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
outputs:
publised_version: ${{ steps.gdk_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.OIDC_ROLE_AWS_ROLE_TO_ASSUME }}
aws-region: ${{ secrets.OIDC_ROLE_AWS_REGION }}
- name: Install Greengrass Development Kit
run: pip install -U git+https://github.com/aws-greengrass/aws-greengrass-gdk-cli.git@v1.1.0
- name: GDK Build
run: gdk component build
- name: GDK Publish
run: gdk component publish
- name: Get published version
id: gdk_version
run: |
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity | jq -r '.Account')
export AWS_REGION="ap-southeast-2"
export LATEST_COMPONENT_VERSION=$(aws greengrassv2 list-component-versions \
--output text \
--no-paginate \
--arn arn:aws:greengrass:${AWS_REGION}:${AWS_ACCOUNT_ID}:components:com.devopstar.Treadmill \
--query 'componentVersions[0].componentVersion')
echo "::set-output name=version::${LATEST_COMPONENT_VERSION}"
deploy:
name: Component deploy
runs-on: ubuntu-latest
needs: publish
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ secrets.OIDC_ROLE_AWS_ROLE_TO_ASSUME }}
aws-region: ${{ secrets.OIDC_ROLE_AWS_REGION }}
- name: Deploy Greengrass component
run: |
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity | jq -r '.Account')
export AWS_REGION="ap-southeast-2"
envsubst < "deployment.json.template" > "deployment.json"
aws greengrassv2 create-deployment \
--cli-input-json file://deployment.json \
--region ${AWS_REGION}
env:
LATEST_COMPONENT_VERSION: ${{needs.publish.outputs.publised_version}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment