|
4 | 4 |
|
5 | 5 | module Targets |
6 | 6 |
|
| 7 | +open System.IO |
| 8 | +open System.IO.Compression |
7 | 9 | open Argu |
8 | 10 | open CommandLine |
9 | 11 | open Fake.Core |
@@ -150,6 +152,73 @@ let private runTests (testSuite: TestSuite) _ = |
150 | 152 | ) |
151 | 153 | } |
152 | 154 |
|
| 155 | +let private compressibleExtensions = set [".html"; ".css"; ".js"; ".json"; ".svg"; ".xml"; ".txt"] |
| 156 | + |
| 157 | +let private gzipCompressDirectory (directory: string) = |
| 158 | + // Remove stale .gz files from any previous run to avoid orphaned pairs |
| 159 | + Directory.EnumerateFiles(directory, "*.gz", SearchOption.AllDirectories) |
| 160 | + |> Seq.toArray |
| 161 | + |> Array.iter File.Delete |
| 162 | + |
| 163 | + let files = |
| 164 | + Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories) |
| 165 | + |> Seq.filter (fun f -> |
| 166 | + match Path.GetExtension(f) with |
| 167 | + | null -> false |
| 168 | + | ext -> compressibleExtensions.Contains(ext.ToLowerInvariant()) |
| 169 | + ) |
| 170 | + |> Seq.toArray |
| 171 | + |
| 172 | + printfn $"Compressing %d{files.Length} files in %s{directory}" |
| 173 | + |
| 174 | + files |
| 175 | + |> Array.Parallel.iter (fun file -> |
| 176 | + let gzPath = file + ".gz" |
| 177 | + use input = File.OpenRead(file) |
| 178 | + use output = File.Create(gzPath) |
| 179 | + use gzip = new GZipStream(output, CompressionLevel.SmallestSize) |
| 180 | + input.CopyTo(gzip) |
| 181 | + ) |
| 182 | + |
| 183 | + // Replace originals with zero-byte placeholders so nginx try_files can resolve |
| 184 | + // paths, while gzip_static always serves the .gz version |
| 185 | + for file in files do |
| 186 | + File.Delete(file) |
| 187 | + File.Create(file).Dispose() |
| 188 | + |
| 189 | + printfn "Compression complete" |
| 190 | + |
| 191 | +let private airGappedBuild _ = |
| 192 | + let assemblyDir = Path.Combine(Paths.Root.FullName, ".artifacts", "assembly") |
| 193 | + if Directory.Exists(assemblyDir) then |
| 194 | + Directory.Delete(assemblyDir, true) |
| 195 | + |
| 196 | + exec { run "dotnet" "run" "--project" "src/tooling/docs-builder" "--" "assembler" "clone" "--environment" "air-gapped" } |
| 197 | + exec { run "dotnet" "run" "--project" "src/tooling/docs-builder" "--" "assembler" "build" "--exporters" "html" "--environment" "air-gapped" } |
| 198 | + let searchDir = Path.Combine(assemblyDir, "docs", "_search") |
| 199 | + if Directory.Exists(searchDir) then |
| 200 | + Directory.Delete(searchDir, true) |
| 201 | + |
| 202 | + File.WriteAllText( |
| 203 | + Path.Combine(assemblyDir, "index.html"), |
| 204 | + """<meta http-equiv="refresh" content="0;url=/docs">""" |
| 205 | + ) |
| 206 | + |
| 207 | + gzipCompressDirectory assemblyDir |
| 208 | + |
| 209 | + exec { |
| 210 | + run "docker" "build" |
| 211 | + "-f" "build/air-gapped/Dockerfile" |
| 212 | + "--build-context" "content=.artifacts/assembly" |
| 213 | + "--build-context" "config=build/air-gapped" |
| 214 | + "-t" "elastic-docs-air-gapped" |
| 215 | + "build/air-gapped" |
| 216 | + } |
| 217 | + |
| 218 | +let private airGappedRun _ = |
| 219 | + printfn "Running at http://localhost:8080" |
| 220 | + exec { run "docker" "run" "-p" "127.0.0.1:8080:8080" "elastic-docs-air-gapped" } |
| 221 | + |
153 | 222 | let private validateLicenses _ = |
154 | 223 | let args = ["-u"; "-t"; "-i"; "docs-builder.sln"; "--use-project-assets-json" |
155 | 224 | "--forbidden-license-types"; "build/forbidden-license-types.json" |
@@ -196,6 +265,8 @@ let Setup (parsed:ParseResults<Build>) = |
196 | 265 | | RunLocalContainer -> Build.Step runLocalContainer |
197 | 266 | | PublishZip -> Build.Step publishZip |
198 | 267 | | ValidateLicenses -> Build.Step validateLicenses |
| 268 | + | Air_Gapped_Build -> Build.Cmd [] [] airGappedBuild |
| 269 | + | Air_Gapped_Run -> Build.Cmd [] [] airGappedRun |
199 | 270 |
|
200 | 271 | // flags |
201 | 272 | | Single_Target |
|
0 commit comments