2019-07-06 06:20:24 +00:00
# syntax = docker/dockerfile:1.1-experimental
2019-01-23 15:48:02 -08:00
ARG KERNEL_IMAGE
ARG TOOLCHAIN_IMAGE
2019-04-18 19:31:43 -07:00
ARG ROOTFS_IMAGE
ARG INITRAMFS_IMAGE
2018-12-19 22:22:05 -08:00
2019-04-18 19:31:43 -07:00
# The proto target generates code from protobuf service definitions.
2019-01-18 06:26:12 -08:00
2019-03-28 02:33:03 +03:00
ARG TOOLCHAIN_IMAGE
FROM ${TOOLCHAIN_IMAGE} AS proto-build
2018-12-19 22:22:05 -08:00
WORKDIR /osd
COPY ./internal/app/osd/proto ./proto
RUN protoc -I/usr/local/include -I./proto --go_out= plugins = grpc:proto proto/api.proto
WORKDIR /trustd
COPY ./internal/app/trustd/proto ./proto
RUN protoc -I/usr/local/include -I./proto --go_out= plugins = grpc:proto proto/api.proto
2019-04-26 23:04:24 +03:00
WORKDIR /init
COPY ./internal/app/init/proto ./proto
RUN protoc -I/usr/local/include -I./proto --go_out= plugins = grpc:proto proto/api.proto
2018-12-19 22:22:05 -08:00
2019-03-28 02:33:03 +03:00
FROM scratch AS proto
COPY --from= proto-build /osd/proto/api.pb.go /internal/app/osd/proto/
COPY --from= proto-build /trustd/proto/api.pb.go /internal/app/trustd/proto/
2019-04-26 23:04:24 +03:00
COPY --from= proto-build /init/proto/api.pb.go /internal/app/init/proto/
2019-03-28 02:33:03 +03:00
2019-04-18 19:31:43 -07:00
# The base provides a common image to build the Talos source code.
2019-01-18 06:26:12 -08:00
2019-01-23 15:48:02 -08:00
ARG TOOLCHAIN_IMAGE
FROM ${TOOLCHAIN_IMAGE} AS base
2019-03-22 15:46:33 +03:00
ENV GOPATH /toolchain/gopath
2019-03-01 23:48:49 +03:00
RUN mkdir -p ${ GOPATH }
2018-12-19 22:22:05 -08:00
ENV GO111MODULE on
2019-05-31 23:59:52 +03:00
ENV GOPROXY https://proxy.golang.org
2019-01-18 06:26:12 -08:00
ENV CGO_ENABLED 0
2018-12-19 22:22:05 -08:00
WORKDIR /src
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
COPY --from= proto /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-01-18 06:26:12 -08:00
# The osd target builds the osd binary.
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-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.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-04-18 19:31:43 -07:00
2018-12-19 22:22:05 -08:00
FROM scratch AS osd
COPY --from= osd-build /osd /osd
ENTRYPOINT [ "/osd" ]
2019-04-18 19:31:43 -07:00
# The osctl targets build the osctl binaries.
2019-01-18 06:26:12 -08:00
2019-04-18 19:31:43 -07:00
FROM base AS osctl-linux-amd64-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-04-02 17:11:17 -07:00
WORKDIR /src/cmd/osctl
2019-07-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.cache GOOS = linux GOARCH = amd64 go build -a -ldflags " -s -w -linkmode external -extldflags \"-static\" -X ${ VERSION_PKG } .Name=Client -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /osctl-linux-amd64
2018-12-19 22:22:05 -08:00
RUN chmod +x /osctl-linux-amd64
2019-04-18 19:31:43 -07:00
2019-01-19 01:58:26 -08:00
FROM scratch AS osctl-linux-amd64
COPY --from= osctl-linux-amd64-build /osctl-linux-amd64 /osctl-linux-amd64
2019-04-18 19:31:43 -07:00
FROM base AS osctl-darwin-amd64-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-04-02 17:11:17 -07:00
WORKDIR /src/cmd/osctl
2019-07-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.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
2018-12-19 22:22:05 -08:00
RUN chmod +x /osctl-darwin-amd64
2019-04-18 19:31:43 -07:00
2019-01-19 01:58:26 -08:00
FROM scratch AS osctl-darwin-amd64
COPY --from= osctl-darwin-amd64-build /osctl-darwin-amd64 /osctl-darwin-amd64
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-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.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-04-18 19:31:43 -07:00
2018-12-19 22:22:05 -08:00
FROM scratch AS trustd
COPY --from= trustd-build /trustd /trustd
ENTRYPOINT [ "/trustd" ]
2019-04-18 19:31:43 -07:00
# The proxyd target builds the proxyd image.
2019-01-18 06:26:12 -08:00
2019-04-18 19:31:43 -07:00
FROM base AS proxyd-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/proxyd
2019-07-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /proxyd
2018-12-19 22:22:05 -08:00
RUN chmod +x /proxyd
2019-04-18 19:31:43 -07:00
2018-12-19 22:22:05 -08:00
FROM scratch AS proxyd
COPY --from= proxyd-build /proxyd /proxyd
ENTRYPOINT [ "/proxyd" ]
2019-04-18 19:31:43 -07: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
2019-07-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Server -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /ntpd
2019-04-18 19:31:43 -07:00
RUN chmod +x /ntpd
FROM scratch AS ntpd
COPY --from= ntpd-build /ntpd /ntpd
ENTRYPOINT [ "/ntpd" ]
# The binaries target allows for parallel compilation of all binaries.
FROM scratch AS binaries-build
COPY --from= init / /
COPY --from= osd / /
COPY --from= trustd / /
COPY --from= proxyd / /
COPY --from= ntpd / /
COPY --from= osctl-linux-amd64 / /
COPY --from= osctl-darwin-amd64 / /
FROM scratch AS binaries
COPY --from= binaries-build /osctl-linux-amd64 /osctl-linux-amd64
COPY --from= binaries-build /osctl-darwin-amd64 /osctl-darwin-amd64
# The kernel target is the linux kernel.
ARG KERNEL_IMAGE
FROM ${KERNEL_IMAGE} as kernel
# The initramfs target creates the compressed initramfs.
FROM base AS init-build
2019-03-23 17:58:13 -05: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-04-18 19:31:43 -07:00
WORKDIR /src/internal/app/init
2019-07-06 06:20:24 +00:00
RUN --mount= type = cache,target= /root/.cache go build -a -ldflags " -s -w -X ${ VERSION_PKG } .Name=Talos -X ${ VERSION_PKG } .SHA= ${ SHA } -X ${ VERSION_PKG } .Tag= ${ TAG } " -o /init
2019-04-18 19:31:43 -07:00
RUN chmod +x /init
FROM scratch AS init
COPY --from= init-build /init /init
ARG INITRAMFS_IMAGE
FROM ${INITRAMFS_IMAGE} AS initramfs-build
WORKDIR /
COPY --from= init-build /init /init
ARG TOOLCHAIN_IMAGE
FROM ${TOOLCHAIN_IMAGE} AS initramfs-archive
COPY --from= initramfs-build / /initramfs
WORKDIR /initramfs
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
# The rootfs target creates the root filesystem archive.
ARG ROOTFS_IMAGE
FROM ${ROOTFS_IMAGE} AS rootfs-build
2019-07-11 02:30:30 +00:00
COPY --from= kernel /modules /
2019-04-18 19:31:43 -07:00
COPY images /usr/images
ARG TOOLCHAIN_IMAGE
FROM ${TOOLCHAIN_IMAGE} AS rootfs-archive
COPY --from= rootfs-build / /rootfs
WORKDIR /rootfs
RUN tar -cvpzf /rootfs.tar.gz .
FROM scratch AS rootfs
COPY --from= rootfs-archive /rootfs.tar.gz /rootfs.tar.gz
# The test target performs tests on the source code.
FROM base AS test
COPY --from= rootfs-build / /rootfs
ENV PATH /rootfs/bin:$PATH
COPY hack/golang/test.sh /bin
# The lint target performs linting on the codebase.
2019-06-28 22:00:52 +03:00
ARG TOOLCHAIN_IMAGE
FROM ${TOOLCHAIN_IMAGE} AS golangci-lint
2019-04-18 19:31:43 -07:00
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /toolchain/bin v1.16.0
2019-06-28 22:00:52 +03:00
FROM base AS lint
2019-04-18 19:31:43 -07:00
COPY hack/golang/golangci-lint.yaml .
2019-06-28 22:00:52 +03:00
COPY --from= golangci-lint /toolchain/bin/golangci-lint /toolchain/bin/
2019-04-18 19:31:43 -07:00
RUN golangci-lint run --config golangci-lint.yaml
# The talos target generates a docker image that can be used to run Talos
# in containers.
ARG TOOLCHAIN_IMAGE
FROM ${TOOLCHAIN_IMAGE} AS talos-build
COPY --from= rootfs-build / /rootfs
# A workaround docker overwriting our /etc symlink.
RUN rm /rootfs/etc
RUN mv /rootfs/var/etc /rootfs/etc
RUN ln -s /etc /rootfs/var/etc
FROM scratch AS talos
COPY --from= talos-build /rootfs /
COPY --from= init-build /init /init
ENTRYPOINT [ "/init" ]
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-03 23:07:02 -05:00
COPY --from= initramfs-build /usr/lib/syslinux/ /usr/lib/syslinux
2019-05-15 16:14:30 -07:00
COPY --from= initramfs /initramfs.xz /usr/install/initramfs.xz
COPY --from= rootfs /rootfs.tar.gz /usr/install/rootfs.tar.gz
COPY --from= osctl-linux-amd64-build /osctl-linux-amd64 /bin/osctl
2019-04-18 19:31:43 -07:00
ARG TAG
ENV VERSION ${ TAG }
ENTRYPOINT [ "entrypoint.sh" ]