Skip to content

Instantly share code, notes, and snippets.

@thiagozs
Created June 22, 2020 22:18
Show Gist options
  • Save thiagozs/415b89439b7415098576f69dd66fa882 to your computer and use it in GitHub Desktop.
Save thiagozs/415b89439b7415098576f69dd66fa882 to your computer and use it in GitHub Desktop.
Docker two stage builder
FROM alpine:3.9 as builder
ENV VERSION=v12.16.2 NPM_VERSION=6 YARN_VERSION=latest
LABEL maintainer="Thiago Zilli Sarmento <thiago.zilli@gmail.com>"
LABEL builder="builder"
RUN apk upgrade --no-cache -U && \
apk add --no-cache \
ca-certificates \
curl \
git \
gnupg \
openssl-dev \
openssh-client \
libstdc++
RUN curl -sfSLO https://unofficial-builds.nodejs.org/download/release/${VERSION}/node-${VERSION}-linux-x64-musl.tar.xz && \
curl -sfSLO https://unofficial-builds.nodejs.org/download/release/${VERSION}/SHASUMS256.txt && \
grep " node-${VERSION}-linux-x64-musl.tar.xz\$" SHASUMS256.txt | sha256sum -c | grep ': OK$' && \
tar -xf node-${VERSION}-linux-x64-musl.tar.xz -C /usr --strip 1 && \
rm node-${VERSION}-linux-x64-musl.tar.xz
RUN npm install -g npm@${NPM_VERSION} && \
find /usr/lib/node_modules/npm -type d \( -name test -o -name .bin \) | xargs rm -rf
RUN for server in ipv4.pool.sks-keyservers.net keyserver.pgp.com ha.pool.sks-keyservers.net; do \
gpg --keyserver $server --recv-keys \
6A010C5166006599AA17F08146C2130DFD2497F5 && break; \
done && \
curl -sfSL -O https://yarnpkg.com/${YARN_VERSION}.tar.gz -O https://yarnpkg.com/${YARN_VERSION}.tar.gz.asc && \
gpg --batch --verify ${YARN_VERSION}.tar.gz.asc ${YARN_VERSION}.tar.gz && \
mkdir /usr/local/share/yarn && \
tar -xf ${YARN_VERSION}.tar.gz -C /usr/local/share/yarn --strip 1 && \
ln -s /usr/local/share/yarn/bin/yarn /usr/local/bin/ && \
ln -s /usr/local/share/yarn/bin/yarnpkg /usr/local/bin/ && \
rm ${YARN_VERSION}.tar.gz*
# Pass the SSH_PRIVATE_KEY as an ARG
ARG SSH_PRIVATE_KEY
RUN mkdir /root/.ssh/ && \
echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa && \
chmod 400 /root/.ssh/id_rsa && \
touch /root/.ssh/known_hosts && \
ssh-keyscan gitlab.com >> /root/.ssh/known_hosts
ARG BRANCH
RUN git clone --progress --verbose \
git@gitlab.com:xxxxx/yyyyy.git \
--branch ${BRANCH} /app && \
rm -fr /app/.git && \
cd /app && \
yarn install && \
yarn build
#&& yarn install --silent >/dev/null 2>&1
WORKDIR /app
FROM node:12-alpine
LABEL maintainer="Thiago Zilli Sarmento <thiago.zilli@gmail.com>"
RUN apk upgrade --no-cache -U && \
apk add --no-cache \
ca-certificates \
iputils \
curl \
shadow \
bash \
tar
WORKDIR /app
ARG ENV_FILE
COPY --from=builder /app ./
COPY ${ENV_FILE} /app/.env
COPY run.sh /app/run.sh
ARG BRANCH
ENV BRANCH=${BRANCH}
RUN export
EXPOSE 3000
CMD /app/run.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment