This repository has been archived by the owner on Nov 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
91 lines (76 loc) · 3.14 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
ARG NODE_ENV=production
ARG UBUNTU_VERSION=22.04
FROM ubuntu:$UBUNTU_VERSION as base
RUN apt-get update && \
apt-get install -y \
curl \
wget \
git \
&& rm -rf /var/lib/apt/lists/*
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 ubuntu
FROM base as node
ARG NODE_VERSION=18
ENV NODE_VERSION=$NODE_VERSION
RUN wget -qO- https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \
&& apt-get install nodejs \
&& npm install -g yarn \
&& rm -rf /var/lib/apt/lists/*
FROM base as kubectl
ARG KUBECTL_VERSION=v1.25.0
ENV KUBECTL_VERSION=$KUBECTL_VERSION
RUN curl --fail -sL https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl > /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl
FROM base as gomplate
ARG GOMPLATE_VERSION=v1.9.0
ENV GOMPLATE_VERSION=$GOMPLATE_VERSION
RUN curl --fail -sL https://github.com/hairyhenderson/gomplate/releases/download/${GOMPLATE_VERSION}/gomplate_linux-amd64 > /tmp/gomplate \
&& mv /tmp/gomplate /usr/local/bin/gomplate \
&& chmod +x /usr/local/bin/gomplate
FROM base as rollout-status
ARG ROLLOUT_STATUS_VERSION=v1.9.1
ENV ROLLOUT_STATUS_VERSION=$ROLLOUT_STATUS_VERSION
RUN curl --fail -sL https://github.com/SocialGouv/rollout-status/releases/download/${ROLLOUT_STATUS_VERSION}/rollout-status-${ROLLOUT_STATUS_VERSION}-linux-amd64 > /tmp/rollout-status \
&& mv /tmp/rollout-status /usr/local/bin/rollout-status \
&& chmod +x /usr/local/bin/rollout-status
FROM base as snip
ARG SNIP_VERSION=v1.13.3
ENV SNIP_VERSION=$SNIP_VERSION
RUN curl --fail -sL https://github.com/devthejo/snip/releases/download/${SNIP_VERSION}/snip-${SNIP_VERSION}-linux-amd64 > /tmp/snip \
&& mv /tmp/snip /usr/local/bin/snip \
&& chmod +x /usr/local/bin/snip
FROM base as jq
ARG JQ_VERSION=1.6
ENV JQ_VERSION=$JQ_VERSION
RUN curl --fail -sL https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64 > /tmp/jq \
&& mv /tmp/jq /usr/local/bin/jq \
&& chmod +x /usr/local/bin/jq
## PREPARE (package.json to avoid node_modules cache invalidation on version bumping)
FROM node as preparation
COPY package.json /app/
RUN node -e "fs.writeFileSync('/app/package.json', JSON.stringify({ ...JSON.parse(fs.readFileSync('/app/package.json')), version: '0.0.0' }));"
## FINAL IMAGE
FROM node as server
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
ENV GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
RUN mkdir /app && chown 1000 /app
ENV PATH=$PATH:/app/bin:/app/node_modules/.bin
ENV PWD=/app
WORKDIR /app
USER 1000
CMD ["yarn", "start"]
COPY --from=kubectl /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=gomplate /usr/local/bin/gomplate /usr/local/bin/gomplate
COPY --from=rollout-status /usr/local/bin/rollout-status /usr/local/bin/rollout-status
COPY --from=snip /usr/local/bin/snip /usr/local/bin/snip
COPY --from=jq /usr/local/bin/jq /usr/local/bin/jq
### INSTALL (node modules)
COPY --from=preparation --chown=1000 /app/package.json ./
COPY --chown=1000 yarn.lock .yarnrc.yml .env.default ./
COPY --chown=1000 .yarn .yarn
#### YARN INSTALL
RUN mkdir common
RUN yarn install --immutable \
&& yarn cache clean
### COPY (package sources)
COPY --chown=1000 . .