Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VL-58] Dockerfile #21

Merged
merged 4 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.git/
.github/
.husky/
**/node_modules/
.adr-dir
.env.default
.eslintrc.json
.gitignore
.prettierrc
README.md
CODEOWNERS
LICENSE
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ARG NODE_VERSION=18.7.0
# Step 1 - Compile code
FROM node:${NODE_VERSION}-alpine as build

WORKDIR /app

COPY --chown=node:node . /app
RUN npm ci && npm run generate && npm run compile

# Step 2 - Prepare production image
FROM node:${NODE_VERSION}-alpine

RUN npm install -g pm2@5.2.0

RUN mkdir -p /app
RUN chown -Rh node:node /app

USER node
WORKDIR /app
COPY --chown=node:node --from=build /app/dist /app/package.json /app/package-lock.json /app/

ENV NODE_ENV=production
ENV LOG_LEVEL=info
ENV PORT=3000
ENV HOSTNAME=0.0.0.0

# Install just the production dependencies and avoid to execute the prepare script (which invoke husky, a dev dependency)
RUN npm install --ignore-scripts && npm cache clean --force

EXPOSE 3000
CMD ["pm2-runtime", "/app/main.js"]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ npm run generate
npm run start
```

## Run with Docker
kin0992 marked this conversation as resolved.
Show resolved Hide resolved

The repository comes with a Dockerfile that you can use to run the application with Docker.
First, build the image:
kin0992 marked this conversation as resolved.
Show resolved Hide resolved

``` sh
docker build -t pnemulator .
```

Then, run the application:
kin0992 marked this conversation as resolved.
Show resolved Hide resolved

``` sh
docker run -p 3000:3000 pnemulator
```

### Example

``` sh
Expand Down