-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathnix2container-image-info.yaml
81 lines (72 loc) · 2.69 KB
/
nix2container-image-info.yaml
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
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: nix2container-image-info
labels:
app.kubernetes.io/versions: "0.1"
spec:
description: >
Get the image name and tag from a nix2container flake output.
workspaces:
- name: optional-src
optional: true
description: |
The source repository to invoke from.
mountPath: /mnt
readOnly: true
- name: nix-store
description: |
An workspace containing a nix store. Appended via a `--store` argument.
readOnly: true
mountPath: /workspace/nix-store/nix
params:
- name: flakeOutput
type: string
description: |
The output of a Nix Flake. This output must refer to an image built with
nix2container.
See:
- https://nixos.wiki/wiki/Flakes for more in formation on the Flake
URL schema.
- https://github.com/nlewo/nix2container for more information on the
required builder for the flake outputs.
Examples:
- "/mnt/src_root#someoutput" for a flake output in the `output-src`
directory.
- "github:TraceMachina/nativelink#image" for the latest nativelink
image.
- "github:<user>/<repo>?ref=pull/<PR_NUMBER>/head#<PACKAGE>" to use
an image from a pull request of a repository on GitHub.
results:
- name: imageName
description: The Nix-derived image name.
- name: imageTag
description: The Nix-derived image tag.
steps:
- name: get-image-tags
image: nixpkgs/nix-flakes:latest
env:
- name: FLAKE_OUTPUT
value: "$(params.flakeOutput)"
script: |
#!/usr/bin/env sh
if [ "$(workspaces.optional-src.bound)" = "true" ]; then
cd "$(workspaces.optional-src.path)"
fi
if [ "$(uname -m)" = "x86_64" ] && [ "$(uname -s)" = "Linux" ]; then
NIX_SOCKET="unix:///workspace/nix-store/nix/var/nix/daemon-socket/socket"
NIX_ROOT="/workspace/nix-store"
NIX_STORE_OPTS="--store ${NIX_SOCKET}?root=${NIX_ROOT}"
else
NIX_STORE_OPTS=""
fi
echo "NIX_STORE_OPTS: '$NIX_STORE_OPTS'"
# Not ideal, but will have to do until we implement more elaborate git
# repo syncing schemes.
git config --global --add safe.directory "*"
IMAGE_NAME=$(nix eval $NIX_STORE_OPTS "${FLAKE_OUTPUT}".imageName --raw)
IMAGE_TAG=$(nix eval $NIX_STORE_OPTS "${FLAKE_OUTPUT}".imageTag --raw)
echo "Evaluated IMAGE_NAME: '$IMAGE_NAME'"
echo "Evaluated IMAGE_TAG: '$IMAGE_TAG'"
echo -n "${IMAGE_NAME}" > $(results.imageName.path)
echo -n "${IMAGE_TAG}" > $(results.imageTag.path)