generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Backend working with nodemon * Backend w/o nodemon * Fix backend probes * Add terrible health check * Roll health check into main routing * Caddy * Shuffle dependencies * Troubleshoot backend test fail
- Loading branch information
1 parent
b314ad5
commit ebd57ea
Showing
8 changed files
with
404 additions
and
52 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 |
---|---|---|
@@ -1,17 +1,26 @@ | ||
# Build | ||
FROM node:alpine AS build | ||
# Build static files | ||
# Node Bullseye has npm | ||
FROM node:20.7.0-bullseye-slim AS build | ||
ENV NODE_ENV production | ||
|
||
# Copy and build | ||
WORKDIR /app | ||
COPY . . | ||
RUN apk add --no-cache python3 g++ make | ||
RUN npm install -g nodemon # Install nodemon globally | ||
RUN npm install | ||
RUN npm i --ignore-scripts --no-update-notifer --omit=dev | ||
|
||
|
||
# User and startup | ||
# Deploy container | ||
# Distroless has node, but not npm | ||
FROM gcr.io/distroless/nodejs20-debian11:nonroot AS deploy | ||
ENV NODE_ENV production | ||
|
||
# Copy over app | ||
WORKDIR /app | ||
COPY --from=build /app ./ | ||
|
||
# Ports, health check and non-root user | ||
EXPOSE 5000 | ||
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:5000 | ||
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:5000 || exit 1 | ||
|
||
#CMD | ||
CMD ["npm", "start"] | ||
# Start up command with 50MB of heap size, each application needs to determine what is the best value. DONT use default as it is 4GB. | ||
CMD ["--max-old-space-size=50", "/app/index"] |
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
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,17 @@ | ||
const express = require("express"); | ||
const router = express.Router({}); | ||
router.get('/', async (_req, res, _next) => { | ||
const check = { | ||
uptime: process.uptime(), | ||
message: 'OK', | ||
timestamp: Date.now() | ||
}; | ||
try { | ||
res.send(check); | ||
} catch (error) { | ||
check.message = error; | ||
res.status(503).send(); | ||
} | ||
}); | ||
// export router with all routes included | ||
module.exports = router; |
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 |
---|---|---|
@@ -1,39 +1,28 @@ | ||
### Use this section while builds are broken | ||
## Use this section once builds are fixed | ||
|
||
FROM node:20-bullseye | ||
FROM node:20.7.0-bullseye-slim AS build | ||
|
||
# Build static files | ||
WORKDIR /app | ||
COPY . . | ||
RUN npm ci | ||
CMD ["npm", "run", "start"] | ||
|
||
RUN npm ci --ignore-scripts && \ | ||
npm run build && \ | ||
rm -rf node_modules | ||
|
||
### Use this section once builds are fixed | ||
# Caddy | ||
FROM caddy:2.7.4-alpine | ||
ENV LOG_LEVEL=info | ||
|
||
# FROM node:20-slim AS build | ||
# Copy static files and config | ||
COPY --from=build /app/build/ /srv | ||
COPY Caddyfile /etc/caddy/Caddyfile | ||
|
||
# # Build static files | ||
# WORKDIR /app | ||
# COPY . . | ||
# CA certs and Caddy format | ||
RUN apk add --no-cache ca-certificates && \ | ||
caddy fmt --overwrite /etc/caddy/Caddyfile | ||
|
||
# RUN npm ci --ignore-scripts && \ | ||
# npm run build && \ | ||
# rm -rf node_modules | ||
|
||
# # Caddy | ||
# FROM caddy:2.7.4-alpine | ||
# ENV LOG_LEVEL=info | ||
|
||
# # Copy static files and config | ||
# COPY --from=build /app/build/ /srv | ||
# COPY Caddyfile /etc/caddy/Caddyfile | ||
|
||
# # CA certs and Caddy format | ||
# RUN apk add --no-cache ca-certificates && \ | ||
# caddy fmt --overwrite /etc/caddy/Caddyfile | ||
|
||
# # User, port and healthcheck | ||
# USER 1001 | ||
# EXPOSE 3000 3001 | ||
# HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:3001/health | ||
# User, port and healthcheck | ||
USER 1001 | ||
EXPOSE 3000 3001 | ||
HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/:3001/health |
Oops, something went wrong.