Skip to content

Commit b5ec3fc

Browse files
committed
Add Docker support
1 parent 061ab3a commit b5ec3fc

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Folders to ignore when copying in the Dockerfile in the builder stage
2+
node_modules
3+
dist
4+
coverage

.github/workflows/node.js.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
test:
10+
test-build:
1111
runs-on: ubuntu-latest
1212

1313
steps:
@@ -27,7 +27,10 @@ jobs:
2727
- name: Run test with coverage
2828
run: npm run test:cov
2929

30-
build:
30+
- name: Run Build
31+
run: npm run build
32+
33+
docker:
3134
runs-on: ubuntu-latest
3235

3336
steps:
@@ -38,8 +41,5 @@ jobs:
3841
node-version: '18'
3942
cache: 'npm'
4043

41-
- name: Install Dependencies
42-
run: npm ci
43-
44-
- name: Run Build
45-
run: npm run build
44+
- name: Build docker image
45+
run: docker build -t typescript-project .

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:18-alpine AS builder
2+
3+
WORKDIR /app
4+
COPY . .
5+
RUN npm install
6+
RUN npm run build
7+
8+
FROM node:18-alpine AS production
9+
10+
ARG NODE_ENV=production
11+
RUN addgroup -S docker && adduser -S user -G docker
12+
13+
WORKDIR /app
14+
15+
COPY --from=builder --chown=user:docker /app/package*.json ./
16+
COPY --from=builder --chown=user:docker /app/dist ./dist
17+
RUN npm ci --omit=dev && npm cache clean --force
18+
19+
USER user
20+
21+
ENTRYPOINT ["node"]
22+
CMD ["dist/index.js"]

0 commit comments

Comments
 (0)