-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathDockerfile
More file actions
128 lines (106 loc) · 3.91 KB
/
Copy pathDockerfile
File metadata and controls
128 lines (106 loc) · 3.91 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
# syntax=docker/dockerfile:1.23
# check=error=true
ARG TEST_BASE_TYPE=alpine
ARG TEST_BASE_IMAGE=${TEST_BASE_TYPE}
ARG TEST_WITH_DARWIN=false
ARG BATS_VERSION=v1.13.0
# build prepares the sources
FROM --platform=$BUILDPLATFORM alpine AS build
COPY xx-* /out/
RUN ln -s xx-cc /out/xx-clang && \
ln -s xx-cc /out/xx-clang++ && \
ln -s xx-cc /out/xx-c++ && \
ln -s xx-apt /out/xx-apt-get
# xx builds the xx image
FROM scratch AS xx
COPY --from=build /out/ /usr/bin/
FROM scratch AS bats-src
ARG BATS_VERSION
ADD "https://github.com/bats-core/bats-core.git#$BATS_VERSION" .
FROM --platform=$BUILDPLATFORM tonistiigi/bats-assert AS bats-assert
FROM ${TEST_BASE_IMAGE} AS test-base-alpine
RUN --mount=type=cache,target=/pkg-cache \
ln -s /pkg-cache /etc/apk/cache && \
apk add bash vim
WORKDIR /work
FROM ${TEST_BASE_IMAGE} AS test-base-debian
RUN --mount=type=cache,target=/pkg-cache \
rm -rf /var/cache/apt/archives && \
ln -s /pkg-cache /var/cache/apt/archives && \
rm /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "1";' > /etc/apt/apt.conf.d/keep-downloads && \
apt update && apt install --no-install-recommends -y bash vim
WORKDIR /work
FROM ${TEST_BASE_IMAGE} AS test-base-rhel
RUN <<EOT
set -ex
. /etc/os-release
if [[ "$ID" = "centos" ]] && [[ "$VERSION_ID" = "7" ]]; then
# CentOS 7 is EOL since June 30, 2024, use vault.centos.org
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
fi
if ! yum install -y epel-release; then
case "$ID" in
fedora) ;;
rocky)
dnf install -y epel-release
;;
*)
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-${VERSION:0:1}.noarch.rpm
yum update -y
;;
esac
fi
if command -v dnf >/dev/null 2>/dev/null; then
dnf install -y bash vim
else
yum install -y bash vim
fi
EOT
WORKDIR /work
FROM test-base-${TEST_BASE_TYPE} AS test-base
ADD --chmod=755 https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.4.0/src/semver /usr/bin/semver
COPY --from=bats-src / /opt/bats
RUN /opt/bats/install.sh /usr && bats --version
COPY --from=bats-assert . .
COPY --from=xx / /
FROM test-base AS test-base-fixtures
COPY fixtures fixtures
FROM test-base AS test-info
ARG TEST_BASE_TYPE
COPY test-info-common.bats test-info-${TEST_BASE_TYPE}.bats ./
RUN ./test-info-common.bats && ./test-info-${TEST_BASE_TYPE}.bats
FROM test-base AS test-windres
COPY test-windres.bats test_helper.bash ./
RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-windres.bats
FROM test-base AS test-apt
COPY test-apt.bats test_helper.bash ./
RUN --mount=type=cache,target=/pkg-cache,sharing=locked [ ! -f /etc/debian_version ] || ./test-apt.bats
FROM test-base AS test-apk
COPY test-apk.bats .
RUN --mount=type=cache,target=/pkg-cache,sharing=locked [ ! -f /etc/alpine-release ] || ./test-apk.bats
FROM test-base AS test-verify
COPY test-verify.bats .
RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-verify.bats
FROM test-base-fixtures AS test-clang
COPY test-clang.bats test_helper.bash ./
RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-clang.bats
FROM test-base-fixtures AS test-go
COPY test-go.bats test_helper.bash ./
RUN --mount=type=cache,target=/pkg-cache,sharing=locked --mount=type=cache,target=/root/.cache ./test-go.bats
FROM test-base-fixtures AS test-cargo
COPY test-cargo.bats test_helper.bash ./
RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-cargo.bats
# these targets can be overwritten with build contexts
FROM scratch AS sdk-extras
FROM scratch AS ld64
# dev can be used for debugging during development
FROM test-base AS dev
COPY --link --from=sdk-extras / /
COPY --link --from=ld64 / /usr/bin/
COPY --link --from=xx / /
COPY fixtures fixtures
COPY *.bats test_helper.bash ./
# default is alias to build xx image
FROM xx AS default