-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
57 lines (40 loc) · 1.32 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
# ------------------
# package.json cache
# ------------------
FROM apteno/alpine-jq:2022-03-27 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
# ------------------
# deps install
# ------------------
FROM node:20.9.0-bullseye AS base
# Setup the app WORKDIR
WORKDIR /app/rab
# 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 package-lock.json ./
# Install dev dependencies
RUN true \
&& npm install
# This step will invalidates cache
COPY . ./
# Build
RUN true \
&& npm run build \
&& rm -rf src/
# ------------------
# final image
# ------------------
FROM node:20.9.0-bullseye as web
LABEL org.opencontainers.image.source = "https://github.com/bodinsamuel/renovate-automatic-branch"
ARG git_hash
ARG version
ENV GIT_HASH ${git_hash:-dev}
ENV VERSION $version
# Do not use root to run the app
USER node
WORKDIR /app/rab
COPY --from=base --chown=node:node /app/rab /app/rab
CMD [ "node", "dist/index.js" ]