Skip to content

Commit 24e8aa9

Browse files
committed
contrast.{resourcegen,cli,e2e}: split from core package
resourcegen,cli and e2e are tools meant to run on the operator's side while coordinator and initializer are binaries that run on the cluster. As we want to decouple the contrast binaries from the runtime binaries, it makes sense to split them so that they can be built separately. Signed-off-by: Spyros Seimenis <sse@edgeless.systems>
1 parent 3a0d5f7 commit 24e8aa9

File tree

3 files changed

+174
-39
lines changed

3 files changed

+174
-39
lines changed
Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,101 @@
11
# Copyright 2025 Edgeless Systems GmbH
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
{ contrast }: contrast.cli
4+
{
5+
lib,
6+
buildGoModule,
7+
contrast,
8+
kata,
9+
installShellFiles,
10+
contrastPkgsStatic,
11+
reference-values,
12+
}:
13+
14+
buildGoModule (finalAttrs: {
15+
pname = "${contrast.pname}-cli";
16+
inherit (contrast)
17+
version
18+
proxyVendor
19+
vendorHash
20+
;
21+
22+
# The source of the main module of this repo. We filter for Go files so that
23+
# changes in the other parts of this repo don't trigger a rebuild.
24+
src =
25+
let
26+
inherit (lib) fileset path hasSuffix;
27+
root = ../../../../.;
28+
in
29+
fileset.toSource {
30+
inherit root;
31+
fileset = fileset.unions [
32+
(path.append root "go.mod")
33+
(path.append root "go.sum")
34+
(path.append root "cli/cmd/assets/image-replacements.txt")
35+
(fileset.fileFilter (file: hasSuffix ".yaml" file.name) (
36+
path.append root "internal/kuberesource/assets"
37+
))
38+
(path.append root "internal/manifest/Milan.pem")
39+
(path.append root "internal/manifest/Genoa.pem")
40+
(path.append root "internal/manifest/Intel_SGX_Provisioning_Certification_RootCA.pem")
41+
(fileset.intersection (fileset.fileFilter (file: hasSuffix ".go" file.name) root) (
42+
fileset.unions [
43+
(path.append root "internal")
44+
(path.append root "cli")
45+
(path.append root "sdk")
46+
]
47+
))
48+
];
49+
};
50+
51+
subPackages = [ "cli" ];
52+
53+
nativeBuildInputs = [ installShellFiles ];
54+
55+
prePatch = ''
56+
install -D ${lib.getExe contrastPkgsStatic.kata.genpolicy} cli/genpolicy/assets/genpolicy-kata
57+
install -D ${kata.genpolicy.rules}/genpolicy-rules.rego cli/genpolicy/assets/genpolicy-rules-kata.rego
58+
install -D ${reference-values} internal/manifest/assets/reference-values.json
59+
'';
60+
61+
# postPatch will be overwritten by the release-cli derivation, prePatch won't.
62+
postPatch = ''
63+
install -D ${kata.genpolicy.settings-dev}/genpolicy-settings.json cli/genpolicy/assets/genpolicy-settings-kata.json
64+
'';
65+
66+
env.CGO_ENABLED = 0;
67+
68+
ldflags = [
69+
"-s"
70+
"-X github.com/edgelesssys/contrast/internal/constants.Version=v${finalAttrs.version}"
71+
"-X github.com/edgelesssys/contrast/internal/constants.KataGenpolicyVersion=${kata.genpolicy.version}"
72+
];
73+
74+
tags = [ "contrast_unstable_api" ];
75+
76+
preCheck = ''
77+
export CGO_ENABLED=1
78+
'';
79+
80+
checkPhase = ''
81+
runHook preCheck
82+
go test -tags=${lib.concatStringsSep "," finalAttrs.tags} -race ./cli/...
83+
runHook postCheck
84+
'';
85+
86+
postInstall = ''
87+
# rename the cli binary to contrast
88+
mv "$out/bin/cli" "$out/bin/contrast"
89+
90+
installShellCompletion --cmd contrast \
91+
--bash <($out/bin/contrast completion bash) \
92+
--fish <($out/bin/contrast completion fish) \
93+
--zsh <($out/bin/contrast completion zsh)
94+
'';
95+
96+
# Skip fixup as binaries are already stripped and we don't
97+
# need any other fixup, saving some seconds.
98+
dontFixup = true;
99+
100+
meta.mainProgram = "contrast";
101+
})

packages/by-name/contrast/contrast/package.nix

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
{
55
lib,
66
buildGoModule,
7-
kata,
8-
installShellFiles,
9-
contrastPkgsStatic,
107
reference-values,
118
}:
129

1310
let
1411
packageOutputs = [
1512
"coordinator"
1613
"initializer"
17-
"cli"
1814
];
1915
in
2016

@@ -36,7 +32,6 @@ buildGoModule (finalAttrs: {
3632
fileset = fileset.unions [
3733
(path.append root "go.mod")
3834
(path.append root "go.sum")
39-
(path.append root "cli/cmd/assets/image-replacements.txt")
4035
(fileset.fileFilter (file: hasSuffix ".dat" file.name) (
4136
path.append root "internal/attestation/tdx/qgs/testdata"
4237
))
@@ -46,15 +41,12 @@ buildGoModule (finalAttrs: {
4641
(path.append root "internal/manifest/Milan.pem")
4742
(path.append root "internal/manifest/Genoa.pem")
4843
(path.append root "internal/manifest/Intel_SGX_Provisioning_Certification_RootCA.pem")
49-
(fileset.difference (fileset.fileFilter (file: hasSuffix ".go" file.name) root) (
44+
(fileset.intersection (fileset.fileFilter (file: hasSuffix ".go" file.name) root) (
5045
fileset.unions [
51-
(path.append root "service-mesh")
52-
(path.append root "tools")
53-
(path.append root "imagepuller")
54-
(path.append root "imagestore")
55-
(path.append root "initdata-processor")
56-
(path.append root "e2e")
57-
(path.append root "nodeinstaller")
46+
(path.append root "internal")
47+
(path.append root "coordinator")
48+
(path.append root "initializer")
49+
(path.append root "sdk")
5850
]
5951
))
6052
];
@@ -63,27 +55,17 @@ buildGoModule (finalAttrs: {
6355
proxyVendor = true;
6456
vendorHash = "sha256-bZqDo21FxfE76iZmlYcQmwerH4V5fYyi53XI4Vy8kro=";
6557

66-
nativeBuildInputs = [ installShellFiles ];
67-
68-
subPackages = packageOutputs ++ [ "internal/kuberesource/resourcegen" ];
58+
subPackages = packageOutputs;
6959

7060
prePatch = ''
71-
install -D ${lib.getExe contrastPkgsStatic.kata.genpolicy} cli/genpolicy/assets/genpolicy-kata
72-
install -D ${kata.genpolicy.rules}/genpolicy-rules.rego cli/genpolicy/assets/genpolicy-rules-kata.rego
7361
install -D ${reference-values} internal/manifest/assets/reference-values.json
7462
'';
7563

76-
# postPatch will be overwritten by the release-cli derivation, prePatch won't.
77-
postPatch = ''
78-
install -D ${kata.genpolicy.settings-dev}/genpolicy-settings.json cli/genpolicy/assets/genpolicy-settings-kata.json
79-
'';
80-
8164
env.CGO_ENABLED = 0;
8265

8366
ldflags = [
8467
"-s"
8568
"-X github.com/edgelesssys/contrast/internal/constants.Version=v${finalAttrs.version}"
86-
"-X github.com/edgelesssys/contrast/internal/constants.KataGenpolicyVersion=${kata.genpolicy.version}"
8769
];
8870

8971
tags = [ "contrast_unstable_api" ];
@@ -103,22 +85,9 @@ buildGoModule (finalAttrs: {
10385
mkdir -p "''${!sub}/bin"
10486
mv "$out/bin/$sub" "''${!sub}/bin/$sub"
10587
done
106-
107-
# rename the cli binary to contrast
108-
mv "$cli/bin/cli" "$cli/bin/contrast"
109-
110-
installShellCompletion --cmd contrast \
111-
--bash <($cli/bin/contrast completion bash) \
112-
--fish <($cli/bin/contrast completion fish) \
113-
--zsh <($cli/bin/contrast completion zsh)
114-
115-
mkdir -p $cli/share
116-
mv $out/share/* $cli/share
11788
'';
11889

11990
# Skip fixup as binaries are already stripped and we don't
12091
# need any other fixup, saving some seconds.
12192
dontFixup = true;
122-
123-
meta.mainProgram = "contrast";
12493
})
Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,73 @@
11
# Copyright 2025 Edgeless Systems GmbH
22
# SPDX-License-Identifier: BUSL-1.1
33

4-
{ contrast }: contrast.out
4+
{
5+
lib,
6+
buildGoModule,
7+
contrast,
8+
reference-values,
9+
}:
10+
11+
buildGoModule (_finalAttrs: {
12+
pname = "${contrast.pname}-resourcegen";
13+
inherit (contrast)
14+
version
15+
proxyVendor
16+
vendorHash
17+
;
18+
19+
# The source of the main module of this repo. We filter for Go files so that
20+
# changes in the other parts of this repo don't trigger a rebuild.
21+
src =
22+
let
23+
inherit (lib) fileset path hasSuffix;
24+
root = ../../../../.;
25+
in
26+
fileset.toSource {
27+
inherit root;
28+
fileset = fileset.unions [
29+
(path.append root "go.mod")
30+
(path.append root "go.sum")
31+
(fileset.fileFilter (file: hasSuffix ".yaml" file.name) (
32+
path.append root "internal/kuberesource/assets"
33+
))
34+
(path.append root "internal/manifest/Milan.pem")
35+
(path.append root "internal/manifest/Genoa.pem")
36+
(path.append root "internal/manifest/Intel_SGX_Provisioning_Certification_RootCA.pem")
37+
(fileset.intersection (fileset.fileFilter (file: hasSuffix ".go" file.name) root) (
38+
fileset.unions [
39+
(path.append root "internal/attestation")
40+
(path.append root "internal/constants")
41+
(path.append root "internal/idblock")
42+
(path.append root "internal/kuberesource")
43+
(path.append root "internal/manifest")
44+
(path.append root "internal/platforms")
45+
(path.append root "internal/userapi")
46+
]
47+
))
48+
];
49+
};
50+
51+
subPackages = [ "internal/kuberesource/resourcegen" ];
52+
53+
prePatch = ''
54+
install -D ${reference-values} internal/manifest/assets/reference-values.json
55+
'';
56+
57+
env.CGO_ENABLED = 0;
58+
59+
ldflags = [
60+
"-s"
61+
];
62+
63+
tags = [ "contrast_unstable_api" ];
64+
65+
# Skip fixup as binaries are already stripped and we don't
66+
# need any other fixup, saving some seconds.
67+
dontFixup = true;
68+
69+
meta = {
70+
description = "Resource generator for Contrast";
71+
mainProgram = "resourcegen";
72+
};
73+
})

0 commit comments

Comments
 (0)