-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.runner_helper.mk
229 lines (188 loc) · 10.7 KB
/
Makefile.runner_helper.mk
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# -------------------------------------------------------------------------------
# The following make file does two things:
# 1. Create binaries for the gitlab-runner-helper app which can be found in
# `./apps/gitlab-runner-helper` for all the platforms we want to support.
# 2. Create Linux containers and extract their file system to be used later to
# build/publish.
#
# If you want to add a new arch or OS you would need to add a new
# file path to the $BINARIES variables and a new GO_ARCH_{{arch}}-{{OS}}
# variable. Note that Linux is implied by default.
# ---------------------------------------------------------------------------
TAR_XZ_ARGS ?= -f -0
# Tar files that we want to generate from the Docker file system, this is
# generally used for linux based Dockerfiles.
BASE_TAR_PATH := out/helper-images/prebuilt
TAR_XZ_ALPINE += ${BASE_TAR_PATH}-alpine-x86_64.tar.xz
TAR_XZ_ALPINE += ${BASE_TAR_PATH}-alpine-x86_64-pwsh.tar.xz
TAR_XZ_ALPINE += ${BASE_TAR_PATH}-alpine-arm.tar.xz
TAR_XZ_ALPINE += ${BASE_TAR_PATH}-alpine-arm64.tar.xz
TAR_XZ_ALPINE += ${BASE_TAR_PATH}-alpine-s390x.tar.xz
TAR_XZ_ALPINE += ${BASE_TAR_PATH}-alpine-ppc64le.tar.xz
TAR_XZ_ALPINE_313 += ${BASE_TAR_PATH}-alpine3.13-x86_64.tar.xz
TAR_XZ_ALPINE_313 += ${BASE_TAR_PATH}-alpine3.13-x86_64-pwsh.tar.xz
TAR_XZ_ALPINE_313 += ${BASE_TAR_PATH}-alpine3.13-arm.tar.xz
TAR_XZ_ALPINE_313 += ${BASE_TAR_PATH}-alpine3.13-arm64.tar.xz
TAR_XZ_ALPINE_313 += ${BASE_TAR_PATH}-alpine3.13-s390x.tar.xz
TAR_XZ_ALPINE_313 += ${BASE_TAR_PATH}-alpine3.13-ppc64le.tar.xz
TAR_XZ_ALPINE_314 += ${BASE_TAR_PATH}-alpine3.14-x86_64.tar.xz
TAR_XZ_ALPINE_314 += ${BASE_TAR_PATH}-alpine3.14-arm.tar.xz
TAR_XZ_ALPINE_314 += ${BASE_TAR_PATH}-alpine3.14-arm64.tar.xz
TAR_XZ_ALPINE_314 += ${BASE_TAR_PATH}-alpine3.14-s390x.tar.xz
TAR_XZ_ALPINE_314 += ${BASE_TAR_PATH}-alpine3.14-ppc64le.tar.xz
TAR_XZ_ALPINE_315 += ${BASE_TAR_PATH}-alpine3.15-x86_64.tar.xz
TAR_XZ_ALPINE_315 += ${BASE_TAR_PATH}-alpine3.15-arm.tar.xz
TAR_XZ_ALPINE_315 += ${BASE_TAR_PATH}-alpine3.15-arm64.tar.xz
TAR_XZ_ALPINE_315 += ${BASE_TAR_PATH}-alpine3.15-s390x.tar.xz
TAR_XZ_ALPINE_315 += ${BASE_TAR_PATH}-alpine3.15-ppc64le.tar.xz
TAR_XZ_ALPINE_LATEST += ${BASE_TAR_PATH}-alpine-latest-x86_64.tar.xz
TAR_XZ_ALPINE_LATEST += ${BASE_TAR_PATH}-alpine-latest-arm.tar.xz
TAR_XZ_ALPINE_LATEST += ${BASE_TAR_PATH}-alpine-latest-arm64.tar.xz
TAR_XZ_ALPINE_LATEST += ${BASE_TAR_PATH}-alpine-latest-s390x.tar.xz
TAR_XZ_ALPINE_LATEST += ${BASE_TAR_PATH}-alpine-latest-ppc64le.tar.xz
TAR_XZ_UBUNTU += ${BASE_TAR_PATH}-ubuntu-x86_64.tar.xz
TAR_XZ_UBUNTU += ${BASE_TAR_PATH}-ubuntu-x86_64-pwsh.tar.xz
TAR_XZ_UBUNTU += ${BASE_TAR_PATH}-ubuntu-arm.tar.xz
TAR_XZ_UBUNTU += ${BASE_TAR_PATH}-ubuntu-arm64.tar.xz
TAR_XZ_UBUNTU += ${BASE_TAR_PATH}-ubuntu-s390x.tar.xz
TAR_XZ_UBUNTU += ${BASE_TAR_PATH}-ubuntu-ppc64le.tar.xz
TAR_XZ_FIPS += ${BASE_TAR_PATH}-ubi-fips-x86_64.tar.xz
# Binaries that we support for the helper image. We are using the following
# pattern match:
# out/binaries/gitlab-runner-helper/gitlab-runner-helper.{{arch}}-{{os}}, these should
# match up with GO_ARCH_* variables names. Note that Linux is implied by
# default.
BASE_BINARY_PATH := out/binaries/gitlab-runner-helper/gitlab-runner-helper
BINARIES := ${BASE_BINARY_PATH}.x86_64-windows
BINARIES += ${BASE_BINARY_PATH}.x86_64
BINARIES += ${BASE_BINARY_PATH}.arm
BINARIES += ${BASE_BINARY_PATH}.arm64
BINARIES += ${BASE_BINARY_PATH}.s390x
BINARIES += ${BASE_BINARY_PATH}.ppc64le
# Define variables with the architecture for each matching binary. We are using
# the following pattern match GO_ARCH_{{arch}}-{{os}}, these should match up
# with BINARIES variables. The value of the variable is the dist name from `go tool dist list`
GO_ARCH_x86_64 = linux/amd64
GO_ARCH_arm = linux/arm
GO_ARCH_arm64 = linux/arm64
GO_ARCH_s390x = linux/s390x
GO_ARCH_ppc64le = linux/ppc64le
GO_ARCH_x86_64-windows = windows/amd64
GO_ARCH_NAME_amd64 = x86_64
# Go files that are used to create the helper binary.
HELPER_GO_FILES ?= $(shell find common network -name '*.go')
# Build the Runner Helper binaries for the host platform.
.PHONY: helper-bin-host
helper-bin-host: ${BASE_BINARY_PATH}.$(shell uname -m)
# Build the Runner Helper binaries for all supported platforms.
.PHONY: helper-bin
helper-bin: $(BINARIES)
# Make sure the fips target is first since it's less general
${BASE_BINARY_PATH}-fips: export GOOS ?= linux
${BASE_BINARY_PATH}-fips: export GOARCH ?= amd64
${BASE_BINARY_PATH}-fips: $(HELPER_GO_FILES)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build \
-tags boringcrypto \
-ldflags "$(GO_LDFLAGS)" \
-o="${BASE_BINARY_PATH}.$(GO_ARCH_NAME_$(GOARCH))-fips" \
$(PKG)/apps/gitlab-runner-helper
${BASE_BINARY_PATH}-fips-docker: export GOOS ?= linux
${BASE_BINARY_PATH}-fips-docker: export GOARCH ?= amd64
${BASE_BINARY_PATH}-fips-docker: export GO_VERSION ?= 1.17
${BASE_BINARY_PATH}-fips-docker: $(HELPER_GO_FILES)
# Building $(NAME)-helper in version $(VERSION) for FIPS $(GOOS) $(GOARCH)
@docker build -t gitlab-runner-helper-fips --build-arg GOOS="$(GOOS)" --build-arg GOARCH="$(GOARCH)" --build-arg GO_VERSION="$(GO_VERSION)" -f dockerfiles/fips/helper.fips.Dockerfile .
@docker rm -f gitlab-runner-helper-fips && docker create -it --name gitlab-runner-helper-fips gitlab-runner-helper-fips
@docker cp gitlab-runner-helper-fips:/gitlab-runner-helper-fips "${BASE_BINARY_PATH}.$(GO_ARCH_NAME_$(GOARCH))-fips"
@docker rm -f gitlab-runner-helper-fips
${BASE_BINARY_PATH}.%: $(HELPER_GO_FILES) $(GOX)
$(GOX) -osarch=$(GO_ARCH_$*) -ldflags "$(GO_LDFLAGS)" -output=$@ $(PKG)/apps/gitlab-runner-helper
# Build the Runner Helper tar files for host platform.
.PHONY: _helper-dockerarchive-host
_helper-dockerarchive-host: ${BASE_TAR_PATH}-$(IMAGE_TARGET_FLAVOUR)-$(shell uname -m)$(IMAGE_VARIANT_SUFFIX).tar.xz
@ # NOTE: The ENTRYPOINT metadata is not preserved on export, so we need to reapply this metadata on import.
@ # See https://gitlab.com/gitlab-org/gitlab-runner/-/merge_requests/2058#note_388341301
docker import ${BASE_TAR_PATH}-$(IMAGE_TARGET_FLAVOUR)-$(shell uname -m)$(IMAGE_VARIANT_SUFFIX).tar.xz \
--change "ENTRYPOINT [\"/usr/bin/dumb-init\", \"/entrypoint\"]" \
gitlab/gitlab-runner-helper:$(IMAGE_VARIANT_PREFIX)$(shell uname -m)-$(REVISION)$(IMAGE_VARIANT_SUFFIX)
.PHONY: helper-dockerarchive-host
helper-dockerarchive-host:
@$(MAKE) _helper-dockerarchive-host IMAGE_TARGET_FLAVOUR='alpine' IMAGE_VARIANT_PREFIX='' IMAGE_VARIANT_SUFFIX=''
@$(MAKE) _helper-dockerarchive-host IMAGE_TARGET_FLAVOUR='alpine' IMAGE_VARIANT_PREFIX='' IMAGE_VARIANT_SUFFIX='-pwsh'
@$(MAKE) _helper-dockerarchive-host IMAGE_TARGET_FLAVOUR='ubuntu' IMAGE_VARIANT_PREFIX='ubuntu-' IMAGE_VARIANT_SUFFIX=''
@$(MAKE) _helper-dockerarchive-host IMAGE_TARGET_FLAVOUR='ubuntu' IMAGE_VARIANT_PREFIX='ubuntu-' IMAGE_VARIANT_SUFFIX='-pwsh'
# Build the Runner Helper tar files for all supported platforms.
.PHONY: helper-dockerarchive
helper-dockerarchive: helper-dockerarchive-alpine helper-dockerarchive-alpine3.13 helper-dockerarchive-alpine3.14 helper-dockerarchive-alpine3.15 helper-dockerarchive-alpine-latest helper-dockerarchive-ubuntu
.PHONY: helper-dockerarchive-alpine
helper-dockerarchive-alpine: $(TAR_XZ_ALPINE)
.PHONY: helper-dockerarchive-alpine3.13
helper-dockerarchive-alpine3.13: $(TAR_XZ_ALPINE_313)
.PHONY: helper-dockerarchive-alpine3.14
helper-dockerarchive-alpine3.14: $(TAR_XZ_ALPINE_314)
.PHONY: helper-dockerarchive-alpine3.15
helper-dockerarchive-alpine3.15: $(TAR_XZ_ALPINE_315)
.PHONY: helper-dockerarchive-alpine-latest
helper-dockerarchive-alpine-latest: $(TAR_XZ_ALPINE_LATEST)
.PHONY: helper-dockerarchive-ubuntu
helper-dockerarchive-ubuntu: $(TAR_XZ_UBUNTU)
.PHONY: helper-dockerarchive-ubi-fips
helper-dockerarchive-ubi-fips: $(TAR_XZ_FIPS)
${BASE_TAR_PATH}-ubi-fips-%.tar.xz: ${BASE_TAR_PATH}-ubi-fips-%.tar
xz $(TAR_XZ_ARGS) $<
${BASE_TAR_PATH}-%-pwsh.tar.xz: ${BASE_TAR_PATH}-%-pwsh.tar
xz $(TAR_XZ_ARGS) $<
${BASE_TAR_PATH}-%.tar.xz: ${BASE_TAR_PATH}-%.tar
xz $(TAR_XZ_ARGS) $<
${BASE_TAR_PATH}-ubi-fips-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= 8.6-754
${BASE_TAR_PATH}-ubi-fips-%.tar: export TARGET_DOCKERFILE ?= Dockerfile.fips
${BASE_TAR_PATH}-ubi-fips-%.tar: export HELPER_BINARY_POSTFIX ?= -fips
${BASE_TAR_PATH}-ubi-fips-%.tar:
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker redhat/ubi8 $* $@
# See https://github.com/PowerShell/powershell/releases for values of PWSH_VERSION/PWSH_IMAGE_DATE
${BASE_TAR_PATH}-alpine-%-pwsh.tar: export IMAGE_SHELL := pwsh
${BASE_TAR_PATH}-alpine-%-pwsh.tar: export PWSH_VERSION ?= 7.1.1
${BASE_TAR_PATH}-alpine-%-pwsh.tar: export PWSH_IMAGE_DATE ?= 20210114
${BASE_TAR_PATH}-alpine-%-pwsh.tar: export PWSH_TARGET_FLAVOR_IMAGE_VERSION ?= 3.12
${BASE_TAR_PATH}-alpine-%-pwsh.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-alpine3.13-%-pwsh.tar: export IMAGE_SHELL := pwsh
${BASE_TAR_PATH}-alpine3.13-%-pwsh.tar: export PWSH_VERSION ?= 7.1.4
${BASE_TAR_PATH}-alpine3.13-%-pwsh.tar: export PWSH_IMAGE_DATE ?= 20210927
${BASE_TAR_PATH}-alpine3.13-%-pwsh.tar: export PWSH_TARGET_FLAVOR_IMAGE_VERSION ?= 3.13
${BASE_TAR_PATH}-alpine3.13-%-pwsh.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-ubuntu-%-pwsh.tar: export IMAGE_SHELL := pwsh
${BASE_TAR_PATH}-ubuntu-%-pwsh.tar: export PWSH_VERSION ?= 7.1.1
${BASE_TAR_PATH}-ubuntu-%-pwsh.tar: export PWSH_IMAGE_DATE ?= 20210114
${BASE_TAR_PATH}-ubuntu-%-pwsh.tar: export PWSH_TARGET_FLAVOR_IMAGE_VERSION ?= 20.04
${BASE_TAR_PATH}-ubuntu-%-pwsh.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker ubuntu $* $@
${BASE_TAR_PATH}-alpine-latest-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= latest
${BASE_TAR_PATH}-alpine-latest-%.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-alpine-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= 3.12.12
${BASE_TAR_PATH}-alpine-%.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-alpine3.13-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= 3.13.10
${BASE_TAR_PATH}-alpine3.13-%.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-alpine3.14-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= 3.14.6
${BASE_TAR_PATH}-alpine3.14-%.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-alpine3.15-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= 3.15.4
${BASE_TAR_PATH}-alpine3.15-%.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker alpine $* $@
${BASE_TAR_PATH}-ubuntu-%.tar: export TARGET_FLAVOR_IMAGE_VERSION ?= 20.04
${BASE_TAR_PATH}-ubuntu-%.tar: ${BASE_BINARY_PATH}.%
@mkdir -p $$(dirname $@_)
@./ci/build_helper_docker ubuntu $* $@