Skip to content

Commit 78f155e

Browse files
committed
refactor: build base node app
1 parent c74930c commit 78f155e

4 files changed

Lines changed: 95 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ permissions:
2121

2222
jobs:
2323
release:
24-
uses: getdevopspro/github-actions/.github/workflows/promote.yml@v0.4.7
24+
uses: getdevopspro/github-actions/.github/workflows/promote.yml@v1.0.1
2525
# secrets:
2626
# checkout-token: ${{ secrets.CHECKOUT_TOKEN }}
2727
with:

Dockerfile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Set default base image
2+
ARG ARG_IMAGE_FROM=docker.io/node:22
3+
4+
# -----------------------------------------------------------------------------
5+
# Stage 1: Nodeapp build
6+
# -----------------------------------------------------------------------------
7+
FROM ${ARG_IMAGE_FROM} AS nodeapp-base
8+
9+
WORKDIR /home/node/app
10+
11+
# -----------------------------------------------------------------------------
12+
# Stage 2: Nodeapp build
13+
# -----------------------------------------------------------------------------
14+
FROM nodeapp-base AS nodeapp-build
15+
16+
COPY static /home/node/app/static
17+
COPY *.json *.ts *.js *.cjs /home/node/app/
18+
COPY src /home/node/app/src
19+
20+
RUN --mount=type=cache,target=/home/node/.npm,sharing=locked \
21+
npm ci --ignore-scripts && \
22+
npm run build && \
23+
npm prune --omit=dev
24+
25+
# -----------------------------------------------------------------------------
26+
# TARGET 1: Nodeapp dev image
27+
# -----------------------------------------------------------------------------
28+
FROM nodeapp-base AS nodeapp-dev
29+
30+
ARG NODE_ENV=development
31+
ARG NODE_UID=1000
32+
ENV NODE_UID=$NODE_UID
33+
ENV NODE_ENV=$NODE_ENV
34+
ENV NPM_CONFIG_PREFIX=/home/node/app/.npm
35+
ENV NPM_CONFIG_CACHE=/home/node/app/.npm
36+
37+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
38+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
39+
set -ex && \
40+
apt-get update && \
41+
apt-get install --no-install-recommends -y \
42+
# Alphabetical order per best practice
43+
# (To make finding packages in lists easier and to help avoid duplicates)
44+
git \
45+
curl \
46+
make \
47+
tar \
48+
unzip \
49+
zip
50+
51+
RUN usermod -u $NODE_UID node && \
52+
groupmod -g $NODE_UID node && \
53+
usermod -d /home/node -m node && \
54+
chown -R $NODE_UID:$NODE_UID /home/node
55+
56+
USER $NODE_UID
57+
58+
CMD ["/bin/bash"]
59+
60+
# -----------------------------------------------------------------------------
61+
# TARGET 2: Nodeapp image
62+
# -----------------------------------------------------------------------------
63+
FROM nodeapp-base AS nodeapp
64+
65+
ARG ENV=production
66+
ARG PORT=3000
67+
ENV NODE_ENV=$ENV
68+
69+
COPY --from=nodeapp-build --chown=node:root /home/node/app/package.json .
70+
COPY --from=nodeapp-build --chown=node:root /home/node/app/node_modules node_modules/
71+
COPY --from=nodeapp-build --chown=node:root /home/node/app/build build/
72+
73+
EXPOSE $PORT
74+
75+
CMD [ "node", "-r", "dotenv/config", "build" ]
76+
77+
# -----------------------------------------------------------------------------
78+
# TARGET 3: Final image
79+
# -----------------------------------------------------------------------------
80+
FROM nodeapp AS final

docker-bake.hcl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// docker-bake.hcl
2+
target "docker-metadata-action" {}
3+
4+
target "build" {
5+
inherits = ["docker-metadata-action"]
6+
context = "./"
7+
dockerfile = "Dockerfile"
8+
platforms = [
9+
"linux/amd64",
10+
"linux/arm64",
11+
]
12+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "test",
3-
"version": "0.0.15",
2+
"name": "github-actions-test",
3+
"version": "0.0.15"
44
}

0 commit comments

Comments
 (0)