diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad528d107..fd48a1954 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: - name: Run Container if: ${{ matrix.os == 'ubuntu-latest' }} - run: docker run elastic/docs-builder:ci-${{ github.event.pull_request.number }} --help + run: dotnet run --project build -c release -- runlocalcontainer integration: diff --git a/build/CommandLine.fs b/build/CommandLine.fs index 87feb1d96..94b13bade 100644 --- a/build/CommandLine.fs +++ b/build/CommandLine.fs @@ -34,6 +34,7 @@ type Build = | [] Publish | [] PublishBinaries + | [] RunLocalContainer | [] PublishContainers | [] PublishZip @@ -67,6 +68,7 @@ with | PristineCheck | PublishBinaries | PublishContainers + | RunLocalContainer | PublishZip | ValidateLicenses | Compile diff --git a/build/Targets.fs b/build/Targets.fs index 547b21dad..f9c04512b 100644 --- a/build/Targets.fs +++ b/build/Targets.fs @@ -73,37 +73,51 @@ let private publishZip _ = ] zip "docs-builder" zip "docs-assembler" + +let private prNumber () = + match Environment.environVarOrNone "GITHUB_REF_NAME" with + | None -> None + | Some s when s.EndsWith "/merge" -> Some (s.Split('/') |> Seq.head) + | _ -> None + +let private imageTags () = + let pr = prNumber() + let exitCode = exec { + validExitCode (fun _ -> true) + exit_code_of "git" "describe" "--tags" "--exact-match" "HEAD" + } + match (exitCode, pr) with + | 0, _ -> "edge;latest" + | _, None -> "edge" + | _, Some pr -> $"ci-%s{pr}" + +let private runLocalContainer _ = + let tag = + match imageTags() with + | ci when ci.StartsWith("ci-") -> ci + | _ -> "edge" + let image = $"elastic/docs-builder:%s{tag}" + exec { run "docker" ["docker"; "run"; image; "--help"] } let private publishContainers _ = let createImage project = let ci = Environment.environVarOrNone "GITHUB_ACTIONS" - let pr = - match Environment.environVarOrNone "GITHUB_REF_NAME" with - | None -> None - | Some s when s.EndsWith "/merge" -> Some (s.Split('/') |> Seq.head) - | _ -> None - let imageTag = + let pr = prNumber() + let baseImageTag = match project with | _ -> "9.0-noble-chiseled-aot" - let labels = - let exitCode = exec { - validExitCode (fun _ -> true) - exit_code_of "git" "describe" "--tags" "--exact-match" "HEAD" - } - match (exitCode, pr) with - | 0, _ -> "edge;latest" - | _, None -> "edge" - | _, Some pr -> $"ci-%s{pr}" + let labels = imageTags() let args = ["publish"; $"src/tooling/%s{project}/%s{project}.csproj"] @ [ "/t:PublishContainer"; "-p"; "DebugType=none"; - "-p"; $"ContainerBaseImage=mcr.microsoft.com/dotnet/nightly/runtime-deps:%s{imageTag}"; + "-p"; $"ContainerBaseImage=mcr.microsoft.com/dotnet/nightly/runtime-deps:%s{baseImageTag}"; "-p"; $"ContainerImageTags=\"%s{labels};%s{Software.Version.Normalize()}\"" "-p"; $"ContainerRepository=elastic/%s{project}" ] + let noPublish = Environment.environVarOrNone "DOCKER_NO_PUBLISH" let registry = match (ci, pr, noPublish) with @@ -172,6 +186,7 @@ let Setup (parsed:ParseResults) = | PristineCheck -> Build.Step pristineCheck | PublishBinaries -> Build.Step publishBinaries | PublishContainers -> Build.Step publishContainers + | RunLocalContainer -> Build.Step runLocalContainer | PublishZip -> Build.Step publishZip | ValidateLicenses -> Build.Step validateLicenses