Skip to content

Commit bb2e19d

Browse files
authored
Add link-index-updater lambda build job (#1217)
* Add link-index-updater lambda build job And reuse it in the release workflow * Also re-use in PR * Fix * Decrease retention * Refactor * Remove `_modified` and check It's not concurrency safe and doesn't work as expected. It's not worth the hassle
1 parent 05dfe82 commit bb2e19d

File tree

4 files changed

+74
-35
lines changed

4 files changed

+74
-35
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
# This workflow is used to build the link-index-updater
3+
# lambda function bootstrap binary that can be deployed to AWS Lambda.
4+
name: Build Link Index Updater Lambda
5+
6+
on:
7+
workflow_dispatch:
8+
workflow_call:
9+
inputs:
10+
ref:
11+
required: false
12+
type: string
13+
default: ${{ github.ref }}
14+
outputs:
15+
artifact-id:
16+
description: 'Artifact ID of the uploaded artifact. Can be used to download the artifact in other workflows.'
17+
value: ${{ jobs.build.outputs.artifact-id }}
18+
19+
jobs:
20+
build:
21+
outputs:
22+
artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }}
23+
zip-file: ${{ steps.create-zip.outputs.zip-file }}
24+
runs-on: ubuntu-latest
25+
env:
26+
BINARY_PATH: .artifacts/docs-lambda-index-publisher/release_linux-x64/bootstrap
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
ref: ${{ inputs.ref }}
31+
- name: Amazon Linux 2023 build
32+
run: |
33+
docker build . -t publish-links-index:latest -f src/infra/docs-lambda-index-publisher/lambda.DockerFile
34+
- name: Get bootstrap binary
35+
run: |
36+
docker cp $(docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc
37+
- name: Inspect bootstrap binary
38+
run: |
39+
tree .artifacts
40+
stat "${BINARY_PATH}"
41+
- name: Archive artifact
42+
id: upload-artifact
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: link-index-updater-lambda-binary
46+
retention-days: 1
47+
if-no-files-found: error
48+
path: ${{ env.BINARY_PATH }}

.github/workflows/pr.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,8 @@ jobs:
2727
run: dotnet run --project src/tooling/docs-assembler -c release -- navigation validate
2828

2929
build-lambda:
30-
runs-on: ubuntu-latest
31-
steps:
32-
- uses: actions/checkout@v4
33-
- name: Amazon Linux 2023 build
34-
run: |
35-
docker build . -t publish-links-index:latest -f src/infra/docs-lambda-index-publisher/lambda.DockerFile
36-
- name: Get bootstrap binary
37-
run: |
38-
docker cp $(docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc
39-
tree .artifacts
40-
stat .artifacts/docs-lambda-index-publisher/release_linux-x64/bootstrap
41-
30+
uses: ./.github/workflows/build-link-index-updater-lambda.yml
31+
4232
lint:
4333
runs-on: ubuntu-latest
4434
defaults:

.github/workflows/release.yml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
})
4545
4646
containers:
47+
needs:
48+
- release-drafter
4749
runs-on: ubuntu-latest
4850
outputs:
4951
full-version: ${{ steps.bootstrap.outputs.full-version }}
@@ -52,7 +54,7 @@ jobs:
5254
steps:
5355
- uses: actions/checkout@v4
5456
with:
55-
ref: ${{ steps.release-drafter.outputs.tag_name }}
57+
ref: ${{ needs.release-drafter.outputs.tag_name }}
5658
- name: Bootstrap Action Workspace
5759
id: bootstrap
5860
uses: ./.github/actions/bootstrap
@@ -65,46 +67,52 @@ jobs:
6567
password: ${{ secrets.GITHUB_TOKEN }}
6668

6769
- name: Publish Containers
68-
run: ./build.sh publishcontainers
70+
run: ./build.sh publishcontainers\
71+
72+
build-lambda:
73+
needs:
74+
- release-drafter
75+
uses: ./.github/workflows/build-link-index-updater-lambda.yml
76+
with:
77+
ref: ${{ needs.release-drafter.outputs.tag_name }}
6978

7079
release-lambda:
7180
environment:
7281
name: link-index-updater-prod
7382
runs-on: ubuntu-latest
7483
needs:
84+
- build-lambda
7585
- release-drafter
7686
permissions:
7787
contents: write
7888
id-token: write
7989
env:
8090
ZIP_FILE: link-index-updater-lambda.zip
8191
steps:
82-
- uses: actions/checkout@v4
83-
with:
84-
ref: ${{ steps.release-drafter.outputs.tag_name }}
85-
- name: Amazon Linux 2023 build
86-
run: |
87-
docker build . -t publish-links-index:latest -f src/infra/docs-lambda-index-publisher/lambda.DockerFile
88-
- name: Get bootstrap binary
92+
93+
- uses: actions/download-artifact@v4
94+
with:
95+
artifact-ids: ${{ needs.build-lambda.outputs.artifact-id }}
96+
97+
- name: Create zip
8998
run: |
90-
docker cp $(docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc
91-
99+
zip -j "${ZIP_FILE}" ./bootstrap
100+
92101
- uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722 # v4.1.0
93102
with:
94103
role-to-assume: arn:aws:iam::197730964718:role/elastic-docs-v3-link-index-updater-deployer
95104
aws-region: us-east-2
96-
105+
97106
- name: Upload Lambda function
98-
run: |
99-
zip -j "${ZIP_FILE}" .artifacts/docs-lambda-index-publisher/release_linux-x64/bootstrap
107+
run: |
100108
aws lambda update-function-code \
101109
--function-name elastic-docs-v3-link-index-updater \
102110
--zip-file "fileb://${ZIP_FILE}"
103111
104112
- name: Attach Distribution to release
105113
env:
106114
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107-
run: gh release upload ${{ needs.release-drafter.outputs.tag_name }} "${ZIP_FILE}"
115+
run: gh release upload --repo ${{ github.repository }} ${{ needs.release-drafter.outputs.tag_name }} "${ZIP_FILE}"
108116

109117
release:
110118
needs:
@@ -126,7 +134,7 @@ jobs:
126134
steps:
127135
- uses: actions/checkout@v4
128136
with:
129-
ref: ${{ steps.release-drafter.outputs.tag_name }}
137+
ref: ${{ needs.release-drafter.outputs.tag_name }}
130138

131139
- name: Bootstrap Action Workspace
132140
id: bootstrap

src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class LinkIndexProvider(IAmazonS3 s3Client, ILambdaLogger logger, string
1919
{
2020
private string? _etag;
2121
private LinkReferenceRegistry? _linkIndex;
22-
private bool _modified;
2322

2423
private async Task<LinkReferenceRegistry> GetLinkIndex()
2524
{
@@ -57,18 +56,12 @@ public async Task UpdateLinkIndexEntry(LinkRegistryEntry linkRegistryEntry)
5756
{
5857
{ linkRegistryEntry.Branch, linkRegistryEntry }
5958
});
60-
_modified = true;
6159
logger.LogInformation("Added new entry for {repository}@{branch}", linkRegistryEntry.Repository, linkRegistryEntry.Branch);
6260
}
6361
}
6462

6563
public async Task Save()
6664
{
67-
if (!_modified)
68-
{
69-
logger.LogInformation("Skipping Save() because the link index was not modified");
70-
return;
71-
}
7265
if (_etag == null || _linkIndex == null)
7366
throw new InvalidOperationException("You must call UpdateLinkIndexEntry() before Save()");
7467
var json = LinkReferenceRegistry.Serialize(_linkIndex);

0 commit comments

Comments
 (0)