Skip to content

Commit 6c9a2f9

Browse files
Merge pull request #1119 from input-output-hk/chore/LW-9879-lace-ops-to-sdk
[LW-9879] Move deployment code from lace-ops to here
2 parents c3b266d + a0adb2a commit 6c9a2f9

39 files changed

+1911
-1130
lines changed

.envrc.local.example

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export K8S_USER=eks-devs
3+
export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxx
4+
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5+
6+
export NIX_CONFIG='
7+
allow-import-from-derivation = true
8+
'

.github/workflows/std.yml

+106-68
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@ on:
1313
branches:
1414
- master
1515
- conway-era
16+
- dev-preview
1617
push:
1718
branches:
1819
- master
1920
- conway-era
21+
- dev-preview
2022
tags:
2123
- '@cardano-sdk/cardano-services**'
2224
env:
23-
AWS_REGION: us-east-1
24-
AWS_ROLE_ARN: arn:aws:iam::926093910549:role/lace-ci
2525
# NIX_UPLOAD_CACHE: s3://lace-nix-cache?region=us-east-1
2626
DISCOVERY_USER_NAME: gha-runner
2727
DISCOVERY_KNOWN_HOSTS_ENTRY: "65.109.126.156 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEOVVDZydvD+diYa6A3EtA3WGw5NfN0wv7ckQxa/fX1O"
28-
permissions:
29-
id-token: write
30-
contents: read
3128
concurrency:
3229
group: std-${{ github.workflow }}-${{ github.ref }}
3330
cancel-in-progress: true
@@ -36,6 +33,12 @@ jobs:
3633
outputs:
3734
hits: ${{ steps.discovery.outputs.hits }}
3835
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
3942
steps:
4043
- name: Configure AWS Credentials
4144
uses: aws-actions/[email protected]
@@ -67,25 +70,36 @@ jobs:
6770
name: ${{ matrix.target.jobName }}
6871
runs-on: ubuntu-latest
6972
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
7180
strategy:
7281
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"]') }}
7483
steps:
7584
- name: Configure AWS Credentials
85+
if: matrix.target != 'dummy-target'
7686
uses: aws-actions/[email protected]
7787
with:
7888
role-to-assume: ${{ env.AWS_ROLE_ARN }}
7989
aws-region: ${{ env.AWS_REGION }}
8090
- name: Login to Amazon ECR
91+
if: matrix.target != 'dummy-target'
8192
id: login-ecr
8293
uses: aws-actions/amazon-ecr-login@v1
8394
- uses: nixbuild/nix-quick-install-action@v25
95+
if: matrix.target != 'dummy-target'
8496
- uses: nixbuild/nixbuild-action@v17
97+
if: matrix.target != 'dummy-target'
8598
with:
8699
nixbuild_ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
87100
generate_summary_for: job
88101
- uses: divnix/std-action/setup-discovery-ssh@main
102+
if: matrix.target != 'dummy-target'
89103
with:
90104
ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
91105
user_name: ${{ env.DISCOVERY_USER_NAME }}
@@ -95,100 +109,124 @@ jobs:
95109
run: |
96110
echo commit: ${{ github.sha }}
97111
- uses: divnix/std-action/run@main
112+
if: matrix.target != 'dummy-target'
98113
with: {ffBuildInstructions: true, remoteStore: "ssh-ng://eu.nixbuild.net"}
99114

100115

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')
107121
permissions:
108-
id-token: write
109122
contents: read
110123
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
115125
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
121127
- uses: nixbuild/nix-quick-install-action@v25
122128
- uses: nixbuild/nixbuild-action@v17
123129
with:
124130
nixbuild_ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
125131
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
126147
- uses: divnix/std-action/setup-discovery-ssh@main
127148
with:
128149
ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
129150
user_name: ${{ env.DISCOVERY_USER_NAME }}
130151
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
138153
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
141166
env:
142-
BRANCH: ${{ github.ref_type == 'branch' && github.head_ref }}
143167
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+
)"
146179
147180
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
158191
environment:
159192
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/
168194
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
174196
- uses: nixbuild/nix-quick-install-action@v25
175197
- uses: nixbuild/nixbuild-action@v17
176198
with:
177199
nixbuild_ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
178200
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
179216
- uses: divnix/std-action/setup-discovery-ssh@main
180217
with:
181218
ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
182219
user_name: ${{ env.DISCOVERY_USER_NAME }}
183220
ssh_known_hosts_entry: ${{ env.DISCOVERY_KNOWN_HOSTS_ENTRY }}
184-
- name: Configure K8S Cluster Access
185-
shell: bash
221+
- name: Deploy to K8s
186222
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+
'

.kube/us-east-1

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
apiVersion: v1
2+
clusters:
3+
- cluster:
4+
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCVENDQWUyZ0F3SUJBZ0lJRXF6d2E1VTRYREl3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TkRBeE1Ea3hOVE13TlRaYUZ3MHpOREF4TURZeE5UTTFOVFphTUJVeApFekFSQmdOVkJBTVRDbXQxWW1WeWJtVjBaWE13Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLCkFvSUJBUURoYi94eStyNTFBR0tsUFVUQVdwTzJlbkI3Vzc0RStGS2pvV3VUd0FsdWIwcVRFSlR6ZlVjLzROOWIKZ3dsYk85TFdIN2ZYRGY0dEVCbjEwK2VRYzlYSTYzN09LYng2bzhuMmlib2JVNlJzY1dxOXNzMk1WY3BGN0VDOQpiZVprRHd4N2FlODZtSmhnZDNKeFBXRWI3SGdPZE8yaEVSN3Z0VEV4NjRwNWl4TzFMbDRrT2VvYzRGQm1tTURvCm9oNjJJRy9YZ3ZFdjc4azZteVRZeWdYV2JDcGRMR3hWa0YzNVRTOE93TTc0YWl6SWNFQ3JSZDAzVDFaT2NOaUoKcUhKQnJBbEt5MzB2OXJ6L0NFbGxwWEFJclY1WXJmcVd1NVBkeUsrdDliSU9zTGJYd2pIalJ2bGJ6Z3ZML1Izegp2MEQwdno2UVhVdy92eGt0VER5bEtyNitkSDVUQWdNQkFBR2pXVEJYTUE0R0ExVWREd0VCL3dRRUF3SUNwREFQCkJnTlZIUk1CQWY4RUJUQURBUUgvTUIwR0ExVWREZ1FXQkJSMlJHOExESzdOYXJOV3FhNnpkRWJjdmt1c3RqQVYKQmdOVkhSRUVEakFNZ2dwcmRXSmxjbTVsZEdWek1BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRQTJqTGQ5UThYRApQYmpsSDhXZjV1ZHAwZDRTSXIzcHYvU0lWQjIwazhHcHFPZFFRcTZVc2IrZVVFL0lwY2tBMkZ3d0ZOZ3M1amJDCjNGRGt2QjE2NHMwT3hQRFYzbnNxTkt0ZDJCUCtITS9QTEFJOXVLOW9QM0ZHYXREZDY1QkJoRnBoaWtGdDIyczIKY3ZVUHByY1VNVG9wT3ZPZGpteEIxdDR3ZDFRVmRCOVRwaVc0eEVPcEsxdmJLc2ZWeEpHdzdYdHFMRlF2dzB3MgpQMXgyNDZJRWlRWXRnazlMcE9WRDNUQ1VwMS9ReUEvclJ3NlFNWU8xdlpqQWpWaXJzWUZQQVlPOU1KcUZOS2x1CmhlRm5UTENiME1JL0NNQWEyOHhmWlFHUVhkNDExWnZUdFFTdWxnUTlMUmovclBQSWRmZ3RzdVJMU2JvVzlqMXYKZVRJWDRkc0RBVkZUCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
5+
server: https://EB65A880B90DF0A9B8455038EF27A45E.gr7.us-east-1.eks.amazonaws.com
6+
name: arn:aws:eks:us-east-1:926093910549:cluster/lace-dev-us-east-1
7+
contexts:
8+
- context:
9+
cluster: arn:aws:eks:us-east-1:926093910549:cluster/lace-dev-us-east-1
10+
user: eks-admin
11+
name: eks-admin
12+
- context:
13+
cluster: arn:aws:eks:us-east-1:926093910549:cluster/lace-dev-us-east-1
14+
user: eks-devs
15+
name: eks-devs
16+
- context:
17+
cluster: arn:aws:eks:us-east-1:926093910549:cluster/lace-dev-us-east-1
18+
user: eks-readonly
19+
name: eks-readonly
20+
- context:
21+
cluster: arn:aws:eks:us-east-1:926093910549:cluster/lace-dev-us-east-1
22+
user: lace-ci
23+
name: lace-ci
24+
current-context: eks-devs
25+
kind: Config
26+
preferences: {}
27+
users:
28+
- name: eks-admin
29+
user:
30+
exec:
31+
apiVersion: client.authentication.k8s.io/v1beta1
32+
args:
33+
- --region
34+
- us-east-1
35+
- eks
36+
- get-token
37+
- --cluster-name
38+
- lace-dev-us-east-1
39+
- --output
40+
- json
41+
- --role
42+
- arn:aws:iam::926093910549:role/eks-admin
43+
command: aws
44+
env:
45+
- name: AWS_PROFILE
46+
value: lw
47+
interactiveMode: IfAvailable
48+
provideClusterInfo: false
49+
- name: eks-devs
50+
user:
51+
exec:
52+
apiVersion: client.authentication.k8s.io/v1beta1
53+
args:
54+
- --region
55+
- us-east-1
56+
- eks
57+
- get-token
58+
- --cluster-name
59+
- lace-dev-us-east-1
60+
- --output
61+
- json
62+
- --role
63+
- arn:aws:iam::926093910549:role/eks-devs
64+
command: aws
65+
env:
66+
- name: AWS_PROFILE
67+
value: lw
68+
interactiveMode: IfAvailable
69+
provideClusterInfo: false
70+
- name: eks-readonly
71+
user:
72+
exec:
73+
apiVersion: client.authentication.k8s.io/v1beta1
74+
args:
75+
- --region
76+
- us-east-1
77+
- eks
78+
- get-token
79+
- --cluster-name
80+
- lace-dev-us-east-1
81+
- --output
82+
- json
83+
- --role
84+
- arn:aws:iam::926093910549:role/eks-readonly
85+
command: aws
86+
env:
87+
- name: AWS_PROFILE
88+
value: lw
89+
interactiveMode: IfAvailable
90+
provideClusterInfo: false
91+
- name: lace-ci
92+
user:
93+
exec:
94+
apiVersion: client.authentication.k8s.io/v1beta1
95+
args:
96+
- --region
97+
- us-east-1
98+
- eks
99+
- get-token
100+
- --cluster-name
101+
- lace-dev-us-east-1
102+
- --output
103+
- json
104+
- --role
105+
- arn:aws:iam::926093910549:role/lace-ci
106+
command: aws
107+
env:
108+
- name: AWS_PROFILE
109+
value: lw
110+
interactiveMode: IfAvailable
111+
provideClusterInfo: false

0 commit comments

Comments
 (0)