forked from harvester/harvester
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
264 lines (193 loc) · 9.51 KB
/
Copy pathDockerfile
File metadata and controls
264 lines (193 loc) · 9.51 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
FROM golang:1.26-bookworm AS builder
ARG CONTAINER_WORKDIR=/go/src/github.com/harvester/harvester
ARG MK_HOST_ARCH
ENV ARCH=$MK_HOST_ARCH
ENV GOTOOLCHAIN=auto
ARG HELM_VERSION=v3.20.0
ARG HELM_SHA256_Linux_amd64=dbb4c8fc8e19d159d1a63dda8db655f9ffa4aac1b9a6b188b34a40957119b286
ARG HELM_SHA256_Linux_arm64=bfb14953295d5324d47ab55f3dfba6da28d46c848978c8fbf412d4271bdc29f1
ARG KIND_VERSION=v0.31.0
ARG KIND_SHA256_Linux_amd64=eb244cbafcc157dff60cf68693c14c9a75c4e6e6fedaf9cd71c58117cb93e3fa
ARG KIND_SHA256_Linux_arm64=8e1014e87c34901cc422a1445866835d1e666f2a61301c27e722bdeab5a1f7e4
ARG CODECOV_VERSION=v0.8.0
ARG CODECOV_SHA256_Linux=b37359013b48fbc3b0790d59fc474a52a260fb96e28e1b2c2ae001dc9b9cc996
SHELL ["/bin/bash", "-c"]
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
xz-utils \
unzip \
zstd \
squashfs-tools \
xorriso \
jq \
mtools \
dosfstools \
patch \
&& rm -rf /var/lib/apt/lists/*
# install yq
RUN GO111MODULE=on go install github.com/mikefarah/yq/v4@v4.27.5
# set up helm
ENV HELM_VERSION=${HELM_VERSION}
ENV HELM_TARBALL=helm-${HELM_VERSION}-linux-${ARCH}.tar.gz
ENV HELM_URL=https://get.helm.sh/${HELM_TARBALL}
RUN mkdir /usr/tmp && \
curl -sSLO --output-dir /usr/tmp ${HELM_URL} && \
HELM_SHA256=HELM_SHA256_Linux_${ARCH} && \
echo "${!HELM_SHA256} /usr/tmp/${HELM_TARBALL}" | sha256sum -c - && \
tar xvzf /usr/tmp/${HELM_TARBALL} --strip-components=1 -C /usr/tmp/ && \
mv /usr/tmp/helm /usr/bin/helm
# -- for make rules
## install docker client
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
curl \
gnupg \
rsync \
&& rm -rf /var/lib/apt/lists/*; \
\
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - >/dev/null; \
echo "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/debian buster stable" > /etc/apt/sources.list.d/docker.list; \
\
apt-get update -qq && apt-get install -y --no-install-recommends \
docker-ce=5:20.10.* \
&& rm -rf /var/lib/apt/lists/*
## install golangci
COPY --from=golangci/golangci-lint:v2.12.2-alpine@sha256:91b27804074a0bacea298707f016911e60cf0cdbc6c7bf5ccacb5f0606d18d60 /usr/bin/golangci-lint /usr/local/bin/golangci-lint
## install controller-gen
RUN GO111MODULE=on go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.17.1
## install ginkgo
RUN GO111MODULE=on go install github.com/onsi/ginkgo/v2/ginkgo@v2.29.0
# install openapi-gen
RUN GO111MODULE=on go install k8s.io/code-generator/cmd/openapi-gen@v0.29.13
# install kind
RUN curl -Lo /usr/bin/kind https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-${ARCH} && \
KIND_SHA256="KIND_SHA256_Linux_${ARCH}" && \
echo "${!KIND_SHA256} /usr/bin/kind" | sha256sum -c - && \
chmod +x /usr/bin/kind
# install codecov
RUN curl -Lo /usr/bin/codecov https://uploader.codecov.io/${CODECOV_VERSION}/linux/codecov && \
echo "${CODECOV_SHA256_Linux} /usr/bin/codecov" | sha256sum -c - && \
chmod +x /usr/bin/codecov
ENV HOME=/go/src/github.com/harvester/harvester
# ---- base ----
FROM builder AS base
WORKDIR /go/src/github.com/harvester/harvester
# to exclude some files, add them in .dockerignore
COPY . .
# ---- build ----
FROM base AS build
ARG MK_REPO_ID
RUN --mount=type=cache,target=/go/pkg/mod,id=harvester-go-mod-${MK_REPO_ID} \
--mount=type=cache,target=/go/src/github.com/harvester/harvester/.cache/go-build,id=harvester-go-build-${MK_REPO_ID} \
./scripts/build
FROM scratch AS build-output
COPY --from=build /go/src/github.com/harvester/harvester/bin/ /bin/
# ---- prepare-addons ----
FROM builder AS prepare-addons
ARG ADDONS_BRANCH=main
# re-pull when remote sha changed
ARG REMOTE_SHA=unknown
RUN mkdir -p /dist/prepare-addon
# clone addons repo
RUN git clone --branch ${ADDONS_BRANCH} --single-branch --depth 1 \
https://github.com/harvester/addons.git /dist/prepare-addons/addons && \
rm -rf /dist/prepare-addons/addons/.git
# generate addon manifests
RUN mkdir -p /dist/prepare-addons/addons-manifests && \
cd /dist/prepare-addons/addons && \
go run . -generateAddons -path /dist/prepare-addons/addons-manifests
# genereate addon templates (for rancherd)
RUN mkdir -p /dist/prepare-addons/addons-templates && \
cd /dist/prepare-addons/addons && \
go run . -generateTemplates -path /dist/prepare-addons/addons-templates
# ---- validate ----
FROM base AS validate
ARG MK_REPO_ID
RUN --mount=type=cache,target=/go/pkg/mod,id=harvester-go-mod-${MK_REPO_ID} \
--mount=type=cache,target=/go/src/github.com/harvester/harvester/.cache/go-build,id=harvester-go-build-${MK_REPO_ID} \
./scripts/validate
# ---- validate-ci ----
FROM base AS validate-ci
ARG MK_REPO_ID
# Init a new git repo for copied files inside the container, the test script checks if files are
# modified after running go generate
RUN git config --global user.email "ci@example.com" && \
git config --global user.name "ci" && \
git init 2>/dev/null && git add . && git commit -q -m "commit for validate-ci"
RUN --mount=type=cache,target=/go/pkg/mod,id=harvester-go-mod-${MK_REPO_ID} \
--mount=type=cache,target=/go/src/github.com/harvester/harvester/.cache/go-build,id=harvester-go-build-${MK_REPO_ID} \
./scripts/validate-ci
# ---- test ----
FROM base AS test
ARG MK_REPO_ID
COPY --from=prepare-addons /dist/prepare-addons/addons-templates/rancherd-22-addons.yaml \
/go/src/github.com/harvester/harvester/pkg/installer/config/templates/rancherd-22-addons.yaml
RUN --mount=type=cache,target=/go/pkg/mod,id=harvester-go-mod-${MK_REPO_ID} \
--mount=type=cache,target=/go/src/github.com/harvester/harvester/.cache/go-build,id=harvester-go-build-${MK_REPO_ID} \
--mount=type=secret,id=codecov_token_${MK_REPO_ID} \
CODECOV_TOKEN=$(cat /run/secrets/codecov_token_${MK_REPO_ID} 2>/dev/null || true) \
./scripts/test
# ---- test-integration ----
FROM base AS test-integration
# ---- generate-manifest ----
FROM base AS generate-manifest
RUN ./scripts/generate-manifest
FROM scratch AS generate-manifest-output
COPY --from=generate-manifest /go/src/github.com/harvester/harvester/deploy/charts/harvester-crd/templates/ /templates/
# ---- generate-openapi ----
FROM base AS generate-openapi
ARG MK_REPO_ID
RUN git config --global user.email "ci@example.com" && \
git config --global user.name "ci" && \
git init 2>/dev/null && git add . && git commit -q -m "commit for validate-ci"
RUN --mount=type=cache,target=/go/pkg/mod,id=harvester-go-mod-${MK_REPO_ID} \
--mount=type=cache,target=/go/src/github.com/harvester/harvester/.cache/go-build,id=harvester-go-build-${MK_REPO_ID} \
./scripts/generate-openapi
FROM scratch AS generate-openapi-output
COPY --from=generate-openapi /go/src/github.com/harvester/harvester/api/openapi-spec/swagger.json /api/openapi-spec/swagger.json
COPY --from=generate-openapi /go/src/github.com/harvester/harvester/scripts/known-api-rule-violations.txt /scripts/known-api-rule-violations.txt
# ---- build-installer ----
FROM base AS build-installer
ARG MK_REPO_ID
COPY --from=prepare-addons /dist/prepare-addons/addons/ /go/src/github.com/harvester/addons/
RUN --mount=type=cache,target=/go/pkg/mod,id=harvester-go-mod-${MK_REPO_ID} \
--mount=type=cache,target=/go/src/github.com/harvester/harvester/.cache/go-build,id=harvester-go-build-${MK_REPO_ID} \
./scripts/build-installer
FROM scratch AS build-installer-output
COPY --from=build-installer /go/src/github.com/harvester/harvester/bin/harvester-installer /bin/
# ---- bundle-builder ----
FROM builder AS bundle-builder
WORKDIR /go/src/github.com/harvester/harvester
COPY scripts/images/*.yaml scripts/images/
COPY scripts/lib/ scripts/lib/
# ---- prepare-addons-charts ----
FROM bundle-builder AS prepare-addons-charts
COPY --from=prepare-addons /dist/prepare-addons/addons/ /go/src/github.com/harvester/addons/
COPY --from=prepare-addons /dist/prepare-addons/addons-templates/ /go/src/github.com/harvester/addons-templates/
COPY scripts/prepare-addons-charts scripts/prepare-addons-charts
RUN bash scripts/prepare-addons-charts
# ---- prepare-harvester-charts ----
FROM bundle-builder AS prepare-harvester-charts
COPY deploy/ deploy/
COPY scripts/prepare-harvester-charts scripts/prepare-harvester-charts
COPY scripts/patch-harvester scripts/patch-harvester
COPY scripts/version scripts/.version_env scripts/
RUN bash scripts/prepare-harvester-charts
# ---- check-images ----
FROM bundle-builder AS check-images
COPY scripts/check-images scripts/check-images
COPY scripts/version-rancher scripts/version-rancher
COPY scripts/images/rancher-images.txt scripts/images/rancherd-bootstrap-images.txt scripts/images/
RUN bash scripts/check-images
# ---- build-iso ----
FROM builder AS build-iso
WORKDIR /go/src/github.com/harvester/harvester
COPY --from=build-installer /go/src/github.com/harvester/harvester/bin/harvester-installer package/harvester-os/files/usr/bin/
COPY --from=prepare-addons /dist/prepare-addons/addons/ /go/src/github.com/harvester/addons/
COPY --from=prepare-harvester-charts /go/src/github.com/harvester/harvester/deploy/charts/ /go/src/github.com/harvester/harvester/deploy/charts/
COPY --from=prepare-harvester-charts /dist/chart-tarballs/* /go/src/github.com/harvester/harvester/package/harvester-repo/charts/
COPY --from=prepare-addons-charts /dist/charts/*.tgz /go/src/github.com/harvester/harvester/package/harvester-repo/charts/
COPY scripts/ scripts/
COPY package/upgrade-matrix.yaml package/upgrade-matrix.yaml
COPY package/harvester-os/ package/harvester-os/
COPY package/harvester-repo/ package/harvester-repo/