-
Notifications
You must be signed in to change notification settings - Fork 12
171 lines (146 loc) · 6.23 KB
/
publish.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# This is a basic workflow to help you get started with Actions
name: Publish
# Controls when the workflow will run
on:
release:
types: [ published ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
registry_name: ghcr.io
image_name: iothub-portal
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
name: Build & Push Solution
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4.2.2
- id: docker-tag
uses: yuya-takeyama/docker-tag-from-github-ref-action@v1
- name: Configure AWS credentials
id: aws-credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# Should use us-east-1 region to push to ECR public registry
aws-region: us-east-1
- name: Docker Login to ACR
# You may pin to the exact commit or the version.
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.registry_name }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{ env.registry_name }}/${{ github.repository_owner }}/${{ env.image_name }}
${{ steps.login-ecr.outputs.registry }}/cgi-fr/${{ env.image_name }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
flavor: |
latest=true
- name: Build and push
# You may pin to the exact commit or the version.
uses: docker/build-push-action@v6.9.0
with:
# Build's context is the set of files located in the specified PATH or URL
context: src/
# Push is a shorthand for --output=type=registry
push: true
build-args: |
BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
GITHUB_RUN_NUMBER=${{ github.run_number }}
tags:
${{ steps.meta.outputs.tags }}
arm_templates:
name: Publish cloud infrastructure templates
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.2.2
- name: Get semver
id: version
uses: docker/metadata-action@v5
with:
images: |
${{ env.registry_name }}/${{ github.repository_owner }}/${{ env.image_name }}
tags: |
type=semver,pattern={{version}}
- uses: actions/checkout@v4.2.2
with:
path: IoT-Hub-Portal
submodules: recursive
- uses: actions/checkout@v4.2.2
with:
ref: arm/main
path: arm-templates
- name: Generate app token
id: generate_app_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Copy templates
working-directory: arm-templates
run: |
rm -rf ./templates/
mkdir -p templates/azure/iotedge-lorawan-starterkit
touch ./templates/.gitkeep
cp -r ../IoT-Hub-Portal/templates/* ./templates/
rm -rf ./templates/iotedge-lorawan-starterkit/
cp -r ../IoT-Hub-Portal/templates/iotedge-lorawan-starterkit/TemplateBicep/* ./templates/azure/iotedge-lorawan-starterkit/
sed -r -i 's/..\/iotedge-lorawan-starterkit\/TemplateBicep\/main.bicep/.\/iotedge-lorawan-starterkit\/main.bicep/g' ./templates/azure/portal_with_lorawan_and_starter_kit.bicep
- name: Update IoTHub Portal docker image tag in app_service.bicep
working-directory: arm-templates/templates/azure
run: sed -i 's/ghcr.io\/cgi-fr\/iothub-portal:latest/ghcr.io\/cgi-fr\/iothub-portal:${{ fromJSON(steps.version.outputs.json).labels['org.opencontainers.image.version'] }}/g' app_service.bicep
- name: Update IoTHub Portal docker image tag in awsdeploy.yml
working-directory: arm-templates/templates/aws
run: |
sed -i 's/public.ecr.aws\/cgi-fr\/iothub-portal:latest/public.ecr.aws\/cgi-fr\/iothub-portal:${{ fromJSON(steps.version.outputs.json).labels['org.opencontainers.image.version'] }}/g' awsdeploy.yml
- name: Generate ARM file
working-directory: arm-templates/templates/azure
run: az bicep build --file azuredeploy.bicep --outfile azuredeploy.json
- name: Upload azure templates to release assets
uses: AButler/upload-release-assets@v3.0
with:
files: 'arm-templates/templates/azure/*.json'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload aws templates to release assets
uses: AButler/upload-release-assets@v3.0
with:
files: 'arm-templates/templates/aws/*.yml'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR for template updates
uses: peter-evans/create-pull-request@v7
with:
base: 'arm/main'
branch: 'arm/feature/update-templates'
path: 'arm-templates'
commit-message: 'Update templates from release.'
token: ${{ steps.generate_app_token.outputs.token }}
title: '[ARM Templates] Update templates from release'
labels: |
arm-templates
automated pr
body: |
Automated changes to the Azure templates.