Commit 20f2a3c7 authored by Imran Hussain's avatar Imran Hussain

Working Node.js to Docker Image example

parents
node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
.gitlab-ci.yml
\ No newline at end of file
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# gatsby files
.cache/
public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
\ No newline at end of file
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
stages:
- build
Build and Push master:
stage: build
only:
- master
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"gitlab-ci-token\",\"password\":\"$CI_JOB_TOKEN\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --destination $CI_REGISTRY_IMAGE:latest
Build and Push tag:
stage: build
only:
- tags
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"gitlab-ci-token\",\"password\":\"$CI_JOB_TOKEN\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
#What image should our image be based off of?
FROM node:lts
RUN mkdir -p /opt/nodeapp/node_modules && chown -R node:node /opt/nodeapp
WORKDIR /opt/nodeapp
COPY package.json ./
COPY npm-shrinkwrap.json ./
USER node
RUN npm ci --only=production
COPY --chown=node:node . .
#Chnage this if you want a different file to be run first instead
CMD [ "node", "index.js" ]
\ No newline at end of file
# NodeJS Docker Example
This repo is an example of how to create a Docker Image out of a NodeJS app.
You can literally just fork and rename the repo.
## What Images are Built?
By default this is what is built.
* latest - Every time you push to master a image is built with the image tag being the git commit full hash. This same image is also tagged as `latest`
* tag - Every time you create a new git tag, a new image is built with that same tag.
## Files in this repo
| File | Explanation |
| --- | --- |
| .dockerignore | List of files not to be copied into the docker image. |
| .gitignore | List of files to not be included in the git repo |
| .gitlab-ci.yml | Settings file for Gitlab CI that tells it what to do and how. In this case build and publish a docker image. |
| Dockerfile | File used by Docker (Google Kaniko in this case) to build a docker image. Change the initial NodeJS run file in here. |
| README.md | What you are reading right now :) |
| package.json | Example NodeJS package.json file |
| npm-shrinkwrap.json | Example NodeJS npm-shrinkwrap.json file |
| index.js | Example NodeJS code file |
\ No newline at end of file
console.log('Hello, world!');
{
"name": "nodejs-docker-example",
"version": "1.0.0",
"lockfileVersion": 1
}
{
"name": "nodejs-docker-example",
"description": "Test NodeJS app for Docker example",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://projects.sucs.org/imranh/nodejs-docker-example"
},
"keywords": [],
"author": "Imran Hussain <imranh@sucs.org>",
"license": "ISC",
"bugs": {
"url": "https://projects.sucs.org/imranh/nodejs-docker-example/issues"
},
"homepage": "https://projects.sucs.org/imranh/nodejs-docker-example"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment