Skip to content

Commit

Permalink
[feature] docker (#33)
Browse files Browse the repository at this point in the history
- Use node 20 "slim"
- install pnpm and pm2 using npm
  • Loading branch information
ponsfrilus committed Jan 27, 2024
1 parent 55d270b commit e74fe0d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
.git/
.github/
.vscode/
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# https://expressjs.com/en/advanced/best-practice-performance.html
# https://javascript.plainenglish.io/build-a-production-ready-node-express-api-with-docker-9a45443427a0
# https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/

# docker build -t epflsi/startpage .
# docker run -it epflsi/startpage bash
# docker run -e PORT=1337 -p 3000:1337 epflsi/startpage -d

FROM node:20-slim

LABEL author="EPFL ISAS-FSD"
LABEL version="1.0"
LABEL project="epfl-startpage"

# RUN apt-get -qq update && apt-get -qq -y --no-install-recommends install curl
# RUN apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
RUN npm install -g pnpm pm2

RUN mkdir -p /home/node/app/src
WORKDIR /home/node/app

COPY package*.json ./
RUN pnpm i --only=production
COPY ./src ./src

# Set internal port
ENV PORT=1337
# Open desired port
EXPOSE 3000

# Let's be sure to use the user "node"
USER node

# It's a production Docker
ENV NODE_ENV=production

# Use pm2 to run the application
ENTRYPOINT ["pm2-runtime", "./src/server.js"]
5 changes: 3 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ app.get('/catalog', function (req, res) {
res.render('pages/catalog', { data, version });
});

app.listen(1337);
console.log('Server listening on port 1337');
const port = process.env.PORT || 1337;
app.listen(port);
console.log(`Server listening on port ${port}`);

0 comments on commit e74fe0d

Please sign in to comment.