Skip to content

Commit 8b870ea

Browse files
author
Chakshu Gautam
authored
Merge pull request #4 from sourabhsahu1/jenkins-setup
2 parents 5e6bd22 + ba82235 commit 8b870ea

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN mvn package -DskipTests=true
1212

1313
# Package stage
1414
FROM openjdk:11-jre-slim
15-
RUN apt update && apt upgrade
15+
RUN apt update && apt -y upgrade
1616
RUN apt install curl -y
1717
ENV HOME=/home/app
1818
WORKDIR $HOME

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ services:
1010
PASSWORD: "${PASSWORD}"
1111
SECURE_KEY: "${SECURE_KEY}"
1212
ports:
13-
- "8080:8080"
13+
- "8081:8080"
1414
healthcheck:
1515
test: ["CMD", "curl", "-f", "http://cdac:8080/api"]
1616
interval: 2s
1717
timeout: 5s
18-
retries: 20
18+
retries: 20

jenkins-build/Jenkinsfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
node() {
2+
properties([
3+
parameters([
4+
string(name: 'docker_repo', defaultValue: 'cdac-service', description: 'Docker Image Name'),
5+
string(name: 'docker_server', defaultValue: 'localhost:5000', description: 'Docker Registry URL'),
6+
7+
])
8+
])
9+
stage('Checkout') {
10+
cleanWs()
11+
checkout scm
12+
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
13+
env.commit_id = sh(script: 'echo ' + env.docker_repo + '_' + commit_hash + '_' + env.BRANCH_NAME, returnStdout: true).trim()
14+
echo "${env.commit_id}"
15+
}
16+
17+
stage('docker-build') {
18+
sh '''
19+
# docker build -f <location-of-docker-file> -t <tag-of-docker-image> <context-for-docker-image>
20+
docker build -f Dockerfile -t $docker_server/$docker_repo:$commit_id .
21+
'''
22+
}
23+
24+
stage('docker-push') {
25+
sh '''
26+
docker push $docker_server/$docker_repo:$commit_id
27+
'''
28+
}
29+
stage('ArchiveArtifacts') {
30+
sh("echo ${commit_id} > commit_id.txt")
31+
archiveArtifacts 'commit_id.txt'
32+
currentBuild.description = "${commit_id}"
33+
}
34+
}

0 commit comments

Comments
 (0)