Skip to content
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

Add multi-stage docker file for CI image #45402

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Dockerfile
Dockerfile.base
bin/build-docker.sh
/.tsc-cache
/.cache
.dockerignore
Expand Down
52 changes: 52 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#### builder image
FROM node:12.18.0 as builder

ARG node_memory=8192
WORKDIR /calypso
ENV YARN_CACHE_FOLDER=/calypso/.cache/yarn
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV NVM_DIR=/calypso/.nvm
ENV NODE_ENV=production
ENV CALYPSO_ENV=production
ENV NODE_OPTIONS=--max-old-space-size=$node_memory
ENV CHROMEDRIVER_SKIP_DOWNLOAD=true
ENV PUPPETEER_SKIP_DOWNLOAD=true
ENV HOME=/calypso

RUN git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR" \
&& git -C "$NVM_DIR" checkout v0.35.3

COPY . .

# Run nvm.sh in a different dir so it doesn't try to use the version specified in /calypso/.nvmrc.
# If not, it will fail the image generation
RUN cd / \
&& . "$NVM_DIR/nvm.sh" \
&& cd $HOME \
&& nvm install \
&& nvm use \
# Prime yarn cache
&& yarn \
# Prime webpack caches
&& yarn build-client-both

ENTRYPOINT [ "/bin/bash" ]

#### ci image
FROM node:12.18.0 as ci

ARG node_memory=8192
ARG UID=1003

WORKDIR /calypso
ENV YARN_CACHE_FOLDER=/calypso/.cache/yarn
ENV NPM_CONFIG_CACHE=/calypso/.cache
ENV NVM_DIR=/calypso/.nvm
ENV NODE_OPTIONS=--max-old-space-size=$node_memory
ENV HOME=/calypso

RUN chown $UID /calypso
# Copy nvm cache so we don't need to download it again
COPY --from=builder --chown=$UID /calypso/.nvm /calypso/.nvm
# Copy all other caches (webpack, babel, yarn...)
COPY --from=builder --chown=$UID /calypso/.cache /calypso/.cache
19 changes: 19 additions & 0 deletions bin/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -o errexit
set -o nounset
set -o pipefail

if [[ -z "${1:-}" ]] ; then
echo "Missing version. Usage:"
echo "$0 <version>"
exit 1
fi

VERSION="$1"
BUILDER_IMAGE_NAME="registry.a8c.com/calypso/base"
CI_IMAGE_NAME="registry.a8c.com/calypso/ci"
BUILDER_IMAGE="${BUILDER_IMAGE_NAME}:${VERSION}"
CI_IMAGE="${CI_IMAGE_NAME}:${VERSION}"

docker build -f Dockerfile.base --no-cache --target builder -t "$BUILDER_IMAGE" .
docker build -f Dockerfile.base --target ci -t "$CI_IMAGE" .