-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.csando
More file actions
72 lines (61 loc) · 2.37 KB
/
build.csando
File metadata and controls
72 lines (61 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// <file>
// <summary>
// Ando build script for Hawk.
//
// Usage:
// - `ando run` : restore, build, and test
// - `ando run -p publish` : dotnet publish to ./artifacts/publish/Hawk.Web
// - `ando run --dind -p publish` : publish + build container (and push to GHCR if GHCR_IMAGE is set)
//
// Notes:
// - The container image only contains the web app. SQL Server is external and configured via connection string.
// - Set project version in *.csproj (currently 0.9.8). This is required for `ando release` workflows.
// </summary>
// </file>
Ando.UseImage("mcr.microsoft.com/dotnet/sdk:10.0");
var publish = DefineProfile("publish");
var web = Dotnet.Project("./Hawk.Web/Hawk.Web.csproj");
var tests = Dotnet.Project("./Hawk.Tests/Hawk.Tests.csproj");
var version = web.Version;
var configuration = global::Ando.Workflow.Configuration.Release;
var artifacts = Root / "artifacts";
var publishDir = artifacts / "publish" / "Hawk.Web";
Dotnet.Restore(tests);
Dotnet.Build(web, o =>
{
o.Configuration = configuration;
o.NoRestore = true;
});
Dotnet.Test(tests, o => o.Configuration = configuration);
if (publish)
{
Dotnet.Publish(web, o => o
.WithConfiguration(configuration)
.SkipRestore()
.SkipBuild()
.Output(publishDir));
// Container publish (like ~/Source/ando/build.csando):
// - Builds multi-arch and pushes to GHCR (no local-only image builds).
// - Override image name with GHCR_IMAGE (ghcr.io/<owner>/<name>).
//
// Notes:
// - Docker ops require `ando --dind`.
// - Auth: Ando auto-logins to ghcr.io when pushing using `GITHUB_TOKEN` (or `gh auth token`).
Docker.Install();
var ghcrOwner =
Env("GITHUB_REPOSITORY_OWNER", required: false) ??
Env("GHCR_OWNER", required: false) ??
"aduggleby";
var ghcrImage =
Env("GHCR_IMAGE", required: false) ??
$"ghcr.io/{ghcrOwner}/hawk";
Log.Info($"Building and pushing multi-arch image: {ghcrImage}:{version}");
Docker.Build("./Hawk.Web/Dockerfile", o => o
.WithPlatforms("linux/amd64", "linux/arm64")
.WithTag($"{ghcrImage}:{version}")
.WithTag($"{ghcrImage}:latest")
.WithContext(".")
.WithPush());
// Builds run in containers; copy outputs back to the host for local inspection/CI artifacts.
Ando.CopyZippedArtifactsToHost("artifacts", "./artifacts");
}