-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathniximage.nix
More file actions
149 lines (136 loc) · 4.2 KB
/
Copy pathniximage.nix
File metadata and controls
149 lines (136 loc) · 4.2 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# SPDX-License-Identifier: MIT
{
pkgs,
lib,
nixkubeVersion ?
(builtins.fromTOML (builtins.readFile ./pkgs/nixkube/pyproject.toml)).project.version,
}:
rec {
server = "ghcr.io";
repo = "${server}/lillecarl/nix-csi";
images = lib.genAttrs [ "aarch64-linux" "x86_64-linux" ] (
system:
let
sysPkgs = import pkgs.path {
inherit system;
overlays = [
(import ./pkgs)
];
};
inherit (sysPkgs) lib;
fakeNss = sysPkgs.dockerTools.fakeNss.override {
extraGroupLines = [
"nixbld:x:30000:"
];
};
runtimeInputs = [
sysPkgs.coreutils
sysPkgs.gitMinimal
sysPkgs.nix
sysPkgs.rsync
sysPkgs.openssh
sysPkgs.kubectl
];
# TODO: consolidate init-copy and init-secrets into the same file (not same script)
# ConfigMap or OCI? I think ConfigMap?
init-copy = sysPkgs.writeShellApplication {
name = "init-copy";
inherit runtimeInputs;
text = # bash
''
set -euo pipefail
set -x
mkdir /tmp
rsync --archive ${fakeNss}/ /
# Resolve the correct store path for this architecture from the JSON NODE_ENV
STORE_PATH=$(nix eval --store dummy:// --raw --impure --expr \
'(builtins.fromJSON (builtins.getEnv "NODE_ENV")).${system}')
# Check if we can SSH to pynixd
EXTRA_SUBSTITUTERS="local?trusted=true"
if nix store ping --store ssh-ng://nix@pynixd; then
EXTRA_SUBSTITUTERS="$EXTRA_SUBSTITUTERS ssh-ng://nix@pynixd?trusted=true"
fi
nix \
build \
--extra-substituters "$EXTRA_SUBSTITUTERS" \
--max-jobs auto \
--option sandbox false \
--store /nix-volume \
--out-link /nix-volume/nix/var/result \
--fallback \
"$STORE_PATH"
'';
};
init-secrets = sysPkgs.writeShellApplication {
name = "init-secrets";
inherit runtimeInputs;
text = # bash
''
set -euo pipefail
set -x
mkdir /tmp
rsync --archive ${fakeNss}/ /
# shellcheck source=/dev/null
source /opt/bin/init-secrets
'';
};
in
pkgs.dockerTools.streamLayeredImage {
name = "${repo}/nix";
tag = "${sysPkgs.nix.version}-${nixkubeVersion}-${sysPkgs.stdenv.hostPlatform.system}";
architecture = sysPkgs.go.GOARCH;
maxLayers = 125;
includeNixDB = true;
contents = [
sysPkgs.dockerTools.binSh
sysPkgs.dockerTools.caCertificates
sysPkgs.dockerTools.usrBinEnv
];
config = {
Entrypoint = [ (lib.getExe init-copy) ];
Env = [
"PATH=${
lib.makeBinPath [
init-copy
init-secrets
]
}"
];
};
}
);
imageRef = system: "${images.${system}.imageName}:${images.${system}.imageTag}";
# Per-arch push scripts (one per system, used by per-arch CI jobs)
pushArch = lib.mapAttrs (
system: image:
pkgs.writeShellApplication {
name = "push-nix-${system}";
runtimeInputs = [
pkgs.skopeo
pkgs.gzip
pkgs.cachix
];
text = # bash
''
skopeo login -u="$REPO_USERNAME" -p="$REPO_TOKEN" ${server}
${image} | gzip --fast | skopeo copy docker-archive:/dev/stdin docker://${imageRef system}
cachix push nix-csi ${image}
'';
}
) images;
# Manifest creation (used by dependent CI job after both arches are pushed)
pushManifest = pkgs.writeShellApplication {
name = "push-nix-manifest";
runtimeInputs = [ pkgs.regctl ];
text = # bash
''
regctl registry login -u="$REPO_USERNAME" -p="$REPO_TOKEN" ${server}
regctl index create ${repo}/nix:${pkgs.nix.version}-${nixkubeVersion} \
--ref ${imageRef "aarch64-linux"} \
--ref ${imageRef "x86_64-linux"}
regctl index create ${repo}/nix:latest \
--ref ${imageRef "aarch64-linux"} \
--ref ${imageRef "x86_64-linux"}
'';
};
}