forked from ansible/creator-ee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
163 lines (163 loc) · 5.6 KB
/
Taskfile.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
---
# see https://taskfile.dev/#/
# cspell: ignore buildx
version: "3"
output: group
env: &env
FORCE_COLOR: "true"
PRE_COMMIT_COLOR: always
vars:
HOSTNAME:
sh: echo ${HOSTNAME:-localhost}
CNT_NAME: creator-ee
VERSION:
sh: git describe --tags
CNT_NAME_TAG: "{{.CNT_NAME}}:{{.VERSION}}"
CNT_NAME_TAG_LATEST: "{{.CNT_NAME}}:latest"
CNT_ROOT: .
# Fail if we are not on a tagged commit
RELEASE_PRECHECK: git describe --tags --exact-match
tasks:
default:
desc: Run most commands
deps:
- setup
- lint
- build
cmds:
- echo {{.TASK}}
- echo Done {{.VERSION}}!
base:
desc: Build base image
deps:
- setup
sources:
- base/*
- .{{.CNT_NAME}}.done
vars: &base-vars
VERSION: "latest"
CNT_NAME: creator-base
CNT_NAME_TAG: "{{.CNT_NAME}}:{{.VERSION}}"
CNT_NAME_TAG_LATEST: "{{.CNT_NAME}}:latest"
CNT_ROOT: base/
RELEASE_PRECHECK: "true"
cmds:
- podman container prune -f
- podman manifest exists {{.CNT_NAME_TAG}} && podman manifest rm {{.CNT_NAME_TAG}} || true
- podman image exists {{.CNT_NAME_TAG}} && podman image rm -f {{.CNT_NAME_TAG}} || true
- podman buildx build ${EXTRA_OPTS:---platform=linux/amd64,linux/arm64} --load {{.CNT_ROOT}} --manifest localhost/{{.CNT_NAME_TAG}}
# running manifest exists is mandatory as this fails if no manifest is
# created locally. If this is skipped the inspect might pull the last
# published manifest instead of using the local one.
- podman manifest exists {{.CNT_NAME_TAG}}
# Fail if the manifest does not contain exactly two images
# Validate image
- ./_build/validate {{.CNT_NAME_TAG}}
# Without next step, podman will pull the base image from quay.io instead
# of using the locally built image when we chain: task base && task build
- podman tag localhost/{{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME}}:latest
- touch .{{.CNT_NAME}}.done
- echo "=== {{.CNT_NAME_TAG}} is ready! ==="
interactive: true
clean:
desc: Clean up all files that not tracked by git
cmds:
- git clean -dxf
# will clean cached images to ensure podman will rebuild containers instead of using a cached result
- podman image prune -f
setup:
desc: Install dependencies
env:
# used inside test-setup.sh
OS: "{{OS}}"
ARCH: "{{ARCH}}"
# needed to avoid warning about installing from galaxy
ANSIBLE_COLLECTIONS_PATH: collections
cmds:
- bash ./_build/test-setup.sh
- ansible-galaxy collection install -r _build/requirements.yml -p collections
sources:
- Taskfile.yml
- _build/requirements.yml
- _build/test-setup.sh
generates:
- out/log/manifest.yml
run: once
interactive: true
build:
desc: Build the project
deps:
- setup
- base
cmds:
- podman container prune -f
- podman manifest exists {{.CNT_NAME_TAG}} && podman manifest rm {{.CNT_NAME_TAG}} || true
- podman image exists {{.CNT_NAME_TAG}} && podman image rm -f {{.CNT_NAME_TAG}} || true
- podman buildx build ${EXTRA_OPTS:---platform=linux/amd64,linux/arm64} --build-arg=CONTAINER_NAME={{.CNT_NAME_TAG}} --load {{.CNT_ROOT}} --manifest {{.CNT_NAME_TAG}}
# running manifest exists is mandatory as this fails if no manifest is
# created locally. If this is skipped the inspect might pull the last
# published manifest instead of using the local one.
- podman manifest exists {{.CNT_NAME_TAG}}
# Fail if the manifest does not contain exactly two images
# Validate image
- ./_build/validate {{.CNT_NAME_TAG}}
# Without next step, podman will pull the base image from quay.io instead
# of using the locally built image when we chain: task base && task build
- podman tag localhost/{{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME}}:latest
- touch .{{.CNT_NAME}}.done
- echo "=== {{.CNT_NAME_TAG}} is ready! ==="
sources:
- Taskfile.yml
- base/*
- _build/*
- Containerfile
generates:
- .{{.CNT_NAME}}.done
interactive: true
exec:
desc: Open a container shell
deps:
- build
cmds:
- podman run --arch=$(arch) --rm -it {{.CNT_NAME_TAG}} /bin/bash
sources:
- Taskfile.yml
interactive: true
lint:
desc: Lint the project
deps:
- setup
cmds:
- python3 -m pre_commit run -a
- _build/dirty.sh
silent: true
pr:
desc: Opens a pull request using gh
deps:
- lint
cmds:
- gh pr create
interactive: true
release:
desc: Publish containers to all public registries (used by CI)
cmds:
- task: build
vars: *env
- "{{.RELEASE_PRECHECK}}"
- podman manifest push {{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME_TAG}}
- podman manifest push {{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME_TAG_LATEST}}
- podman manifest push {{.CNT_NAME_TAG}} ghcr.io/ansible/{{.CNT_NAME_TAG}}
- podman manifest push {{.CNT_NAME_TAG}} ghcr.io/ansible/{{.CNT_NAME_TAG_LATEST}}
interactive: true
release-base:
desc: Publish creator-base container (used by CI)
vars: *base-vars
cmds:
- task: base
vars: *base-vars
- "{{.RELEASE_PRECHECK}}"
- podman manifest push {{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME_TAG}}
- podman manifest push {{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME_TAG_LATEST}}
- podman manifest push {{.CNT_NAME_TAG}} ghcr.io/ansible/{{.CNT_NAME_TAG}}
- podman manifest push {{.CNT_NAME_TAG}} ghcr.io/ansible/{{.CNT_NAME_TAG_LATEST}}
interactive: true