-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIMS-390: Dockerize Express API (#1978)
- Loading branch information
1 parent
f4fb1fc
commit 1eae294
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
coverage/ | ||
dist/ | ||
node_modules/ | ||
.dockerignore | ||
.gitignore | ||
*Dockerfile* | ||
package-lock.json | ||
README.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
############################################# | ||
# Base # | ||
############################################# | ||
# Use an official Node.js runtime as a base image | ||
FROM node:18.17.1-bullseye-slim as base | ||
|
||
# Set the working directory in the container | ||
WORKDIR /express-api | ||
|
||
ENV NODE_ENV=development | ||
ENV CONTAINERIZED=true | ||
|
||
# Copy files, excluding those in .dockerignore | ||
COPY . . | ||
|
||
# Install TypeScript. Needed for build process. | ||
RUN npm i -D typescript | ||
|
||
# Compile to JavaScript build | ||
RUN npm run build | ||
|
||
############################################# | ||
# Prod Build # | ||
############################################# | ||
FROM node:18.17.1-bullseye-slim as Prod | ||
|
||
# Set the working directory to /express-api | ||
WORKDIR /express-api | ||
|
||
ENV NODE_ENV=production | ||
ENV CONTAINERIZED=true | ||
|
||
# Install packages. Needed even for compiled build. | ||
COPY package.json . | ||
RUN npm i | ||
|
||
# Add curl for health check | ||
RUN apt-get update | ||
RUN apt-get install -y curl | ||
|
||
# Copy compiled build from base | ||
COPY --from=base /express-api/dist . | ||
|
||
CMD [ "node", "server.js" ] | ||
|