Skip to content

Commit 96d9831

Browse files
authored
Merge pull request #63 from htres736/develop
Added Dockerfiles and Jenkinsfile for devops automation
2 parents 6e6d52b + 647b759 commit 96d9831

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.dockerignore
2+
**/node_modules
3+
npm-debug.log
4+
Dockerfile
5+
.git
6+
.gitignore
7+
**/*.crt
8+
**/*.key
9+
**/*.pem

Dockerfile-dev

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:12.16.1@sha256:8fa78144d1864f2b08ca4a2d28e9cc32930d78850630652ff338793291a91f0c
2+
RUN apt update -y && apt upgrade -y && apt install -y curl wget bash iputils-ping net-tools dnsutils zip unzip python3 && ln -sf python3 /usr/bin/python
3+
4+
5+
6+
WORKDIR /web
7+
# use changes to package.json to force Docker not to use the cache
8+
# when we change our application's nodejs dependencies:
9+
COPY package*.json ./
10+
11+
# install dev dependencies for building
12+
RUN npm i
13+
14+
# copy the code into the image for building
15+
COPY . ./
16+
17+
# compile typescript
18+
RUN tsc
19+
20+
EXPOSE 1342
21+
CMD ["node", "/web/dist/bin/main.js"]
22+
#CMD ["tail", "-f", "/dev/null"]

Dockerfile-prod

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM node:12.16.1-alpine@sha256:5e1a147114839599442784549d04b45821c7b178f7fc09d4ab9853543ae1388e AS appbuild
2+
RUN apk update
3+
RUN apk add --no-cache build-base python3 && ln -sf python3 /usr/bin/python
4+
5+
6+
7+
WORKDIR /build
8+
# use changes to package.json to force Docker not to use the cache
9+
# when we change our application's nodejs dependencies:
10+
COPY package*.json ./
11+
12+
# install dev dependencies for building
13+
RUN npm i
14+
15+
# copy the code into the image for building
16+
COPY . ./
17+
18+
# compile typescript
19+
RUN tsc
20+
21+
# make a 2 part Dockerfile in order reduce overall image size of the final prod image
22+
FROM node:12.16.1-alpine@sha256:5e1a147114839599442784549d04b45821c7b178f7fc09d4ab9853543ae1388e
23+
RUN apk update && apk upgrade && apk add curl --no-cache && apk add --no-cache build-base python3 && ln -sf python3 /usr/bin/python
24+
25+
# create dirs in the container & set permissions so node user can access them
26+
RUN mkdir -p /web && chown -R node:node /web
27+
USER node
28+
WORKDIR /web
29+
30+
# copy the package.jsons to prepare for install
31+
COPY --chown=node:node package*.json ./
32+
33+
# install dependencies only for prod
34+
RUN npm i --only=production
35+
36+
# copy the built code from the build image into the prod image
37+
COPY --from=appbuild --chown=node:node /build /web/
38+
39+
EXPOSE 1342
40+
CMD ["node", "/web/dist/bin/main.js"]
41+
#CMD ["tail", "-f", "/dev/null"]

Jenkinsfile-dev

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
pipeline {
2+
environment {
3+
registry = "mathematicalthinking/mt-sso"
4+
registryCredential = 'mt-docker-hub-credentials'
5+
dockerImage = ''
6+
}
7+
agent {
8+
docker { image '21pstem/dindbuildagent:latest' }
9+
}
10+
stages {
11+
stage('Build Docker Image') {
12+
steps {
13+
script {
14+
//checkout scm
15+
sh ls -la .
16+
dockerImage = docker.build(registry + ":$BUILD_NUMBER", "-f Dockerfile-dev .")
17+
}
18+
}
19+
}
20+
stage('Push Docker Image') {
21+
steps {
22+
script {
23+
docker.withRegistry( '', registryCredential ) {
24+
dockerImage.push()
25+
//dockerImage.push('latest')
26+
}
27+
}
28+
}
29+
}
30+
stage('Deploy to test env') {
31+
steps {
32+
script {
33+
// docker swarm deploy cmds go here
34+
}
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)