Add an example project with dockerfile - 1st draft

This commit is contained in:
Kevyn Bruyere
2020-08-19 10:20:45 +02:00
parent 5062025381
commit b23fcf2c06
5 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,13 @@
node_modules/
.git
README.md
LICENSE
.vscode
.idea
npm-debug.log
coverage
.env
.editorconfig
.aws
dist
.npmrc

View File

View File

@ -0,0 +1,31 @@
FROM node:14.8.0-alpine AS build
# Copy dependency information and install all dependencies
COPY --chown=node:node package.json package-lock.json ./
RUN npm ci
# Copy source code (and all other relevant files)
COPY --chown=node:node src ./src
# Build code
RUN npm run build
# Run-time stage
FROM node:14.8.0-alpine
# Set non-root user and expose port 3000
USER node
EXPOSE 3000
WORKDIR /home/node/app
# Copy dependency information and build results from previous stage
COPY --chown=node:node --from=build package.json package-lock.json ./
COPY --chown=node:node --from=build node_modules ./node_modules
COPY --chown=node:node --from=build dist ./dist
# Clean dev packages
RUN npm prune --production
CMD [ "node", "dist/app.js" ]

View File

@ -0,0 +1,28 @@
{
"name": "node-app-with-docker",
"version": "1.0.0",
"description": "An example node app that uses docker to be built",
"main": "src/app.ts",
"scripts": {
"run": "dist/app.js",
"build": "tsc --outDir dist -m commonjs -t ES2020 src/app.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/goldbergyoni/nodebestpractices.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/goldbergyoni/nodebestpractices/issues"
},
"homepage": "https://github.com/goldbergyoni/nodebestpractices#readme",
"dependencies": {
"koa": "^2.13.0"
},
"devDependencies": {
"@types/koa": "^2.11.4",
"typescript": "^3.9.7"
}
}

View File

@ -0,0 +1,10 @@
import * as Koa from 'koa';
const app = new Koa();
app.use(async ctx => {
ctx.body = 'Hello World';
});
app.listen(3000, () => {
console.log('Navigate to http://localhost:3000');
});