mirror of
				https://github.com/goldbergyoni/nodebestpractices.git
				synced 2025-10-31 09:38:39 +08:00 
			
		
		
		
	Add an example project with dockerfile - 1st draft
This commit is contained in:
		
							
								
								
									
										13
									
								
								sections/examples/dockerfile/.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								sections/examples/dockerfile/.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| node_modules/ | ||||
| .git | ||||
| README.md | ||||
| LICENSE | ||||
| .vscode | ||||
| .idea | ||||
| npm-debug.log | ||||
| coverage | ||||
| .env | ||||
| .editorconfig | ||||
| .aws | ||||
| dist | ||||
| .npmrc | ||||
							
								
								
									
										0
									
								
								sections/examples/dockerfile/.npmrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								sections/examples/dockerfile/.npmrc
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										31
									
								
								sections/examples/dockerfile/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								sections/examples/dockerfile/Dockerfile
									
									
									
									
									
										Normal 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" ] | ||||
							
								
								
									
										28
									
								
								sections/examples/dockerfile/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								sections/examples/dockerfile/package.json
									
									
									
									
									
										Normal 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" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										10
									
								
								sections/examples/dockerfile/src/app.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								sections/examples/dockerfile/src/app.ts
									
									
									
									
									
										Normal 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'); | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user
	 Kevyn Bruyere
					Kevyn Bruyere