-
Notifications
You must be signed in to change notification settings - Fork 97
/
Earthfile
245 lines (213 loc) · 7.65 KB
/
Earthfile
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
VERSION 0.6
FROM alpine
ARG FLAVOR=opensuse
ARG IMAGE=quay.io/c3os/c3os:${FLAVOR}-latest
ARG LUET_VERSION=0.32.4
ARG REPOSITORIES_FILE=repositories.yaml
IF [ "$FLAVOR" = "fedora" ] || [ "$FLAVOR" = "tumbleweed" ] || [ "$FLAVOR" = "ubuntu" ]
ARG REPOSITORIES_FILE=repositories.yaml.${FLAVOR}
END
ARG COSIGN_SKIP=".*quay.io/c3os/.*"
# TODO: This should match for each flavor
ARG COSIGN_REPOSITORY=raccos/releases-teal
ARG COSIGN_EXPERIMENTAL=0
ARG CGO_ENABLED=0
ARG ELEMENTAL_IMAGE=quay.io/costoolkit/elemental:v0.0.15-8a78e6b
go-deps:
FROM golang
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
RUN apt-get update && apt-get install -y upx
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
BUILD_GOLANG:
COMMAND
WORKDIR /build
COPY . ./
ARG CGO_ENABLED
ARG BIN
ARG SRC
ENV CGO_ENABLED=${CGO_ENABLED}
RUN go build -ldflags "-s -w" -o ${BIN} ./cmd/${SRC} && upx ${BIN}
SAVE ARTIFACT ${BIN} ${BIN} AS LOCAL build/${BIN}
build-c3os-cli:
FROM +go-deps
DO +BUILD_GOLANG --BIN=c3os --SRC=cli --CGO_ENABLED=$CGO_ENABLED
build-c3os-agent:
FROM +go-deps
DO +BUILD_GOLANG --BIN=c3os-agent --SRC=agent --CGO_ENABLED=$CGO_ENABLED
build-c3os-agent-provider:
FROM +go-deps
DO +BUILD_GOLANG --BIN=agent-provider-c3os --SRC=provider --CGO_ENABLED=$CGO_ENABLED
build:
BUILD +build-c3os-cli
BUILD +build-c3os-agent
BUILD +build-c3os-agent-provider
luet:
FROM quay.io/luet/base:$LUET_VERSION
SAVE ARTIFACT /usr/bin/luet /luet
framework:
ARG COSIGN_SKIP
ARG REPOSITORIES_FILE
ARG COSIGN_EXPERIMENTAL
ARG COSIGN_REPOSITORY
FROM alpine
COPY +luet/luet /usr/bin/luet
# cosign keyless verify
ENV COSIGN_EXPERIMENTAL=${COSIGN_EXPERIMENTAL}
# Repo containing signatures
ENV COSIGN_REPOSITORY=${COSIGN_REPOSITORY}
# Skip this repo artifacts verify as they are not signed
ENV COSIGN_SKIP=${COSIGN_SKIP}
# Copy the luet config file pointing to the upgrade repository
COPY repositories/$REPOSITORIES_FILE /etc/luet/luet.yaml
ENV USER=root
IF [ "$FLAVOR" = "alpine" ] || [ "$FLAVOR" = "fedora" ] || [ "$FLAVOR" = "ubuntu" ] || [ "$FLAVOR" = "alpine-arm-rpi" ]
RUN /usr/bin/luet install -y --system-target /framework \
meta/cos-verify \
meta/cos-core \
cloud-config/recovery \
cloud-config/live \
cloud-config/network \
cloud-config/boot-assessment \
cloud-config/rootfs \
utils/edgevpn \
utils/k9s \
system-openrc/cos-setup \
utils/nerdctl \
system/kernel \
system/dracut-initrd
ELSE
RUN /usr/bin/luet install -y --system-target /framework \
meta/cos-verify \
meta/cos-core \
utils/edgevpn \
cloud-config/recovery \
cloud-config/live \
cloud-config/boot-assessment \
cloud-config/network \
cloud-config/rootfs \
systemd-service/edgevpn \
utils/k9s \
container/kubectl \
utils/nerdctl
END
COPY overlay/files /framework
SAVE ARTIFACT /framework/ framework
docker:
# Source the flavor-provided docker file
FROM DOCKERFILE -f images/Dockerfile.$FLAVOR .
ARG K3S_VERSION
ARG C3OS_VERSION
ARG OS_VERSION=${K3S_VERSION}+k3s1-c3OS${C3OS_VERSION}
ARG OS_ID=c3os
ARG FLAVOR
ARG OS_NAME=${OS_ID}-${FLAVOR}
ARG OS_REPO=quay.io/c3os/c3os
ARG OS_LABEL=${FLAVOR}-latest
ENV OS_LABEL=$OS_LABEL
ENV OS_NAME=$OS_NAME
ENV OS_ID=$OS_ID
ENV OS_VERSION=$OS_VERSION
ENV OS_REPO=$OS_REPO
# Includes overlay/files
COPY +framework/framework /
# Copy flavor-specific overlay files
IF [ "$FLAVOR" = "alpine" ]
COPY overlay/files-alpine/ /
ELSE IF [ "$FLAVOR" = "alpine-arm-rpi" ]
COPY overlay/files-alpine/ /
COPY overlay/files-opensuse-arm-rpi/ /
ELSE IF [ "$FLAVOR" = "opensuse-arm-rpi" ]
COPY overlay/files-opensuse-arm-rpi/ /
END
# Copy c3os binaries
COPY +build-c3os-cli/c3os /usr/bin/c3os
COPY +build-c3os-agent/c3os-agent /usr/bin/c3os-agent
COPY +build-c3os-agent-provider/agent-provider-c3os /usr/bin/agent-provider-c3os
# update OS-release file
RUN envsubst >/etc/os-release </usr/lib/os-release.tmpl && \
rm /usr/lib/os-release.tmpl
# Regenerate initrd if necessary
IF [ "$FLAVOR" = "opensuse" ] || [ "$FLAVOR" = "opensuse-arm-rpi" ] || [ "$FLAVOR" = "tumbleweed-arm-rpi" ]
RUN mkinitrd
ELSE IF [ "$FLAVOR" = "ubuntu" ]
RUN kernel=$(ls /boot/vmlinuz-* | head -n1) && \
ln -sf "${kernel#/boot/}" /boot/vmlinuz
RUN kernel=$(ls /lib/modules | head -n1) && \
dracut -f "/boot/initrd-${kernel}" "${kernel}" && \
ln -sf "initrd-${kernel}" /boot/initrd
RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}"
END
# If it's an ARM flavor, we want a symlink here
IF [ "$FLAVOR" = "alpine-arm-rpi" ] || [ "$FLAVOR" = "opensuse-arm-rpi" ] || [ "$FLAVOR" = "tumbleweed-arm-rpi" ]
RUN ln -sf Image /boot/vmlinuz
END
SAVE IMAGE $IMAGE
docker-rootfs:
FROM +docker
SAVE ARTIFACT /. rootfs
elemental:
ARG ELEMENTAL_IMAGE
FROM ${ELEMENTAL_IMAGE}
SAVE ARTIFACT /usr/bin/elemental elemental
iso:
ARG ELEMENTAL_IMAGE
ARG ISO_NAME=${OS_ID}
ARG IMG=docker:$IMAGE
ARG overlay=overlay/files-iso
ARG TOOLKIT_REPOSITORY=quay.io/costoolkit/releases-teal
FROM $ELEMENTAL_IMAGE
RUN zypper in -y jq docker
WORKDIR /build
COPY . ./
WITH DOCKER --allow-privileged --load $IMAGE=(+docker)
RUN elemental --repo $TOOLKIT_REPOSITORY --name $ISO_NAME --debug build-iso --date=false --local --overlay-iso /build/${overlay} $IMAGE --output /build/
END
# See: https://github.com/rancher/elemental-cli/issues/228
RUN sha256sum $ISO_NAME.iso > $ISO_NAME.iso.sha256
SAVE ARTIFACT /build/$ISO_NAME.iso c3os.iso AS LOCAL build/$ISO_NAME.iso
SAVE ARTIFACT /build/$ISO_NAME.iso.sha256 c3os.iso.sha256 AS LOCAL build/$ISO_NAME.iso.sha256
netboot:
FROM opensuse/leap
ARG ISO_NAME=${OS_ID}
WORKDIR /build
COPY +iso/c3os.iso c3os.iso
COPY . .
RUN zypper in -y cdrtools
RUN /build/scripts/netboot.sh c3os.iso $ISO_NAME
SAVE ARTIFACT /build/$ISO_NAME.squashfs squashfs AS LOCAL build/$ISO_NAME.squashfs
SAVE ARTIFACT /build/$ISO_NAME-kernel kernel AS LOCAL build/$ISO_NAME-kernel
SAVE ARTIFACT /build/$ISO_NAME-initrd initrd AS LOCAL build/$ISO_NAME-initrd
SAVE ARTIFACT /build/$ISO_NAME.ipxe ipxe AS LOCAL build/$ISO_NAME.ipxe
arm-image:
ARG ELEMENTAL_IMAGE
FROM $ELEMENTAL_IMAGE
ARG MODEL=rpi64
ARG IMAGE_NAME=${FLAVOR}.img
RUN zypper in -y jq docker git curl gptfdisk kpartx
#COPY +luet/luet /usr/bin/luet
WORKDIR /build
RUN git clone https://github.com/rancher/elemental-toolkit && mkdir elemental-toolkit/build
RUN curl https://luet.io/install.sh | sh
ENV STATE_SIZE="6200"
ENV RECOVERY_SIZE="4200"
ENV SIZE="15200"
ENV DEFAULT_ACTIVE_SIZE="2000"
COPY --platform=linux/arm64 +docker-rootfs/rootfs /build/image
# With docker is required for loop devices
WITH DOCKER --allow-privileged
RUN cd elemental-toolkit && \
./images/arm-img-builder.sh --model $MODEL --directory "/build/image" build/$IMAGE_NAME && mv build ../
END
RUN xz -v /build/build/$IMAGE_NAME
SAVE ARTIFACT /build/build/$IMAGE_NAME.xz img AS LOCAL build/$IMAGE_NAME
SAVE ARTIFACT /build/build/$IMAGE_NAME.sha256 img AS LOCAL build/$IMAGE_NAME.sha256
all:
BUILD +docker
BUILD +iso
BUILD +netboot
all-arm:
BUILD --platform=linux/arm64 +docker
BUILD +arm-image