-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (71 loc) · 3.05 KB
/
deploy-apps.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Greengrass components - deploy
# Only trigger, when the test workflow succeeded
on:
workflow_run:
workflows: ["Greengrass components - build"]
types:
- completed
env:
# Must be setup
OIDC_ROLE_AWS: ${{ secrets.OIDC_ROLE_AWS }}
REGION: ${{ vars.AWS_REGION }}
# Optional
THING_GROUP_NAME: GreengrassGroup
# Don't change
components-directory: ./greengrass-components/components
jobs:
# Deploy the updated component on the device if necessary
deploy:
name: Component deploy
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
id-token: write
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }} # Get head reference to compare commits
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.OIDC_ROLE_AWS }} # This is required for requesting the JWT
aws-region: ${{ env.REGION }} # This is required for actions/checkout
- name: "Install dependencies"
run: sudo apt-get install jq
- name: Deploy Greengrass components on the device
run: |
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --output text --no-paginate --query 'Account')
cli_version=$(aws greengrassv2 list-component-versions \
--output text \
--no-paginate \
--arn arn:aws:greengrass:${{ env.REGION }}:aws:components:aws.greengrass.Cli \
--query "componentVersions[0].componentVersion")
export CLI_VERSION=$cli_version
export AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID
export AWS_REGION=${{ env.REGION }}
export THING_GROUP=${{ env.THING_GROUP_NAME }}
envsubst < "deployment.json.template" > "deployment.json"
COMPONENTS=$(find . -maxdepth 1 -type d -not -name '.*' -exec basename {} \;)
for component in $COMPONENTS
do
version=$(aws greengrassv2 list-component-versions \
--output text \
--no-paginate \
--arn arn:aws:greengrass:${{ env.REGION }}:${AWS_ACCOUNT_ID}:components:${component} \
--query "componentVersions[0].componentVersion")
# Update JSON using jq
jq --arg name "$component" \
--arg version "$version" \
--arg reset """" \
'.components += { ($name): { "componentVersion": $version, "configurationUpdate": { "reset": [$reset] } } }' \
"deployment.json" > tmp.json && mv tmp.json "deployment.json"
done
# deploy
aws greengrassv2 create-deployment \
--cli-input-json file://deployment.json \
--region ${{ env.REGION }}
echo "Deployment finished!"
working-directory: ${{ env.components-directory }}