Skip to content

Commit 7eeb49f

Browse files
authored
Running local container on main attempts to run ci-<PR> (#1788)
1 parent 717279d commit 7eeb49f

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105

106106
- name: Run Container
107107
if: ${{ matrix.os == 'ubuntu-latest' }}
108-
run: docker run elastic/docs-builder:ci-${{ github.event.pull_request.number }} --help
108+
run: dotnet run --project build -c release -- runlocalcontainer
109109

110110

111111
integration:

build/CommandLine.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Build =
3434

3535
| [<CliPrefix(CliPrefix.None);SubCommand>] Publish
3636
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PublishBinaries
37+
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] RunLocalContainer
3738
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PublishContainers
3839
| [<CliPrefix(CliPrefix.None);Hidden;SubCommand>] PublishZip
3940

@@ -67,6 +68,7 @@ with
6768
| PristineCheck
6869
| PublishBinaries
6970
| PublishContainers
71+
| RunLocalContainer
7072
| PublishZip
7173
| ValidateLicenses
7274
| Compile

build/Targets.fs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,37 +73,51 @@ let private publishZip _ =
7373
]
7474
zip "docs-builder"
7575
zip "docs-assembler"
76+
77+
let private prNumber () =
78+
match Environment.environVarOrNone "GITHUB_REF_NAME" with
79+
| None -> None
80+
| Some s when s.EndsWith "/merge" -> Some (s.Split('/') |> Seq.head)
81+
| _ -> None
82+
83+
let private imageTags () =
84+
let pr = prNumber()
85+
let exitCode = exec {
86+
validExitCode (fun _ -> true)
87+
exit_code_of "git" "describe" "--tags" "--exact-match" "HEAD"
88+
}
89+
match (exitCode, pr) with
90+
| 0, _ -> "edge;latest"
91+
| _, None -> "edge"
92+
| _, Some pr -> $"ci-%s{pr}"
93+
94+
let private runLocalContainer _ =
95+
let tag =
96+
match imageTags() with
97+
| ci when ci.StartsWith("ci-") -> ci
98+
| _ -> "edge"
99+
let image = $"elastic/docs-builder:%s{tag}"
100+
exec { run "docker" ["docker"; "run"; image; "--help"] }
76101

77102
let private publishContainers _ =
78103

79104
let createImage project =
80105
let ci = Environment.environVarOrNone "GITHUB_ACTIONS"
81-
let pr =
82-
match Environment.environVarOrNone "GITHUB_REF_NAME" with
83-
| None -> None
84-
| Some s when s.EndsWith "/merge" -> Some (s.Split('/') |> Seq.head)
85-
| _ -> None
86-
let imageTag =
106+
let pr = prNumber()
107+
let baseImageTag =
87108
match project with
88109
| _ -> "9.0-noble-chiseled-aot"
89-
let labels =
90-
let exitCode = exec {
91-
validExitCode (fun _ -> true)
92-
exit_code_of "git" "describe" "--tags" "--exact-match" "HEAD"
93-
}
94-
match (exitCode, pr) with
95-
| 0, _ -> "edge;latest"
96-
| _, None -> "edge"
97-
| _, Some pr -> $"ci-%s{pr}"
110+
let labels = imageTags()
98111
let args =
99112
["publish"; $"src/tooling/%s{project}/%s{project}.csproj"]
100113
@ [
101114
"/t:PublishContainer";
102115
"-p"; "DebugType=none";
103-
"-p"; $"ContainerBaseImage=mcr.microsoft.com/dotnet/nightly/runtime-deps:%s{imageTag}";
116+
"-p"; $"ContainerBaseImage=mcr.microsoft.com/dotnet/nightly/runtime-deps:%s{baseImageTag}";
104117
"-p"; $"ContainerImageTags=\"%s{labels};%s{Software.Version.Normalize()}\""
105118
"-p"; $"ContainerRepository=elastic/%s{project}"
106119
]
120+
107121
let noPublish = Environment.environVarOrNone "DOCKER_NO_PUBLISH"
108122
let registry =
109123
match (ci, pr, noPublish) with
@@ -172,6 +186,7 @@ let Setup (parsed:ParseResults<Build>) =
172186
| PristineCheck -> Build.Step pristineCheck
173187
| PublishBinaries -> Build.Step publishBinaries
174188
| PublishContainers -> Build.Step publishContainers
189+
| RunLocalContainer -> Build.Step runLocalContainer
175190
| PublishZip -> Build.Step publishZip
176191
| ValidateLicenses -> Build.Step validateLicenses
177192

0 commit comments

Comments
 (0)