Skip to content

Commit

Permalink
build: Use alpine, buildkit, and refactor pkg caching. Fixes argoproj…
Browse files Browse the repository at this point in the history
…#10134 (argoproj#10135)

Signed-off-by: J.P. Zivalich <[email protected]>
  • Loading branch information
JPZ13 authored Dec 1, 2022
1 parent 652970c commit 6673cfb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
66 changes: 28 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

####################################################################################################

Expand All @@ -71,31 +59,33 @@ 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

####################################################################################################

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/
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6673cfb

Please sign in to comment.