Skip to content

Commit

Permalink
PIMS-390: Dockerize Express API (#1978)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharala-Perumal authored Dec 13, 2023
1 parent f4fb1fc commit 1eae294
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ services:
networks:
- pims

####################### Express API #######################
express-api:
restart: 'no'
container_name: express-api
build:
context: express-api
target: Prod
env_file:
- .env
ports:
- ${API_HTTP_PORT:-5000}:5000
depends_on:
- postgres
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:5000/api/v2/health']
interval: 300s
timeout: 10s
retries: 3
networks:
- pims

####################### Frontend #######################
frontend:
profiles: ['prod']
Expand Down
9 changes: 9 additions & 0 deletions express-api/.dockerignore
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

45 changes: 45 additions & 0 deletions express-api/Dockerfile
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" ]

0 comments on commit 1eae294

Please sign in to comment.