2019-07-23 17:17:16 +03:00
# syntax = docker/dockerfile-upstream:master-experimental
2019-07-06 06:20:24 +00:00
2019-07-13 00:24:51 +00:00
ARG TOOLS
FROM $TOOLS AS tools
ENV PATH /toolchain/bin
RUN [ "/toolchain/bin/mkdir" , "/bin" , "/tmp" ]
RUN [ "/toolchain/bin/ln" , "-svf" , "/toolchain/bin/bash" , "/bin/sh" ]
RUN [ "/toolchain/bin/ln" , "-svf" , "/toolchain/etc/ssl" , "/etc/ssl" ]
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /toolchain/bin v1.16.0
# The build target creates a container that will be used to build Talos source
# code.
FROM scratch AS build
COPY --from= tools / /
SHELL [ "/toolchain/bin/bash" , "-c" ]
ENV PATH /toolchain/bin:/toolchain/go/bin
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org
ENV CGO_ENABLED 0
WORKDIR /src
2018-12-19 22:22:05 -08:00
2019-07-13 00:24:51 +00:00
# The generate target generates code from protobuf service definitions.
2019-01-18 06:26:12 -08:00
2019-07-13 00:24:51 +00:00
FROM build AS generate-build
2018-12-19 22:22:05 -08:00
WORKDIR /osd
COPY ./internal/app/osd/proto ./proto
2019-07-13 00:24:51 +00:00
RUN protoc -I./proto --go_out= plugins = grpc:proto proto/api.proto
2018-12-19 22:22:05 -08:00
WORKDIR /trustd
COPY ./internal/app/trustd/proto ./proto
2019-07-13 00:24:51 +00:00
RUN protoc -I./proto --go_out= plugins = grpc:proto proto/api.proto
2019-07-16 15:09:35 +00:00
WORKDIR /machined
COPY ./internal/app/machined/proto ./proto
2019-07-13 00:24:51 +00:00
RUN protoc -I./proto --go_out= plugins = grpc:proto proto/api.proto
2019-07-21 18:27:15 +00:00
2019-07-13 00:24:51 +00:00
FROM scratch AS generate
COPY --from= generate-build /osd/proto/api.pb.go /internal/app/osd/proto/
COPY --from= generate-build /trustd/proto/api.pb.go /internal/app/trustd/proto/
2019-07-16 15:09:35 +00:00
COPY --from= generate-build /machined/proto/api.pb.go /internal/app/machined/proto/
2019-03-28 02:33:03 +03:00
2019-07-13 00:24:51 +00:00
# The base target provides a container that can be used to build all Talos
# assets.
2019-01-18 06:26:12 -08:00
2019-07-13 00:24:51 +00:00
FROM build AS base
2019-01-19 01:58:26 -08:00
COPY ./go.mod ./
COPY ./go.sum ./
2018-12-19 22:22:05 -08:00
RUN go mod download
RUN go mod verify
2019-04-11 02:50:56 +03:00
COPY ./cmd ./cmd
COPY ./pkg ./pkg
COPY ./internal ./internal
2019-07-13 00:24:51 +00:00
COPY --from= generate /internal/app ./internal/app
2019-04-17 23:25:22 +03:00
RUN go list -mod= readonly all >/dev/null
2019-06-22 07:18:08 +03:00
RUN ! go mod tidy -v 2>& 1 | grep .
2018-12-19 22:22:05 -08:00
2019-07-13 00:24:51 +00:00
# The init target builds the init binary.
FROM base AS init-build
ARG SHA
ARG TAG
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
WORKDIR /src/internal/app/init
RUN go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Talos -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /init
RUN chmod +x /init
2019-07-21 18:27:15 +00:00
2019-07-13 00:24:51 +00:00
FROM scratch AS init
COPY --from= init-build /init /init
2019-07-16 15:09:35 +00:00
# The machined target builds the machined image.
FROM base AS machined-build
ARG SHA
ARG TAG
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
WORKDIR /src/internal/app/machined
2019-07-21 18:27:15 +00:00
RUN --mount= type = cache,target= /.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /machined
2019-07-16 15:09:35 +00:00
RUN chmod +x /machined
2019-07-21 18:27:15 +00:00
2019-07-16 15:09:35 +00:00
FROM scratch AS machined
COPY --from= machined-build /machined /machined
2019-07-13 00:24:51 +00:00
# The ntpd target builds the ntpd image.
FROM base AS ntpd-build
ARG SHA
ARG TAG
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
WORKDIR /src/internal/app/ntpd
RUN go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /ntpd
RUN chmod +x /ntpd
2019-07-21 18:27:15 +00:00
2019-07-13 00:24:51 +00:00
FROM scratch AS ntpd
COPY --from= ntpd-build /ntpd /ntpd
ENTRYPOINT [ "/ntpd" ]
# The osd target builds the osd image.
2018-12-19 22:22:05 -08:00
2019-04-18 19:31:43 -07:00
FROM base AS osd-build
2018-12-19 22:22:05 -08:00
ARG SHA
ARG TAG
2019-04-03 18:29:21 -07:00
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
2018-12-19 22:22:05 -08:00
WORKDIR /src/internal/app/osd
2019-07-25 00:29:50 +03:00
RUN --mount= type = cache,target= /.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /osd
2018-12-19 22:22:05 -08:00
RUN chmod +x /osd
2019-07-21 18:27:15 +00:00
2018-12-19 22:22:05 -08:00
FROM scratch AS osd
COPY --from= osd-build /osd /osd
ENTRYPOINT [ "/osd" ]
2019-07-13 00:24:51 +00:00
# The proxyd target builds the proxyd image.
2019-01-19 01:58:26 -08:00
2019-07-13 00:24:51 +00:00
FROM base AS proxyd-build
2019-01-19 01:58:26 -08:00
ARG SHA
ARG TAG
2019-04-03 18:29:21 -07:00
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
2019-07-13 00:24:51 +00:00
WORKDIR /src/internal/app/proxyd
2019-07-25 00:29:50 +03:00
RUN --mount= type = cache,target= /.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /proxyd
2019-07-13 00:24:51 +00:00
RUN chmod +x /proxyd
2019-07-21 18:27:15 +00:00
2019-07-13 00:24:51 +00:00
FROM scratch AS proxyd
COPY --from= proxyd-build /proxyd /proxyd
ENTRYPOINT [ "/proxyd" ]
2018-12-19 22:22:05 -08:00
2019-04-18 19:31:43 -07:00
# The trustd target builds the trustd image.
2019-01-18 06:26:12 -08:00
2019-04-18 19:31:43 -07:00
FROM base AS trustd-build
2018-12-19 22:22:05 -08:00
ARG SHA
ARG TAG
2019-04-03 18:29:21 -07:00
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
2018-12-19 22:22:05 -08:00
WORKDIR /src/internal/app/trustd
2019-07-25 00:29:50 +03:00
RUN --mount= type = cache,target= /.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /trustd
2018-12-19 22:22:05 -08:00
RUN chmod +x /trustd
2019-07-21 18:27:15 +00:00
2018-12-19 22:22:05 -08:00
FROM scratch AS trustd
COPY --from= trustd-build /trustd /trustd
ENTRYPOINT [ "/trustd" ]
2019-07-13 00:24:51 +00:00
# The osctl targets build the osctl binaries.
2019-01-18 06:26:12 -08:00
2019-07-13 00:24:51 +00:00
FROM base AS osctl-linux-build
2018-12-19 22:22:05 -08:00
ARG SHA
ARG TAG
2019-04-03 18:29:21 -07:00
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
2019-07-13 00:24:51 +00:00
WORKDIR /src/cmd/osctl
2019-07-25 00:29:50 +03:00
RUN --mount= type = cache,target= /.cache GOOS = linux GOARCH = amd64 go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Client -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /osctl-linux-amd64
2019-07-13 00:24:51 +00:00
RUN chmod +x /osctl-linux-amd64
2019-07-21 18:27:15 +00:00
2019-07-13 00:24:51 +00:00
FROM scratch AS osctl-linux
COPY --from= osctl-linux-build /osctl-linux-amd64 /osctl-linux-amd64
2019-04-18 19:31:43 -07:00
2019-07-13 00:24:51 +00:00
FROM base AS osctl-darwin-build
2019-04-18 19:31:43 -07:00
ARG SHA
ARG TAG
ARG VERSION_PKG = "github.com/talos-systems/talos/internal/pkg/version"
2019-07-13 00:24:51 +00:00
WORKDIR /src/cmd/osctl
2019-07-25 00:29:50 +03:00
RUN --mount= type = cache,target= /.cache GOOS = darwin GOARCH = amd64 go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Client -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /osctl-darwin-amd64
2019-07-13 00:24:51 +00:00
RUN chmod +x /osctl-darwin-amd64
2019-07-21 18:27:15 +00:00
2019-07-13 00:24:51 +00:00
FROM scratch AS osctl-darwin
COPY --from= osctl-darwin-build /osctl-darwin-amd64 /osctl-darwin-amd64
2019-04-18 19:31:43 -07:00
# The kernel target is the linux kernel.
2019-07-13 00:24:51 +00:00
FROM scratch AS kernel
2019-07-21 18:27:15 +00:00
COPY --from= docker.io/autonomy/kernel:a135947 /boot/vmlinuz /vmlinuz
COPY --from= docker.io/autonomy/kernel:a135947 /boot/vmlinux /vmlinux
2019-04-18 19:31:43 -07:00
2019-07-21 18:27:15 +00:00
# The rootfs target provides the Talos rootfs.
2019-04-18 19:31:43 -07:00
2019-07-21 18:27:15 +00:00
FROM build AS rootfs-base
2019-07-13 00:24:51 +00:00
COPY --from= docker.io/autonomy/fhs:8467184 / /rootfs
COPY --from= docker.io/autonomy/ca-certificates:20f39f7 / /rootfs
COPY --from= docker.io/autonomy/containerd:03821f9 / /rootfs
COPY --from= docker.io/autonomy/cni:063e06f / /rootfs
COPY --from= docker.io/autonomy/dosfstools:767dee6 / /rootfs
COPY --from= docker.io/autonomy/eudev:05186a8 / /rootfs
COPY --from= docker.io/autonomy/iptables:a7aa58f / /rootfs
COPY --from= docker.io/autonomy/libressl:3fca2cf / /rootfs
COPY --from= docker.io/autonomy/libseccomp:80ea634 / /rootfs
COPY --from= docker.io/autonomy/musl:9bc7430 / /rootfs
COPY --from= docker.io/autonomy/runc:c79f79d / /rootfs
COPY --from= docker.io/autonomy/socat:032c783 / /rootfs
COPY --from= docker.io/autonomy/syslinux:85e1f9c / /rootfs
COPY --from= docker.io/autonomy/xfsprogs:5e50579 / /rootfs
COPY --from= docker.io/autonomy/kubeadm:8607389 / /rootfs
COPY --from= docker.io/autonomy/crictl:ddbeea1 / /rootfs
COPY --from= docker.io/autonomy/base:f9a4941 /toolchain/lib/libblkid.* /rootfs/lib
COPY --from= docker.io/autonomy/base:f9a4941 /toolchain/lib/libuuid.* /rootfs/lib
COPY --from= docker.io/autonomy/base:f9a4941 /toolchain/lib/libkmod.* /rootfs/lib
2019-07-21 18:27:15 +00:00
COPY --from= docker.io/autonomy/kernel:a135947 /lib/modules /rootfs/lib/modules
COPY --from= machined /machined /rootfs/sbin/init
COPY images/ntpd.tar /rootfs/usr/images/
COPY images/osd.tar /rootfs/usr/images/
COPY images/proxyd.tar /rootfs/usr/images/
COPY images/trustd.tar /rootfs/usr/images/
2019-07-25 21:38:20 +00:00
# NB: We run the cleanup step before creating extra directories, files, and
# symlinks to avoid accidentally cleaning them up.
COPY ./hack/cleanup.sh /toolchain/bin/cleanup.sh
RUN cleanup.sh /rootfs
2019-07-21 18:27:15 +00:00
RUN touch /rootfs/etc/resolv.conf
RUN touch /rootfs/etc/hosts
RUN touch /rootfs/etc/os-release
RUN mkdir -pv /rootfs/{ boot,usr/local/share}
RUN mkdir -pv /rootfs/{ etc/kubernetes/manifests,etc/cni,usr/libexec/kubernetes}
RUN ln -s /etc/ssl /rootfs/etc/pki
RUN ln -s /etc/ssl /rootfs/usr/share/ca-certificates
RUN ln -s /etc/ssl /rootfs/usr/local/share/ca-certificates
RUN ln -s /etc/ssl /rootfs/etc/ca-certificates
2019-07-13 00:24:51 +00:00
2019-07-21 18:27:15 +00:00
FROM rootfs-base AS rootfs-squashfs
COPY --from= rootfs / /rootfs
RUN mksquashfs /rootfs /rootfs.sqsh -all-root -noappend -comp xz -Xdict-size 100%
2019-04-18 19:31:43 -07:00
FROM scratch AS rootfs
2019-07-21 18:27:15 +00:00
COPY --from= rootfs-base /rootfs /
# The initramfs target provides the Talos initramfs image.
FROM build AS initramfs-archive
WORKDIR /initramfs
COPY --from= rootfs-squashfs /rootfs.sqsh .
COPY --from= init /init .
RUN set -o pipefail && find . 2>/dev/null | cpio -H newc -o | xz -v -C crc32 -0 -e -T 0 -z >/initramfs.xz
FROM scratch AS initramfs
COPY --from= initramfs-archive /initramfs.xz /initramfs.xz
2019-04-18 19:31:43 -07:00
# The talos target generates a docker image that can be used to run Talos
# in containers.
FROM scratch AS talos
2019-07-21 18:27:15 +00:00
COPY --from= rootfs / /
ENTRYPOINT [ "/sbin/init" ]
2019-04-18 19:31:43 -07:00
2019-05-15 16:14:30 -07:00
# The installer target generates an image that can be used to install Talos to
# various environments.
2019-04-18 19:31:43 -07:00
FROM alpine:3.8 AS installer
2019-05-15 16:14:30 -07:00
RUN apk --update add \
2019-06-25 19:25:57 -07:00
bash \
cdrkit \
curl \
qemu-img \
syslinux \
unzip \
util-linux \
xfsprogs
2019-07-03 23:07:02 -05:00
COPY --from= hashicorp/packer:1.4.2 /bin/packer /bin/packer
COPY hack/installer/packer.json /packer.json
COPY hack/installer/entrypoint.sh /bin/entrypoint.sh
2019-05-15 16:14:30 -07:00
COPY --from= kernel /vmlinuz /usr/install/vmlinuz
2019-07-21 18:27:15 +00:00
COPY --from= rootfs /usr/lib/syslinux/ /usr/lib/syslinux
2019-05-15 16:14:30 -07:00
COPY --from= initramfs /initramfs.xz /usr/install/initramfs.xz
2019-07-13 00:24:51 +00:00
COPY --from= osctl-linux-build /osctl-linux-amd64 /bin/osctl
2019-04-18 19:31:43 -07:00
ARG TAG
ENV VERSION ${ TAG }
ENTRYPOINT [ "entrypoint.sh" ]
2019-07-13 00:24:51 +00:00
# The test target performs tests on the source code.
2019-07-18 23:05:26 +03:00
FROM base AS test-runner
2019-07-13 00:24:51 +00:00
RUN unlink /etc/ssl
2019-07-21 18:27:15 +00:00
COPY --from= rootfs / /
2019-07-13 00:24:51 +00:00
COPY hack/golang/test.sh /bin
2019-07-23 17:17:16 +03:00
ARG TESTPKGS
2019-07-25 00:29:50 +03:00
RUN --security= insecure --mount= type = cache,target= /tmp --mount= type = cache,target= /.cache /bin/test.sh ${ TESTPKGS }
2019-07-18 23:05:26 +03:00
FROM scratch AS test
COPY --from= test-runner /src/coverage.txt /coverage.txt
2019-07-13 00:24:51 +00:00
# The lint target performs linting on the source code.
FROM base AS lint
COPY hack/golang/golangci-lint.yaml .
2019-07-25 00:29:50 +03:00
RUN --mount= type = cache,target= /.cache golangci-lint run --config golangci-lint.yaml