13
13
branches :
14
14
- master
15
15
- conway-era
16
+ - dev-preview
16
17
push :
17
18
branches :
18
19
- master
19
20
- conway-era
21
+ - dev-preview
20
22
tags :
21
23
- ' @cardano-sdk/cardano-services**'
22
24
env :
23
- AWS_REGION : us-east-1
24
- AWS_ROLE_ARN : arn:aws:iam::926093910549:role/lace-ci
25
25
# NIX_UPLOAD_CACHE: s3://lace-nix-cache?region=us-east-1
26
26
DISCOVERY_USER_NAME : gha-runner
27
27
DISCOVERY_KNOWN_HOSTS_ENTRY : " 65.109.126.156 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEOVVDZydvD+diYa6A3EtA3WGw5NfN0wv7ckQxa/fX1O"
28
- permissions :
29
- id-token : write
30
- contents : read
31
28
concurrency :
32
29
group : std-${{ github.workflow }}-${{ github.ref }}
33
30
cancel-in-progress : true
36
33
outputs :
37
34
hits : ${{ steps.discovery.outputs.hits }}
38
35
runs-on : [self-hosted, discovery]
36
+ env :
37
+ AWS_REGION : us-east-1
38
+ AWS_ROLE_ARN : arn:aws:iam::926093910549:role/lace-ci
39
+ permissions :
40
+ id-token : write
41
+ contents : read
39
42
steps :
40
43
- name : Configure AWS Credentials
41
44
uses :
aws-actions/[email protected]
@@ -67,25 +70,36 @@ jobs:
67
70
name : ${{ matrix.target.jobName }}
68
71
runs-on : ubuntu-latest
69
72
needs : discover
70
- if : fromJSON(needs.discover.outputs.hits).oci-images.publish != '{}'
73
+ env :
74
+ AWS_REGION : us-east-1
75
+ AWS_ROLE_ARN : arn:aws:iam::926093910549:role/lace-ci
76
+ # NIX_UPLOAD_CACHE: s3://lace-nix-cache?region=us-east-1
77
+ permissions :
78
+ id-token : write
79
+ contents : read
71
80
strategy :
72
81
matrix :
73
- target : ${{ fromJSON(needs.discover.outputs.hits). oci-images.publish }}
82
+ target : ${{ contains( fromJSON(needs.discover.outputs.hits), 'oci-images') && fromJSON(needs.discover.outputs.hits). oci-images.publish || fromJSON('["dummy-target"]') }}
74
83
steps :
75
84
- name : Configure AWS Credentials
85
+ if : matrix.target != 'dummy-target'
76
86
uses :
aws-actions/[email protected]
77
87
with :
78
88
role-to-assume : ${{ env.AWS_ROLE_ARN }}
79
89
aws-region : ${{ env.AWS_REGION }}
80
90
- name : Login to Amazon ECR
91
+ if : matrix.target != 'dummy-target'
81
92
id : login-ecr
82
93
uses : aws-actions/amazon-ecr-login@v1
83
94
- uses : nixbuild/nix-quick-install-action@v25
95
+ if : matrix.target != 'dummy-target'
84
96
- uses : nixbuild/nixbuild-action@v17
97
+ if : matrix.target != 'dummy-target'
85
98
with :
86
99
nixbuild_ssh_key : ${{ secrets.SSH_PRIVATE_KEY }}
87
100
generate_summary_for : job
88
101
- uses : divnix/std-action/setup-discovery-ssh@main
102
+ if : matrix.target != 'dummy-target'
89
103
with :
90
104
ssh_key : ${{ secrets.SSH_PRIVATE_KEY }}
91
105
user_name : ${{ env.DISCOVERY_USER_NAME }}
@@ -95,100 +109,124 @@ jobs:
95
109
run : |
96
110
echo commit: ${{ github.sha }}
97
111
- uses : divnix/std-action/run@main
112
+ if : matrix.target != 'dummy-target'
98
113
with : {ffBuildInstructions: true, remoteStore: "ssh-ng://eu.nixbuild.net"}
99
114
100
115
101
- diff-to-eu :
102
- runs-on : ubuntu-latest
103
- needs : [discover, images]
104
- name : ${{ matrix.target.jobName }} (us-east-1)
105
- env :
106
- AWS_REGION : us-east-1
116
+ # TODO: remove all hardcoded instances of `dev-preview` in the next iteration
117
+ diff-to-us :
118
+ needs : images
119
+ name : Diff & Comment (dev-preview)
120
+ if : github.event_name == 'pull_request' && (github.base_ref == 'master')
107
121
permissions :
108
- id-token : write
109
122
contents : read
110
123
pull-requests : write
111
- if : fromJSON(needs.discover.outputs.hits).deployments.diff != '{}' && github.event_name == 'pull_request'
112
- strategy :
113
- matrix :
114
- target : ${{ fromJSON(needs.discover.outputs.hits).deployments.diff }}
124
+ runs-on : ubuntu-22.04
115
125
steps :
116
- - name : Configure AWS Credentials
117
- uses :
aws-actions/[email protected]
118
- with :
119
- role-to-assume : ${{ env.AWS_ROLE_ARN }}
120
- aws-region : ${{ env.AWS_REGION }}
126
+ - uses : actions/checkout@v4
121
127
- uses : nixbuild/nix-quick-install-action@v25
122
128
- uses : nixbuild/nixbuild-action@v17
123
129
with :
124
130
nixbuild_ssh_key : ${{ secrets.SSH_PRIVATE_KEY }}
125
131
generate_summary_for : job
132
+ # Further steps assume AWS_PROFILE=lw, while the official action has no way to specify that profile:
133
+ - name : Set up AWS credentials
134
+ run : |
135
+ mkdir -p ~/.aws
136
+
137
+ cat <<EOF >~/.aws/credentials
138
+ [lw]
139
+ aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY}}
140
+ aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}
141
+ EOF
142
+
143
+ cat <<EOF >~/.aws/config
144
+ [lw]
145
+ region = us-east-1
146
+ EOF
126
147
- uses : divnix/std-action/setup-discovery-ssh@main
127
148
with :
128
149
ssh_key : ${{ secrets.SSH_PRIVATE_KEY }}
129
150
user_name : ${{ env.DISCOVERY_USER_NAME }}
130
151
ssh_known_hosts_entry : ${{ env.DISCOVERY_KNOWN_HOSTS_ENTRY }}
131
- - name : Configure K8S Cluster Access
132
- shell : bash
133
- run : |
134
- echo "Assuming role '$(aws sts get-caller-identity)' in cluster 'lace-dev-us-east-1'."
135
- aws eks update-kubeconfig --name "lace-dev-us-east-1"
136
- - name : Show commit
137
- shell : bash
152
+ - name : Generate the Diff
138
153
run : |
139
- echo commit: ${{ github.sha }}
140
- - uses : divnix/std-action/run@main
154
+ echo 'export K8S_USER=eks-devs' >.envrc.local
155
+
156
+ nix develop .#x86_64-linux.local.envs.main -L --command bash -c '
157
+ set -euo pipefail
158
+
159
+ export AWS_PROFILE="lw"
160
+ export AWS_REGION="us-east-1"
161
+
162
+ # FIXME: before merging: change target to `dev-preview@us-east-1`
163
+ nix run -L ".#[email protected] " | tee k8s-plan.diff
164
+ '
165
+ - name : Post Comment on the PR
141
166
env :
142
- BRANCH : ${{ github.ref_type == 'branch' && github.head_ref }}
143
167
GH_TOKEN : ${{ github.token }}
144
- OWNER_AND_REPO : ${{ github.repository }}
145
- with : {ffBuildInstructions: true, remoteStore: "ssh-ng://eu.nixbuild.net"}
168
+ run : |
169
+ prNumber=$(cut -d/ -f1 <<<'${{ github.ref_name }}')
170
+ gh pr comment "$prNumber" --body "$(
171
+ echo '<details>'
172
+ echo "<summary>$(head -n 1 k8s-plan.diff)</summary>"
173
+ echo
174
+ echo '```diff'
175
+ tail -n +2 k8s-plan.diff
176
+ echo '```'
177
+ echo '</details>'
178
+ )"
146
179
147
180
148
- deploy-to-eu :
149
- runs-on : ubuntu-latest
150
- needs : [discover, images]
151
- name : ${{ matrix.target.jobName }} (us-east-1)
152
- env :
153
- AWS_REGION : us-east-1
154
- permissions :
155
- id-token : write
156
- contents : read
157
- deployments : write
181
+ # TODO: remove all hardcoded instances of `dev-preview` in the next iteration
182
+ deploy-to-us :
183
+ if : (github.event_name == 'push' && github.ref_name == 'master') || (github.event_name == 'workflow_dispatch' && inputs.deploy)
184
+ needs : [images]
185
+ concurrency :
186
+ # Only one deployment at a time per environment, and wait for the previous one to finish:
187
+ group : deploy-dev-preview
188
+ cancel-in-progress : false
189
+ name : Deploy (dev-preview)
190
+ runs-on : ubuntu-22.04
158
191
environment :
159
192
name : dev-preview
160
- url : https://backend.dev-preview.eks.lw.iog.io
161
- # Boolean input should be compared with string until https://github.com/actions/runner/issues/2238 resolved
162
- if : >
163
- fromJSON(needs.discover.outputs.hits).deployments.apply != '{}' && ((github.event_name == 'push' && github.ref == 'refs/heads/master') || inputs.deploy)
164
-
165
- strategy :
166
- matrix :
167
- target : ${{ fromJSON(needs.discover.outputs.hits).deployments.apply }}
193
+ url : https://dev-preview.lw.iog.io/
168
194
steps :
169
- - name : Configure AWS Credentials
170
- uses :
aws-actions/[email protected]
171
- with :
172
- role-to-assume : ${{ env.AWS_ROLE_ARN }}
173
- aws-region : ${{ env.AWS_REGION }}
195
+ - uses : actions/checkout@v4
174
196
- uses : nixbuild/nix-quick-install-action@v25
175
197
- uses : nixbuild/nixbuild-action@v17
176
198
with :
177
199
nixbuild_ssh_key : ${{ secrets.SSH_PRIVATE_KEY }}
178
200
generate_summary_for : job
201
+ # Further steps assume AWS_PROFILE=lw, while the official action has no way to specify that profile:
202
+ - name : Set up AWS credentials
203
+ run : |
204
+ mkdir -p ~/.aws
205
+
206
+ cat <<EOF >~/.aws/credentials
207
+ [lw]
208
+ aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY}}
209
+ aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}
210
+ EOF
211
+
212
+ cat <<EOF >~/.aws/config
213
+ [lw]
214
+ region = us-east-1
215
+ EOF
179
216
- uses : divnix/std-action/setup-discovery-ssh@main
180
217
with :
181
218
ssh_key : ${{ secrets.SSH_PRIVATE_KEY }}
182
219
user_name : ${{ env.DISCOVERY_USER_NAME }}
183
220
ssh_known_hosts_entry : ${{ env.DISCOVERY_KNOWN_HOSTS_ENTRY }}
184
- - name : Configure K8S Cluster Access
185
- shell : bash
221
+ - name : Deploy to K8s
186
222
run : |
187
- echo "Assuming role '$(aws sts get-caller-identity)' in cluster 'lace-dev-us-east-1'."
188
- aws eks update-kubeconfig --name "lace-dev-us-east-1"
189
- - name : Show commit
190
- shell : bash
191
- run : |
192
- echo commit: ${{ github.sha }}
193
- - uses : divnix/std-action/run@main
194
- with : {ffBuildInstructions: true, remoteStore: "ssh-ng://eu.nixbuild.net"}
223
+ echo 'export K8S_USER=eks-devs' >.envrc.local
224
+
225
+ nix develop .#x86_64-linux.local.envs.main -L --command bash -c '
226
+ set -euo pipefail
227
+
228
+ export AWS_PROFILE="lw"
229
+ export AWS_REGION="us-east-1"
230
+
231
+ echo yes | nix run -L ".#[email protected] "
232
+ '
0 commit comments