From 721a32e21392b644319829c1e959cd5afb22f12f Mon Sep 17 00:00:00 2001 From: Viachaslau Date: Wed, 4 Sep 2024 12:04:34 +0400 Subject: [PATCH] chore: add Dockerfile for quick setup (#83) --- .github/workflows/auto-build.yml | 3 +++ Dockerfile | 39 ++++++++++++++++++++++++++++++++ README.md | 6 +++++ 3 files changed, 48 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/auto-build.yml b/.github/workflows/auto-build.yml index 872a9cf..3064031 100644 --- a/.github/workflows/auto-build.yml +++ b/.github/workflows/auto-build.yml @@ -45,3 +45,6 @@ jobs: - name: Run e2e tests run: npm run test:e2e + + - name: Build Docker image + run: cp .env.example .env && docker build -t sectester-js-demo . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..74b7b2f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +################### +# BUILDER +################### + +FROM node:18-alpine AS build + +WORKDIR /usr/src/app + +# Copy and build NestJS server project +COPY --chown=node:node package*.json ./ +COPY --chown=node:node tsconfig.build.json ./ +COPY --chown=node:node tsconfig.json ./ +COPY --chown=node:node nest-cli.json ./ +COPY --chown=node:node .env ./ +COPY --chown=node:node src ./src + +ENV NPM_CONFIG_LOGLEVEL=error +RUN npm ci --no-audit +RUN npm run build +RUN npm run migration:up +RUN npm prune --production + +USER node + +################### +# PRODUCTION +################### + +FROM node:18-alpine AS production + +WORKDIR /usr/src/app + +COPY --chown=node:node .env ./ +COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules +COPY --chown=node:node --from=build /usr/src/app/package*.json ./ +COPY --chown=node:node --from=build /usr/src/app/test.db ./ +COPY --chown=node:node --from=build /usr/src/app/dist ./dist + +CMD ["npm", "run", "start:prod"] diff --git a/README.md b/README.md index 7005923..0f37653 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,12 @@ Finally, perform this command in terminal to run the application: $ npm start ``` +_Note_: Alternatively, you can quickly run the SecTester SDK Demo app using Docker: + +```bash +docker build -t sectester-js-demo-image . && docker run --name sectester-js-demo -p 3000:3000 -d sectester-js-demo-image +``` + While having the application running, open a browser and type `http://localhost:3000/api`, and hit enter. You should see the Swagger UI page for that application that allows you to test the RESTFul CRUD API, like in the following screenshot: