Skip to content

Commit 090aa64

Browse files
feat(ci): add runtime target to frontend Dockerfile
Also configures docker-compose to unambiguously use this Dockerfile and gives it an explicit target that lets the Dockerfile be the authoritative source of what base image to use but skips doing production builds in dev
1 parent 4e59856 commit 090aa64

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
services:
33
app:
4-
image: node:18-slim
54
build:
65
context: ./src/app
76
dockerfile: Dockerfile
7+
target: environment
88
working_dir: /usr/local/src
99
environment:
1010
- PORT=4321

src/app/Dockerfile

+28-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
FROM node:18-slim
2-
ARG HOME=usr/local/src/
3-
WORKDIR $HOME
1+
## Target: environment
2+
#
3+
# This initially-empty target provides an environment for docker-compose
4+
# to start from the same base as the production builder environment. Common
5+
# dependencies could be added here
6+
#
7+
FROM node:18-slim as environment
48

5-
COPY entrypoint.sh /entrypoint.sh
6-
RUN chmod +x /entrypoint.sh
79

8-
ADD . .
9-
ENTRYPOINT [ "/entrypoint.sh" ]
10-
CMD ["npm", "run", "dev", "--host"]
11-
EXPOSE 4321
10+
## Target: builder
11+
#
12+
# This target builds /src/dist with layers optimized for caching dependencies
13+
#
14+
FROM environment as builder
15+
WORKDIR /src
16+
17+
COPY package*.json ./
18+
RUN npm ci
19+
20+
COPY * ./
21+
RUN npm run build
22+
23+
24+
## Target: runtime
25+
#
26+
# This target provides an nginx web server wrapped around the static
27+
# website build from the builder target
28+
#
29+
FROM nginx:alpine as runtime
30+
COPY --from=builder /src/dist /usr/share/nginx/html

0 commit comments

Comments
 (0)