-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
105 lines (83 loc) · 2.94 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# ------------------
# Build playwright
# ------------------
FROM ubuntu:jammy as base
# For tzdata
ARG DEBIAN_FRONTEND=noninteractive
ARG TZ=America/Los_Angeles
# === INSTALL Node.js ===
RUN apt-get update && \
# Install node16
apt-get install -y curl wget && \
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
# Feature-parity with node.js base images.
apt-get install -y --no-install-recommends git openssh-client && \
npm install -g yarn && \
# clean apt cache
rm -rf /var/lib/apt/lists/* && \
# Create the pwuser
adduser pwuser
# === BAKE BROWSERS INTO IMAGE ===
ARG PLAYWRIGHT_VERSION
ENV PLAYWRIGHT_VERSION ${PLAYWRIGHT_VERSION}
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
# Browsers will be downloaded in `/ms-playwright`.
RUN mkdir /ms-playwright \
&& PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true npm install -g playwright@$PLAYWRIGHT_VERSION \
&& npx playwright install --with-deps chromium \
&& npx playwright install --with-deps firefox \
# Clean cache
&& rm -rf /var/lib/apt/lists/* \
&& chmod -R 777 /ms-playwright
# ------------------
# package.json cache
# ------------------
FROM apteno/alpine-jq:2022-09-25 AS deps
# To prevent cache invalidation from changes in fields other than dependencies
COPY package.json /tmp
RUN jq 'walk(if type == "object" then with_entries(select(.key | test("^jest|prettier|eslint|semantic|dotenv|nodemon") | not)) else . end) | { name, dependencies, devDependencies, packageManager }' < /tmp/package.json > /tmp/deps.json
# ------------------
# New base image
# ------------------
FROM base as tmp
ENV IN_DOCKER true
ENV PLAYWRIGHT_BROWSERS_PATH="/ms-playwright"
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD="true"
# Setup the app WORKDIR
WORKDIR /app/tmp
# Copy and install dependencies separately from the app's code
# To leverage Docker's cache when no dependency has change
COPY --from=deps /tmp/deps.json ./package.json
COPY yarn.lock .yarnrc.yml ./
COPY .yarn .yarn
# Install dev dependencies
RUN true \
&& yarn install
# This step will invalidates cache
COPY . ./
# Builds the UI, install chrome and remove dev dependencies
RUN true \
&& ls -lah /app/tmp \
&& yarn build \
&& yarn workspaces focus --all --production \
&& rm -rf .yarn/
# ------------------
# New final image that only contains built code
# ------------------
FROM base as final
ARG VERSION
ENV VERSION ${VERSION:-dev}
# Autolink repository https://docs.github.com/en/packages/learn-github-packages/connecting-a-repository-to-a-package
LABEL org.opencontainers.image.source=https://github.com/algolia/renderscript
LABEL org.opencontainers.image.revision=$VERSION
ENV NODE_ENV production
ENV IN_DOCKER true
ENV PLAYWRIGHT_BROWSERS_PATH="/ms-playwright"
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD="true"
# Do not use root to run the app
USER pwuser
# Copy install from previous stage
WORKDIR /app/renderscript
COPY --from=tmp --chown=pwuser:pwuser /app/tmp /app/renderscript
CMD [ "node", "dist/index.js" ]