forked from tinkerbell/actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
49 lines (43 loc) · 1.82 KB
/
Dockerfile
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
# syntax=docker/dockerfile:experimental
# Build mkfs as an static
FROM gcc:10.2.0 as mke2fs
RUN wget https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.45.6/e2fsprogs-1.45.6.tar.gz; tar -xvzf ./e2fsprogs-1.45.6.tar.gz
WORKDIR /e2fsprogs-1.45.6/
RUN ./configure --enable-static=yes CFLAGS='-g -O2 -static'
RUN make
RUN make -C misc mke2fs.static
# build swap as static
FROM gcc:10.2.0 as swap
RUN git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
WORKDIR /util-linux/
RUN apt-get update; apt-get install -y gettext bison autopoint
RUN ./autogen.sh; ./configure LDFLAGS="-static"
RUN make LDFLAGS="-all-static" swapon
RUN make LDFLAGS="-all-static" mkswap
# Build rootio
FROM golang:1.15-alpine as rootio
RUN apk add --no-cache git ca-certificates gcc linux-headers musl-dev
COPY . /go/src/github.com/thebsdbox/rootio/
WORKDIR /go/src/github.com/thebsdbox/rootio
ENV GO111MODULE=on
RUN --mount=type=cache,sharing=locked,id=gomod,target=/go/pkg/mod/cache \
--mount=type=cache,sharing=locked,id=goroot,target=/root/.cache/go-build \
CGO_ENABLED=1 GOOS=linux go build -a -ldflags "-linkmode external -extldflags '-static' -s -w" -o rootio
# build fattools as static
FROM gcc:10.2.0 as fattools
RUN git clone https://github.com/dosfstools/dosfstools
WORKDIR /dosfstools/
RUN ./autogen.sh; ./configure
RUN make LDFLAGS="--static"
# build lvm2 as static
FROM alpine as lvm
RUN apk update && apk add lvm2-static=2.03.21-r3
# Build final image
FROM scratch
COPY --from=mke2fs /e2fsprogs-1.45.6/misc/mke2fs.static /sbin/mke2fs
COPY --from=swap util-linux/swapon /sbin/swapon
COPY --from=swap util-linux/mkswap /sbin/mkswap
COPY --from=fattools dosfstools/src/mkfs.fat /sbin/mkfs.fat
COPY --from=lvm /usr/sbin/lvm.static /sbin/lvm
COPY --from=rootio /go/src/github.com/thebsdbox/rootio/rootio .
ENTRYPOINT ["/rootio"]