Skip to content

Commit

Permalink
chore: refactor Dockerfiles to reduce build time (argoproj#9081)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian <colid.bondzio@gmail.com>
  • Loading branch information
adriang-90 authored Apr 13, 2022
1 parent fa46ac1 commit cc6c625
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 53 deletions.
71 changes: 36 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ ARG BASE_IMAGE=docker.io/library/ubuntu:21.10
# 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 docker.io/library/golang:1.18 as builder
FROM docker.io/library/golang:1.18 AS builder

RUN echo 'deb http://deb.debian.org/debian buster-backports main' >> /etc/apt/sources.list

RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install --no-install-recommends -y \
openssh-server \
nginx \
unzip \
fcgiwrap \
git \
git-lfs \
Expand All @@ -24,18 +25,17 @@ RUN apt-get update && apt-get install -y \

WORKDIR /tmp

ADD hack/install.sh .
ADD hack/installers installers
ADD hack/tool-versions.sh .
COPY hack/install.sh hack/tool-versions.sh ./
COPY hack/installers installers

RUN ./install.sh helm-linux
RUN INSTALL_PATH=/usr/local/bin ./install.sh kustomize
RUN ./install.sh awscli-linux
RUN ./install.sh helm-linux && \
INSTALL_PATH=/usr/local/bin ./install.sh kustomize && \
./install.sh awscli-linux

####################################################################################################
# Argo CD Base - used as the base for both the release and dev argocd images
####################################################################################################
FROM $BASE_IMAGE as argocd-base
FROM $BASE_IMAGE AS argocd-base

USER root

Expand All @@ -48,7 +48,8 @@ RUN groupadd -g 999 argocd && \
chmod g=u /home/argocd && \
apt-get update && \
apt-get dist-upgrade -y && \
apt-get install -y git git-lfs tini gpg tzdata && \
apt-get install -y \
git git-lfs tini gpg tzdata && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand All @@ -59,19 +60,20 @@ COPY --from=builder /usr/local/bin/kustomize /usr/local/bin/kustomize
COPY --from=builder /usr/local/aws-cli/v2/current/dist /usr/local/aws-cli/v2/current/dist
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
# keep uid_entrypoint.sh for backward compatibility
RUN ln -s /usr/local/bin/entrypoint.sh /usr/local/bin/uid_entrypoint.sh
RUN ln -s /usr/local/aws-cli/v2/current/dist/aws /usr/local/bin/aws
RUN ln -s /usr/local/bin/entrypoint.sh /usr/local/bin/uid_entrypoint.sh && \
ln -s /usr/local/aws-cli/v2/current/dist/aws /usr/local/bin/aws

# support for mounting configuration from a configmap
RUN mkdir -p /app/config/ssh && \
touch /app/config/ssh/ssh_known_hosts && \
ln -s /app/config/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts
WORKDIR /app/config/ssh
RUN touch ssh_known_hosts && \
ln -s ssh_known_hosts /etc/ssh/ssh_known_hosts

RUN mkdir -p /app/config/tls
RUN mkdir -p /app/config/gpg/source && \
mkdir -p /app/config/gpg/keys && \
chown argocd /app/config/gpg/keys && \
chmod 0700 /app/config/gpg/keys
WORKDIR /app/config
RUN mkdir -p tls && \
mkdir -p gpg/source && \
mkdir -p gpg/keys && \
chown argocd gpg/keys && \
chmod 0700 gpg/keys

ENV USER=argocd

Expand All @@ -81,14 +83,15 @@ WORKDIR /home/argocd
####################################################################################################
# Argo CD UI stage
####################################################################################################
FROM --platform=$BUILDPLATFORM docker.io/library/node:12.18.4 as argocd-ui
FROM --platform=$BUILDPLATFORM docker.io/library/node:12.18.4 AS argocd-ui

WORKDIR /src
ADD ["ui/package.json", "ui/yarn.lock", "./"]
COPY ["ui/package.json", "ui/yarn.lock", "./"]

RUN yarn install --network-timeout 200000
RUN yarn install --network-timeout 200000 && \
yarn cache clean

ADD ["ui/", "."]
COPY ["ui/", "."]

ARG ARGO_VERSION=latest
ENV ARGO_VERSION=$ARGO_VERSION
Expand All @@ -97,13 +100,11 @@ RUN HOST_ARCH='amd64' NODE_ENV='production' NODE_ONLINE_ENV='online' NODE_OPTION
####################################################################################################
# Argo CD Build stage which performs the actual build of Argo CD binaries
####################################################################################################
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.18 as argocd-build
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.18 AS argocd-build

WORKDIR /go/src/github.com/argoproj/argo-cd

COPY go.mod go.mod
COPY go.sum go.sum

COPY go.* ./
RUN go mod download

# Perform the build
Expand All @@ -120,12 +121,12 @@ FROM argocd-base
COPY --from=argocd-build /go/src/github.com/argoproj/argo-cd/dist/argocd* /usr/local/bin/

USER root
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-cmp-server
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-notifications
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-applicationset-controller
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-cmp-server && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-notifications && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-applicationset-controller

USER 999
12 changes: 6 additions & 6 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ FROM argocd-base
COPY argocd /usr/local/bin/

USER root
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-notifications
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-applicationset-controller
RUN ln -s /usr/local/bin/argocd /usr/local/bin/argocd-server && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-repo-server && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-application-controller && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-dex && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-notifications && \
ln -s /usr/local/bin/argocd /usr/local/bin/argocd-applicationset-controller

USER 999
7 changes: 2 additions & 5 deletions test/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ ENV GOROOT /usr/local/go
ENV GOPATH /go

# Install build and test dependencies
ADD ./hack/tool-versions.sh .
ADD ./hack/install.sh .
ADD ./hack/installers installers
ADD go.mod go.mod
ADD go.sum go.sum
COPY hack/install.sh hack/tool-versions.sh go.* ./
COPY hack/installers installers

RUN ./install.sh helm-linux && \
./install.sh kubectl-linux && \
Expand Down
4 changes: 2 additions & 2 deletions test/remote/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN go install github.com/mattn/goreman@latest && \
FROM ubuntu:21.10

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install --no-install-recommends -y \
ca-certificates \
curl \
openssh-server \
Expand All @@ -23,7 +23,7 @@ RUN apt-get update && apt-get install -y \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir -p /etc/certs
WORKDIR /etc/certs

# These are required for running end-to-end tests
COPY ./test/fixture/testrepos/id_rsa.pub /root/.ssh/authorized_keys
Expand Down
10 changes: 5 additions & 5 deletions ui-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM node:12.18.4 as node
FROM node:12.18.4 AS node

RUN apt-get update && apt-get install -y \
software-properties-common
RUN apt-get update && apt-get install --no-install-recommends -y \
software-properties-common

#Chrome browser to run the tests
ARG CHROME_VERSION=86.0.4240.75
RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add \
&& wget https://www.slimjet.com/chrome/download-chrome.php?file=files%2F$CHROME_VERSION%2Fgoogle-chrome-stable_current_amd64.deb \
&& dpkg -i download-chrome*.deb || true

RUN apt-get install -y -f \
RUN apt-get install --no-install-recommends -y -f \
&& rm -rf /var/lib/apt/lists/*

#Disable the SUID sandbox so that chrome can launch without being in a privileged container
Expand All @@ -20,6 +20,6 @@ RUN dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /o
WORKDIR /usr/src/app
COPY package*.json ./
COPY yarn.lock ./
RUN yarn install
RUN yarn install && yarn cache clean
COPY . .

0 comments on commit cc6c625

Please sign in to comment.