Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/build-link-index-updater-lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# This workflow is used to build the link-index-updater
# lambda function bootstrap binary that can be deployed to AWS Lambda.
name: Build Link Index Updater Lambda

on:
workflow_dispatch:
workflow_call:
inputs:
ref:
required: false
type: string
default: ${{ github.ref }}
outputs:
artifact-id:
description: 'Artifact ID of the uploaded artifact. Can be used to download the artifact in other workflows.'
value: ${{ jobs.build.outputs.artifact-id }}

jobs:
build:
outputs:
artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }}
zip-file: ${{ steps.create-zip.outputs.zip-file }}
runs-on: ubuntu-latest
env:
BINARY_PATH: .artifacts/docs-lambda-index-publisher/release_linux-x64/bootstrap
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Amazon Linux 2023 build
run: |
docker build . -t publish-links-index:latest -f src/infra/docs-lambda-index-publisher/lambda.DockerFile
- name: Get bootstrap binary
run: |
docker cp $(docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc
- name: Inspect bootstrap binary
run: |
tree .artifacts
stat "${BINARY_PATH}"
- name: Archive artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: link-index-updater-lambda-binary
retention-days: 1
if-no-files-found: error
path: ${{ env.BINARY_PATH }}
14 changes: 2 additions & 12 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,8 @@ jobs:
run: dotnet run --project src/tooling/docs-assembler -c release -- navigation validate

build-lambda:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Amazon Linux 2023 build
run: |
docker build . -t publish-links-index:latest -f src/infra/docs-lambda-index-publisher/lambda.DockerFile
- name: Get bootstrap binary
run: |
docker cp $(docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc
tree .artifacts
stat .artifacts/docs-lambda-index-publisher/release_linux-x64/bootstrap

uses: ./.github/workflows/build-link-index-updater-lambda.yml

lint:
runs-on: ubuntu-latest
defaults:
Expand Down
40 changes: 24 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
})

containers:
needs:
- release-drafter
runs-on: ubuntu-latest
outputs:
full-version: ${{ steps.bootstrap.outputs.full-version }}
Expand All @@ -52,7 +54,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ steps.release-drafter.outputs.tag_name }}
ref: ${{ needs.release-drafter.outputs.tag_name }}
- name: Bootstrap Action Workspace
id: bootstrap
uses: ./.github/actions/bootstrap
Expand All @@ -65,46 +67,52 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Containers
run: ./build.sh publishcontainers
run: ./build.sh publishcontainers\

build-lambda:
needs:
- release-drafter
uses: ./.github/workflows/build-link-index-updater-lambda.yml
with:
ref: ${{ needs.release-drafter.outputs.tag_name }}

release-lambda:
environment:
name: link-index-updater-prod
runs-on: ubuntu-latest
needs:
- build-lambda
- release-drafter
permissions:
contents: write
id-token: write
env:
ZIP_FILE: link-index-updater-lambda.zip
steps:
- uses: actions/checkout@v4
with:
ref: ${{ steps.release-drafter.outputs.tag_name }}
- name: Amazon Linux 2023 build
run: |
docker build . -t publish-links-index:latest -f src/infra/docs-lambda-index-publisher/lambda.DockerFile
- name: Get bootstrap binary

- uses: actions/download-artifact@v4
with:
artifact-ids: ${{ needs.build-lambda.outputs.artifact-id }}

- name: Create zip
run: |
docker cp $(docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc
zip -j "${ZIP_FILE}" ./bootstrap

- uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722 # v4.1.0
with:
role-to-assume: arn:aws:iam::197730964718:role/elastic-docs-v3-link-index-updater-deployer
aws-region: us-east-2

- name: Upload Lambda function
run: |
zip -j "${ZIP_FILE}" .artifacts/docs-lambda-index-publisher/release_linux-x64/bootstrap
run: |
aws lambda update-function-code \
--function-name elastic-docs-v3-link-index-updater \
--zip-file "fileb://${ZIP_FILE}"

- name: Attach Distribution to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ needs.release-drafter.outputs.tag_name }} "${ZIP_FILE}"
run: gh release upload --repo ${{ github.repository }} ${{ needs.release-drafter.outputs.tag_name }} "${ZIP_FILE}"

release:
needs:
Expand All @@ -126,7 +134,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ steps.release-drafter.outputs.tag_name }}
ref: ${{ needs.release-drafter.outputs.tag_name }}

- name: Bootstrap Action Workspace
id: bootstrap
Expand Down
7 changes: 0 additions & 7 deletions src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class LinkIndexProvider(IAmazonS3 s3Client, ILambdaLogger logger, string
{
private string? _etag;
private LinkReferenceRegistry? _linkIndex;
private bool _modified;

private async Task<LinkReferenceRegistry> GetLinkIndex()
{
Expand Down Expand Up @@ -57,18 +56,12 @@ public async Task UpdateLinkIndexEntry(LinkRegistryEntry linkRegistryEntry)
{
{ linkRegistryEntry.Branch, linkRegistryEntry }
});
_modified = true;
logger.LogInformation("Added new entry for {repository}@{branch}", linkRegistryEntry.Repository, linkRegistryEntry.Branch);
}
}

public async Task Save()
{
if (!_modified)
{
logger.LogInformation("Skipping Save() because the link index was not modified");
return;
}
if (_etag == null || _linkIndex == null)
throw new InvalidOperationException("You must call UpdateLinkIndexEntry() before Save()");
var json = LinkReferenceRegistry.Serialize(_linkIndex);
Expand Down
Loading