-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: Simpler Docker build #5057
Changes from 1 commit
1d73d86
dfa4833
4311723
2d1ecb8
5654369
3389d04
ecfbf6f
36d0fba
c992059
f9d2d41
f651360
be31b1b
0609dbb
ce1d62e
526de2a
13572ec
1ee7e45
174c5e1
d3bbf14
df85ec9
a5cc59e
781f62b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
# Prevent vendor directory from being copied to ensure we are not not pulling unexpected cruft from | ||
# a user's workspace, and are only building off of what is locked by dep. | ||
*.iml | ||
*.md | ||
*.yaml | ||
.github | ||
.idea | ||
.run | ||
assets | ||
community | ||
coverage.out | ||
dist | ||
docs | ||
examples | ||
manifests | ||
sdks | ||
vendor | ||
test/e2e | ||
ui/dist | ||
ui/node_modules | ||
ui/node_modules | ||
v3 | ||
vendor |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ on: | |
- v* | ||
branches: | ||
- master | ||
- buildx | ||
|
||
defaults: | ||
run: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#################################################################################################### | ||
# Builder image | ||
# Initial stage which pulls prepares build dependencies and CLI tooling we need for our final image | ||
# Also used as the image in CI jobs so needs all dependencies | ||
#################################################################################################### | ||
FROM golang:1.15.7 as builder | ||
|
||
ARG IMAGE_OS=linux | ||
ARG DOCKER_CHANNEL=stable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ARGs can and should go before the first FROM |
||
ARG DOCKER_VERSION=18.09.1 | ||
# NOTE: kubectl version should be one minor version less than https://storage.googleapis.com/kubernetes-release/release/stable.txt | ||
ARG KUBECTL_VERSION=1.19.6 | ||
ARG JQ_VERSION=1.6 | ||
|
||
FROM golang:1.15.7 as builder | ||
|
||
RUN apt-get update && apt-get --no-install-recommends install -y \ | ||
git \ | ||
|
@@ -27,32 +27,24 @@ RUN apt-get update && apt-get --no-install-recommends install -y \ | |
|
||
WORKDIR /tmp | ||
|
||
# Install docker | ||
ENV DOCKER_CHANNEL stable | ||
ENV DOCKER_VERSION 18.09.1 | ||
|
||
RUN if [ "${IMAGE_OS}" = "linux" ]; then \ | ||
export IMAGE_ARCH=`uname -m`; \ | ||
if [ "${IMAGE_ARCH}" = "ppc64le" ] ||[ "${IMAGE_ARCH}" = "s390x" ]; then \ | ||
wget -O docker.tgz https://download.docker.com/${IMAGE_OS}/static/${DOCKER_CHANNEL}/${IMAGE_ARCH}/docker-18.06.3-ce.tgz; \ | ||
else \ | ||
wget -O docker.tgz https://download.docker.com/${IMAGE_OS}/static/${DOCKER_CHANNEL}/${IMAGE_ARCH}/docker-${DOCKER_VERSION}.tgz; \ | ||
fi \ | ||
fi && \ | ||
tar --extract --file docker.tgz --strip-components 1 --directory /usr/local/bin/ && \ | ||
rm docker.tgz | ||
# https://blog.container-solutions.com/faster-builds-in-docker-with-go-1-11 | ||
WORKDIR /go/src/github.com/argoproj/argo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. classic cache speed up technique |
||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
|
||
WORKDIR /go/src/github.com/argoproj/argo | ||
alexec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
COPY . . | ||
|
||
#################################################################################################### | ||
# argoexec-base | ||
# Used as the base for both the release and development version of argoexec | ||
#################################################################################################### | ||
|
||
FROM debian:10.7-slim as argoexec-base | ||
|
||
ARG IMAGE_OS=linux | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need this because we use `docker buildx --platform linux/amd64' |
||
ARG DOCKER_CHANNEL | ||
ARG DOCKER_VERSION | ||
ARG KUBECTL_VERSION | ||
ARG JQ_VERSION | ||
|
||
# NOTE: kubectl version should be one minor version less than https://storage.googleapis.com/kubernetes-release/release/stable.txt | ||
ENV KUBECTL_VERSION=1.19.6 | ||
ENV JQ_VERSION=1.6 | ||
RUN apt-get update && \ | ||
apt-get --no-install-recommends install -y curl procps git apt-utils apt-transport-https ca-certificates tar mime-support && \ | ||
apt-get clean \ | ||
|
@@ -64,85 +56,89 @@ RUN apt-get update && \ | |
/usr/share/doc \ | ||
/usr/share/doc-base | ||
|
||
ADD hack/recurl.sh . | ||
ADD hack/image_arch.sh . | ||
RUN . ./image_arch.sh && ./recurl.sh /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/${IMAGE_OS}/${IMAGE_ARCH}/kubectl | ||
COPY hack/recurl.sh . | ||
RUN if [ $(uname -m) = ppc64le ] || [ $(uname -m) = s390x ]; then \ | ||
./recurl.sh docker.tgz https://download.docker.com/$(uname -s|tr '[:upper:]' '[:lower:]')/static/${DOCKER_CHANNEL}/$(uname -m) docker-18.06.3-ce.tgz; \ | ||
else \ | ||
./recurl.sh docker.tgz https://download.docker.com/$(uname -s|tr '[:upper:]' '[:lower:]')/static/${DOCKER_CHANNEL}/$(uname -m)/docker-${DOCKER_VERSION}.tgz; \ | ||
fi && \ | ||
tar --extract --file docker.tgz --strip-components 1 --directory /usr/local/bin/ && \ | ||
rm docker.tgz | ||
|
||
RUN ./recurl.sh /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/$(uname -s|tr '[:upper:]' '[:lower:]')/$(uname -m)/kubectl | ||
RUN ./recurl.sh /usr/local/bin/jq https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64 | ||
RUN rm recurl.sh | ||
|
||
COPY hack/ssh_known_hosts /etc/ssh/ssh_known_hosts | ||
COPY hack/nsswitch.conf /etc/nsswitch.conf | ||
COPY --from=builder /usr/local/bin/docker /usr/local/bin/ | ||
COPY hack/ssh_known_hosts /etc/ssh/ | ||
COPY hack/nsswitch.conf /etc/ | ||
|
||
|
||
#################################################################################################### | ||
|
||
FROM node:14.0.0 as argo-ui | ||
|
||
ADD ["ui", "ui"] | ||
ADD ["api", "api"] | ||
COPY ui/package.json ui/yarn.lock ui/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another classic speed up technique |
||
|
||
RUN JOBS=max yarn --cwd ui install --network-timeout 1000000 | ||
|
||
COPY ui ui | ||
COPY api api | ||
|
||
RUN JOBS=max yarn --cwd ui build | ||
|
||
#################################################################################################### | ||
# Argo Build stage which performs the actual build of Argo binaries | ||
|
||
FROM builder as argoexec-build | ||
|
||
RUN --mount=type=cache,target=/root/.cache/go-build make dist/argoexec | ||
|
||
#################################################################################################### | ||
FROM builder as argo-build | ||
|
||
ARG IMAGE_OS=linux | ||
FROM builder as workflow-controller-build | ||
|
||
# Perform the build | ||
WORKDIR /go/src/github.com/argoproj/argo | ||
COPY . . | ||
# check we can use Git | ||
RUN git rev-parse HEAD | ||
RUN --mount=type=cache,target=/root/.cache/go-build make dist/workflow-controller | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a buildx way to do build caching, I'm not 100% sure it works, so we may want to remove later on |
||
|
||
# controller image | ||
RUN . hack/image_arch.sh && make dist/workflow-controller-${IMAGE_OS}-${IMAGE_ARCH} | ||
RUN . hack/image_arch.sh && ./dist/workflow-controller-${IMAGE_OS}-${IMAGE_ARCH} version | grep clean | ||
#################################################################################################### | ||
|
||
# executor image | ||
RUN . hack/image_arch.sh && make dist/argoexec-${IMAGE_OS}-${IMAGE_ARCH} | ||
RUN . hack/image_arch.sh && ./dist/argoexec-${IMAGE_OS}-${IMAGE_ARCH} version | grep clean | ||
FROM builder as argocli-build | ||
|
||
# cli image | ||
RUN mkdir -p ui/dist | ||
COPY --from=argo-ui ui/dist/app ui/dist/app | ||
# stop make from trying to re-build this without yarn installed | ||
RUN touch ui/dist/node_modules.marker | ||
RUN touch ui/dist/app/index.html | ||
RUN . hack/image_arch.sh && make argo-server.crt argo-server.key dist/argo-${IMAGE_OS}-${IMAGE_ARCH} | ||
RUN . hack/image_arch.sh && ./dist/argo-${IMAGE_OS}-${IMAGE_ARCH} version 2>&1 | grep clean | ||
RUN --mount=type=cache,target=/root/.cache/go-build make dist/argo | ||
|
||
#################################################################################################### | ||
# argoexec | ||
#################################################################################################### | ||
|
||
FROM argoexec-base as argoexec | ||
ARG IMAGE_OS=linux | ||
COPY --from=argo-build /go/src/github.com/argoproj/argo/dist/argoexec-${IMAGE_OS}-* /usr/local/bin/argoexec | ||
|
||
COPY --from=argoexec-build /go/src/github.com/argoproj/argo/dist/argoexec /usr/local/bin/ | ||
|
||
ENTRYPOINT [ "argoexec" ] | ||
|
||
#################################################################################################### | ||
# workflow-controller | ||
#################################################################################################### | ||
|
||
FROM scratch as workflow-controller | ||
|
||
USER 8737 | ||
ARG IMAGE_OS=linux | ||
# Add timezone data | ||
COPY --from=argo-build /usr/share/zoneinfo /usr/share/zoneinfo | ||
COPY --from=argo-build /go/src/github.com/argoproj/argo/dist/workflow-controller-${IMAGE_OS}-* /bin/workflow-controller | ||
|
||
COPY --from=workflow-controller-build /usr/share/zoneinfo /usr/share/ | ||
COPY --chown=8737 --from=workflow-controller-build /go/src/github.com/argoproj/argo/dist/workflow-controller /bin/ | ||
|
||
ENTRYPOINT [ "workflow-controller" ] | ||
|
||
#################################################################################################### | ||
# argocli | ||
#################################################################################################### | ||
|
||
FROM scratch as argocli | ||
|
||
USER 8737 | ||
ARG IMAGE_OS=linux | ||
COPY --from=argoexec-base /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts | ||
COPY --from=argoexec-base /etc/nsswitch.conf /etc/nsswitch.conf | ||
COPY --from=argoexec-base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY --from=argo-build --chown=8737 /go/src/github.com/argoproj/argo/argo-server.crt argo-server.crt | ||
COPY --from=argo-build --chown=8737 /go/src/github.com/argoproj/argo/argo-server.key argo-server.key | ||
COPY --from=argo-build /go/src/github.com/argoproj/argo/dist/argo-${IMAGE_OS}-* /bin/argo | ||
|
||
COPY hack/ssh_known_hosts /etc/ssh/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer depend on argoexec |
||
COPY hack/nsswitch.conf /etc/ | ||
COPY --from=argocli-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=argocli-build --chown=8737 /go/src/github.com/argoproj/argo/argo-server.crt / | ||
COPY --from=argocli-build --chown=8737 /go/src/github.com/argoproj/argo/argo-server.key / | ||
COPY --from=argocli-build /go/src/github.com/argoproj/argo/dist/argo /bin/ | ||
|
||
ENTRYPOINT [ "argo" ] |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while these files are small, they can result in invalidating the Docker caches, forcing build steps to be re-run