Skip to content

Commit

Permalink
feat: dockerize express server (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored Jan 2, 2025
1 parent e42890e commit f710722
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
node_modules
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20 AS base

FROM base AS builder
WORKDIR /code
COPY . .
RUN cd server && npm ci && npm run build

FROM base AS final
WORKDIR /app
COPY --from=builder /code/server/*.js ./
COPY --from=builder /code/server/*.json ./
COPY --from=builder /code/server/controllers ./controllers/
COPY --from=builder /code/server/routes ./routes/
COPY --from=builder /code/server/node_modules ./node_modules/
COPY --chmod=555 docker-entrypoint.sh .
ENTRYPOINT ["/app/docker-entrypoint.sh"]
12 changes: 12 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

__app=$(cd $(dirname ${BASH_SOURCE[0]}); pwd -P)

# Check for arguments
# No arguments passed or first argument begins with dash
if [[ ${#} -eq 0 ]] || [[ ${1#-} != ${1} ]]; then
cd ${__app}
set -- npm run start "${@}"
fi

exec "${@}"
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"start": "node dist/server.js",
"start": "node server.js",
"dev": "nodemon --exec ts-node server.js"
},
"keywords": [],
Expand Down

0 comments on commit f710722

Please sign in to comment.