diff --git a/Dockerfile b/Dockerfile index e62143fbecc7..589cfbe2ac96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,66 +1,54 @@ #syntax=docker/dockerfile:1.2 -FROM golang:1.18 as builder +FROM golang:1.18-alpine3.16 as builder -RUN apt-get update && apt-get --no-install-recommends install -y \ +RUN apk update && apk add --no-cache \ git \ make \ - apt-utils \ - apt-transport-https \ ca-certificates \ wget \ - gcc && \ - apt-get clean \ - && rm -rf \ - /var/lib/apt/lists/* \ - /tmp/* \ - /var/tmp/* \ - /usr/share/man \ - /usr/share/doc \ - /usr/share/doc-base - -WORKDIR /tmp - -# https://blog.container-solutions.com/faster-builds-in-docker-with-go-1-11 + curl \ + gcc \ + bash \ + jq \ + mailcap + WORKDIR /go/src/github.com/argoproj/argo-workflows COPY go.mod . COPY go.sum . -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod go mod download COPY . . #################################################################################################### -FROM node:16 as argo-ui +FROM node:16-alpine as argo-ui + +RUN apk update && apk add --no-cache git COPY ui/package.json ui/yarn.lock ui/ -RUN JOBS=max yarn --cwd ui install --network-timeout 1000000 +RUN --mount=type=cache,target=/root/.yarn \ + YARN_CACHE_FOLDER=/root/.yarn JOBS=max \ + yarn --cwd ui install --network-timeout 1000000 COPY ui ui COPY api api -RUN NODE_OPTIONS="--max-old-space-size=2048" JOBS=max yarn --cwd ui build +RUN --mount=type=cache,target=/root/.yarn \ + YARN_CACHE_FOLDER=/root/.yarn JOBS=max \ + NODE_OPTIONS="--max-old-space-size=2048" JOBS=max yarn --cwd ui build #################################################################################################### FROM builder as argoexec-build -COPY hack/arch.sh hack/os.sh /bin/ - -# NOTE: kubectl version should be one minor version less than https://storage.googleapis.com/kubernetes-release/release/stable.txt -RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.24.8/bin/$(os.sh)/$(arch.sh)/kubectl && \ - chmod +x /usr/local/bin/kubectl - -RUN curl -o /usr/local/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && \ - chmod +x /usr/local/bin/jq - # Tell git to forget about all of the files that were not included because of .dockerignore in order to ensure that # the git state is "clean" even though said .dockerignore files are not present RUN cat .dockerignore >> .gitignore RUN git status --porcelain | cut -c4- | xargs git update-index --skip-worktree -RUN --mount=type=cache,target=/root/.cache/go-build make dist/argoexec +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build make dist/argoexec #################################################################################################### @@ -71,7 +59,7 @@ FROM builder as workflow-controller-build RUN cat .dockerignore >> .gitignore RUN git status --porcelain | cut -c4- | xargs git update-index --skip-worktree -RUN --mount=type=cache,target=/root/.cache/go-build make dist/workflow-controller +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build make dist/workflow-controller #################################################################################################### @@ -79,23 +67,25 @@ FROM builder as argocli-build 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 # Tell git to forget about all of the files that were not included because of .dockerignore in order to ensure that # the git state is "clean" even though said .dockerignore files are not present RUN cat .dockerignore >> .gitignore RUN git status --porcelain | cut -c4- | xargs git update-index --skip-worktree -RUN --mount=type=cache,target=/root/.cache/go-build make dist/argo +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build make dist/argo + +#################################################################################################### + +# NOTE: kubectl version should be one minor version less than https://storage.googleapis.com/kubernetes-release/release/stable.txt +FROM bitnami/kubectl:1.24.8 as kubectl #################################################################################################### FROM gcr.io/distroless/static as argoexec -COPY --from=argoexec-build /usr/local/bin/kubectl /bin/ -COPY --from=argoexec-build /usr/local/bin/jq /bin/ +COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /bin/ +COPY --from=argoexec-build /usr/bin/jq /bin/ COPY --from=argoexec-build /go/src/github.com/argoproj/argo-workflows/dist/argoexec /bin/ COPY --from=argoexec-build /etc/mime.types /etc/mime.types COPY hack/ssh_known_hosts /etc/ssh/ diff --git a/Makefile b/Makefile index acf5defaa090..b844dc52c2b5 100644 --- a/Makefile +++ b/Makefile @@ -231,9 +231,10 @@ argoexec-image: %-image: [ ! -e dist/$* ] || mv dist/$* . - docker build \ + docker buildx build \ -t $(IMAGE_NAMESPACE)/$*:$(VERSION) \ --target $* \ + --load \ . [ ! -e $* ] || mv $* dist/ docker run --rm -t $(IMAGE_NAMESPACE)/$*:$(VERSION) version