-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpodman.tasks.yml
193 lines (177 loc) · 6.93 KB
/
podman.tasks.yml
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
version: "3"
tasks:
build:
desc: Build the '{{.IMAGE_NAME}}' image
summary: |
Build the '{{.IMAGE_NAME}}' image
This task builds the container image defined in {{.CONTAINERFILE}}.
Variables:
- IMAGE_NAME: Provide the image name, required.
- CONTAINERFILE: Provide the path to the Containerfile, required.
- IMAGE_TAG: Provide the image tag, defaults to `latest`.
- IMAGE: Provide the full image tag, defaults to `IMAGE_NAME:IMAGE_TAG`.
- PODMAN_OPTS: Optionally provide options for the `podman build` command.
requires:
vars:
- IMAGE_NAME
- CONTAINERFILE
vars:
IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}'
COMPUTED_IMAGE: '{{.IMAGE | default (printf "%s:%s" .IMAGE_NAME .IMAGE_TAG)}}'
FORMAT: '{{.FORMAT | default "oci"}}'
cmds:
- podman build .
--file {{.CONTAINERFILE}}
--tag {{.COMPUTED_IMAGE}}
--format {{.FORMAT}}
{{.PODMAN_OPTS}}
- task: test
vars: { IMAGE: '{{.COMPUTED_IMAGE}}' }
# TODO: Allow work avoidance but with dynamically provided files part of the
# Containerfile, otherwise it won't work when there are files copied into
# the container.
test:
desc: Test the '{{.IMAGE_NAME}}' image
summary: |
Test the '{{.IMAGE_NAME}}' image
This task tests that software defined in {{.EXPECTED_CONFIG}} is executable
and installed in the right version.
Variables:
- IMAGE_NAME: Provide the image name, required.
- IMAGE_TAG: Provide the image tag, defaults to `latest`.
- IMAGE: Provide the full image tag, defaults to `IMAGE_NAME:IMAGE_TAG`.
requires:
vars:
- IMAGE_NAME
- EXPECTED_CONFIG
vars:
IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}'
COMPUTED_IMAGE: '{{.IMAGE | default (printf "%s:%s" .IMAGE_NAME .IMAGE_TAG)}}'
cmds:
- bash common/scripts/check-versions.sh
{{.EXPECTED_CONFIG}}
{{.COMPUTED_IMAGE}}
preconditions:
- sh: which podman
msg: The `podman` CLI is required to run this task.
- sh: which yq
msg: The `yq` CLI is required to run this task.
- sh: which jq
msg: The `jq` CLI is required to run this task.
- sh: podman image exists {{.COMPUTED_IMAGE}}
msg: The `{{.COMPUTED_IMAGE}}` image does not exist. Have you built it already?
release:
desc: Release the '{{.IMAGE_NAME}}' image.
summary: |
Release the '{{.IMAGE_NAME}}' image
This task builds, tests, and creates a WSL distro for the image.
Variables:
- IMAGE_NAME: Provide the image name, required.
- IMAGE_TAG: Provide the image tag, defaults to `<branch>-<timestamp>-<short commit hash>`.
- IMAGE: Provide the full image tag, defaults to `IMAGE_NAME:IMAGE_TAG`.
- PODMAN_OPTS: Optionally provide options for the `podman run` command.
requires:
vars:
- IMAGE_NAME
vars:
TIMESTAMP:
sh: date -u +%Y-%m-%d_%H%M%S
GIT_BRANCH:
sh: git rev-parse --abbrev-ref HEAD | sed 's/[^a-zA-Z0-9._-]/-/g'
GIT_HASH:
sh: git describe --dirty --always --abbrev=8
IMAGE_TAG: '{{.IMAGE_TAG | default (printf "%s-%s-%s" .GIT_BRANCH .TIMESTAMP .GIT_HASH)}}'
COMPUTED_IMAGE: '{{.IMAGE | default (printf "%s:%s" .IMAGE_NAME .IMAGE_TAG)}}'
cmds:
- task: build
vars:
IMAGE: '{{.COMPUTED_IMAGE}}'
- task: wsl
vars:
IMAGE: '{{.COMPUTED_IMAGE}}'
IMAGE_TAG: '{{.IMAGE_TAG}}'
debug:
desc: Debug the '{{.IMAGE_NAME}}' image
summary: |
Debug the '{{.IMAGE_NAME}}' image
This task runs the container image and mounts the repository root into the
the container. The working dir is set to this mounted folder.
Variables:
- IMAGE_NAME: Provide the image name, required.
- IMAGE_TAG: Provide the image tag, defaults to `latest`.
- IMAGE: Provide the full image tag, defaults to `IMAGE_NAME:IMAGE_TAG`.
- PODMAN_OPTS: Optionally provide options for the `podman run` command.
requires:
vars:
- IMAGE_NAME
vars:
IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}'
COMPUTED_IMAGE: '{{.IMAGE | default (printf "%s:%s" .IMAGE_NAME .IMAGE_TAG)}}'
cmds:
- podman run
--rm -it
--volume .:/repo
--workdir /repo
{{.PODMAN_OPTS}}
{{.COMPUTED_IMAGE}}
interactive: true
preconditions:
- sh: which podman
msg: The `podman` CLI is required to run this task.
- sh: podman image exists {{.COMPUTED_IMAGE}}
msg: The `{{.COMPUTED_IMAGE}}` image does not exist. Have you built it already?
wsl:
desc: Build a WSL distro from '{{.IMAGE_NAME}}' image
summary: |
Build a WSL distro from '{{.IMAGE_NAME}}' image
This task builds a WSL distro based on the '{{.IMAGE_NAME}}' image.
The resulting tar archive can be imported on a Windows system with WSL
installed.
requires:
vars:
- IMAGE_NAME
vars:
IMAGE_TAG: '{{.IMAGE_TAG | default "latest"}}'
COMPUTED_IMAGE: '{{.IMAGE | default (printf "%s:%s" .IMAGE_NAME .IMAGE_TAG)}}'
BUILD_PATH: "build"
TMP_PATH: "{{.BUILD_PATH}}/{{.IMAGE_NAME}}-{{.IMAGE_TAG}}/"
ROOTFS_TAR: "{{.TMP_PATH}}/{{.IMAGE_NAME}}-{{.IMAGE_TAG}}.tar"
ZIP_ARCHIVE: "{{.IMAGE_NAME}}-{{.IMAGE_TAG}}.zip"
cmds:
# Export container filesystem
- |
set -o pipefail
NAME={{.IMAGE_NAME}}-export-$(date +%s)
podman run --name $NAME --tty {{.COMPUTED_IMAGE}} ls / > /dev/null
ID=$(podman ps --all | grep -i $NAME | awk '{ print $1 }')
mkdir -p {{.TMP_PATH}}
podman export --output {{.ROOTFS_TAR}} $ID
podman rm -f $ID
# Prepare archive contents
- cp common/wsl/* {{.TMP_PATH}}/.
- sed -i {{.TMP_PATH}}/installer.ps1
-e 's/<name>/{{.IMAGE_NAME}}-{{.IMAGE_TAG}}/'
-e 's/<tar>/{{.IMAGE_NAME}}-{{.IMAGE_TAG}}.tar/'
# Create archive
- |
pushd {{.BUILD_PATH}} || exit 1
zip -r {{.ZIP_ARCHIVE}} {{.IMAGE_NAME}}-{{.IMAGE_TAG}}
popd || exit 1
status:
- test -f {{.ROOTFS_TAR}}
# Task is up-to-date if container image is older than build artifact
- |
image_creation_time_utc=$(podman inspect {{.COMPUTED_IMAGE}} --format '{{`{{.Created}}`}}' \
| cut -d. -f1 \
| xargs -I{} date -u -d {} +%s)
build_creation_time_utc=$(TZ=UTC stat -c %Y {{.ROOTFS_TAR}})
test "$image_creation_time_utc" -lt "$build_creation_time_utc"
preconditions:
- sh: which podman
msg: The `podman` CLI is required to run this task.
- sh: which awk
msg: The `awk` CLI is required to run this task.
- sh: which zip
msg: The `zip` CLI is required to run this task.
- sh: podman image exists {{.COMPUTED_IMAGE}}
msg: The `{{.COMPUTED_IMAGE}}` image does not exist. Have you built it already?