-
Notifications
You must be signed in to change notification settings - Fork 31
feature/publish links index lamdba #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7954e99
stage
Mpdreamz 6396b35
Merge branch 'main' into feature/publish-links-index-lamdba
Mpdreamz 0e453e3
Simplify function
Mpdreamz 3d2a08b
ensure binary is named bootstrap
Mpdreamz c021aea
add lambda docker build
Mpdreamz f015b1b
update lambda build
Mpdreamz 4564519
Add `free-disk-space` input (#614)
reakaleek d255f9a
Simply if check on Free Disk Space (#616)
Mpdreamz 552bf6d
Default CurrentUrlPath to empty string while we investigate further (…
Mpdreamz b733643
Fix `free-disk-space` input attempt 2 (#617)
reakaleek d148715
Just compare with repository name for now (#619)
reakaleek b1bb06d
Add update-reference-index action (#622)
Mpdreamz a84d015
Update links-index.json whenever a PR get's closed (#623)
Mpdreamz 2512e28
Update links-index.json whenever we push a links.json (#624)
Mpdreamz 199d427
Continue-on-error temporarily for validate-inbound-links (#627)
Mpdreamz a63dc2e
docs-preview: Use `since_last_remote_commit: true` for changed-files …
reakaleek 68221f9
On ci skip if /docs folder has no docset.yml silently (#630)
Mpdreamz 31af4f9
Revert "docs-preview: Use `since_last_remote_commit: true` for change…
reakaleek defe51d
Feature: allow the docs-build action to hint to subsequent steps to s…
Mpdreamz a9fcb3b
Set correct deployment status (#632)
reakaleek 4c7b972
Optimize preview build to avoid checkout on pull_request* events (#633)
reakaleek b11ef54
Add `PrimaryNav` feature (#604)
reakaleek 36b6f0a
Revert "Add `PrimaryNav` feature (#604)" (#635)
reakaleek 2494506
Add smoke test (#637)
reakaleek 04b29d7
Run free-disk-space action in security-docs (#639)
reakaleek 9e445c4
Add `primary-nav` feature (#636)
reakaleek f1d7252
Inbound link checking, fully validate if found in links-index (#643)
Mpdreamz 5a9cd46
Add `landing-page-path` output and use it in preview workflow (#642)
reakaleek e0b6e99
Fix preview-build.yml (#644)
reakaleek d78729a
Remove unused workflow (#646)
reakaleek 1c9b6df
Add validate command for single published repository (#648)
Mpdreamz 9e0d9e2
Refactor link index command into dedicated LinkRegistry module (#649)
Mpdreamz 6a40a78
Better error messages for cross_link errors (From `docs-builder` and …
Mpdreamz bb0c9ca
Add logging to git remote resolving (#652)
Mpdreamz 483f026
Update cross-repo links syntax info (#654)
leemthompo 2763ef7
If GITHUB_REPOSITORY is set use it verbatim (#655)
Mpdreamz a8d4f79
Share inbound-links commands with `docs-builder` (#657)
Mpdreamz 3f9eb40
Fix `environment_url` in preview deployment (#658)
reakaleek 4dcfb39
Adjust links and wording in primary and secondary navigation (#659)
reakaleek e3a5e36
Add mobile navigations (#662)
reakaleek 83a1955
Add extension hook points to all special usecases to inject themselve…
Mpdreamz c328730
Rename binary to follow kebab-case convention
Mpdreamz 812a2e2
Move lambda.DockerFile
Mpdreamz 29e0eb8
Update lambda.DockerFile
Mpdreamz 7059fae
Update README.md for publish-links-index-lambda with build instructions
Mpdreamz 1d551c5
Merge remote-tracking branch 'origin/main' into feature/publish-links…
Mpdreamz 0e6f0e0
Update src/docs-lambda-index-publisher/lambda.DockerFile
Mpdreamz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Diagnostics; | ||
using System.Text; | ||
using Amazon.Lambda.Core; | ||
using Amazon.Lambda.RuntimeSupport; | ||
using Amazon.S3; | ||
using Amazon.S3.Model; | ||
using Elastic.Markdown.CrossLinks; | ||
|
||
await LambdaBootstrapBuilder.Create(Handler) | ||
.Build() | ||
.RunAsync(); | ||
|
||
static async Task<string> Handler(ILambdaContext context) | ||
{ | ||
var sw = Stopwatch.StartNew(); | ||
IAmazonS3 client = new AmazonS3Client(); | ||
var bucketName = "elastic-docs-link-index"; | ||
var request = new ListObjectsV2Request | ||
{ | ||
BucketName = bucketName, | ||
MaxKeys = 5 | ||
}; | ||
|
||
var linkIndex = new LinkIndex | ||
{ | ||
Repositories = [] | ||
}; | ||
try | ||
{ | ||
ListObjectsV2Response response; | ||
do | ||
{ | ||
response = await client.ListObjectsV2Async(request, CancellationToken.None); | ||
foreach (var obj in response.S3Objects) | ||
{ | ||
if (!obj.Key.StartsWith("elastic/", StringComparison.OrdinalIgnoreCase)) | ||
continue; | ||
|
||
var tokens = obj.Key.Split('/'); | ||
if (tokens.Length < 3) | ||
continue; | ||
|
||
var repository = tokens[1]; | ||
var branch = tokens[2]; | ||
|
||
var entry = new LinkIndexEntry | ||
{ | ||
Repository = repository, | ||
Branch = branch, | ||
ETag = obj.ETag.Trim('"'), | ||
Path = obj.Key | ||
}; | ||
if (linkIndex.Repositories.TryGetValue(repository, out var existingEntry)) | ||
existingEntry[branch] = entry; | ||
else | ||
linkIndex.Repositories.Add(repository, new Dictionary<string, LinkIndexEntry> | ||
{ | ||
{ branch, entry } | ||
}); | ||
Console.WriteLine(entry); | ||
} | ||
|
||
// If the response is truncated, set the request ContinuationToken | ||
// from the NextContinuationToken property of the response. | ||
request.ContinuationToken = response.NextContinuationToken; | ||
} while (response.IsTruncated); | ||
} | ||
catch (AmazonS3Exception ex) | ||
{ | ||
return $"Error encountered on server. Message:'{ex.Message}' getting list of objects."; | ||
} | ||
|
||
var json = LinkIndex.Serialize(linkIndex); | ||
|
||
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); | ||
await client.UploadObjectFromStreamAsync(bucketName, "link-index.json", stream, new Dictionary<string, object>(), CancellationToken.None); | ||
return $"Finished in {sw}"; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Index Registry Update Lambda Function | ||
|
||
From a linux `x86_64` machine you can use the followint to build a AOT binary that will run | ||
|
||
on a vanilla `Amazon Linux 2023` without any dependencies. | ||
|
||
```bash | ||
docker build . -t publish-links-index:latest -f src/docs-lambda-index-publisher/lambda.DockerFile | ||
``` | ||
|
||
Then you can copy the published artifacts from the image using: | ||
|
||
```bash | ||
docker cp (docker create --name tc publish-links-index:latest):/app/.artifacts/publish ./.artifacts && docker rm tc | ||
``` | ||
|
||
The `bootstrap` binary should now be available under: | ||
|
||
``` | ||
.artifacts/publish/docs-lambda-index-publisher/release_linux-x64/bootstrap | ||
``` | ||
|
15 changes: 15 additions & 0 deletions
15
src/docs-lambda-index-publisher/aws-lambda-tools-defaults.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"Information": [ | ||
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", | ||
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", | ||
"dotnet lambda help", | ||
"All the command line options for the Lambda command can be specified in this file." | ||
], | ||
"profile": "", | ||
"region": "", | ||
"configuration": "Release", | ||
"function-runtime": "provided.al2", | ||
"function-memory-size": 512, | ||
"function-timeout": 180, | ||
"function-handler": "Elastic.Documentation.Lambda.LinkIndexUploader" | ||
} |
31 changes: 31 additions & 0 deletions
31
src/docs-lambda-index-publisher/docs-lambda-index-publisher.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
|
||
<AssemblyName>bootstrap</AssemblyName> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
|
||
<IsPublishable>true</IsPublishable> | ||
<PublishAot>true</PublishAot> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
<EnableSdkContainerSupport>true</EnableSdkContainerSupport> | ||
<TrimmerSingleWarn>false</TrimmerSingleWarn> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
|
||
<RootNamespace>Elastic.Documentation.Lambda.LinkIndexUploader</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.3"/> | ||
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.0"/> | ||
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4"/> | ||
<PackageReference Include="AWSSDK.S3" Version="3.7.414.5"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Elastic.Markdown\Elastic.Markdown.csproj"/> | ||
</ItemGroup> | ||
</Project> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS base | ||
|
||
ARG TARGETARCH | ||
ARG TARGETOS | ||
|
||
WORKDIR /app | ||
|
||
RUN rpm --import https://packages.microsoft.com/keys/microsoft.asc | ||
|
||
RUN curl -o /etc/yum.repos.d/microsoft-prod.repo https://packages.microsoft.com/config/fedora/39/prod.repo | ||
|
||
RUN dnf update -y | ||
RUN dnf install -y dotnet-sdk-9.0 | ||
RUN dnf install -y npm | ||
RUN dnf install -y git | ||
RUN dnf install -y clang | ||
|
||
#COPY ./src/ ./src/ | ||
#COPY ./tests/ ./tests/ | ||
#COPY ./docs/*.csproj ./docs/ | ||
#COPY ./.github/*.csproj ./.github/ | ||
#COPY ./build/*.fsproj ./build/ | ||
#COPY ./*.sln ./ | ||
|
||
COPY . . | ||
|
||
ENV DOTNET_NOLOGO=true | ||
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true | ||
Mpdreamz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
RUN arch=$TARGETARCH \ | ||
&& if [ "$arch" = "amd64" ]; then arch="x64"; fi \ | ||
&& echo $TARGETOS-$arch > /tmp/rid | ||
|
||
RUN dotnet publish src/docs-lambda-index-publisher -r linux-x64 -c Release | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.