Compare commits
9 Commits
deploy-on-
...
complete-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0023bf9bde | ||
|
|
b52b845526 | ||
|
|
3559bee477 | ||
|
|
86b41c173d | ||
|
|
ec07045f5b | ||
|
|
a9ad429d59 | ||
|
|
69c20e807e | ||
|
|
1c35a7f6c3 | ||
|
|
c22ccead98 |
51
Jenkinsfile
vendored
51
Jenkinsfile
vendored
@@ -2,11 +2,33 @@
|
|||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
tools {
|
||||||
|
maven 'Maven'
|
||||||
|
}
|
||||||
|
environment {
|
||||||
|
ECR_REPO_URL = '664574038682.dkr.ecr.eu-west-3.amazonaws.com'
|
||||||
|
IMAGE_REPO = "${ECR_REPO_URL}/java-maven-app"
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
|
stage('increment version') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
echo 'incrementing app version...'
|
||||||
|
sh 'mvn build-helper:parse-version versions:set \
|
||||||
|
-DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.minorVersion}.\\\${parsedVersion.nextIncrementalVersion} \
|
||||||
|
versions:commit'
|
||||||
|
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
|
||||||
|
def version = matcher[0][1]
|
||||||
|
env.IMAGE_NAME = "$version-$BUILD_NUMBER"
|
||||||
|
echo "############ ${IMAGE_REPO}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
stage('build app') {
|
stage('build app') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "building the application..."
|
echo "building the application..."
|
||||||
|
sh 'mvn clean package'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,18 +36,39 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "building the docker image..."
|
echo "building the docker image..."
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'ecr-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||||
|
sh "docker build -t ${IMAGE_REPO}:${IMAGE_NAME} ."
|
||||||
|
sh "echo $PASS | docker login -u $USER --password-stdin ${ECR_REPO_URL}"
|
||||||
|
sh "docker push ${IMAGE_REPO}:${IMAGE_NAME}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('deploy') {
|
stage('deploy') {
|
||||||
environment {
|
environment {
|
||||||
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
||||||
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
||||||
|
APP_NAME = 'java-maven-app'
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo 'deploying docker image...'
|
echo 'deploying docker image...'
|
||||||
sh 'kubectl create deployment nginx-deployment --image=nginx'
|
sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -'
|
||||||
|
sh 'envsubst < kubernetes/service.yaml | kubectl apply -f -'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('commit version update') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
withCredentials([usernamePassword(credentialsId: 'gitlab-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||||
|
sh 'git config user.email "jenkins@example.com"'
|
||||||
|
sh 'git config user.name "Jenkins"'
|
||||||
|
sh "git remote set-url origin https://${USER}:${PASS}@gitlab.com/nanuchi/java-maven-app.git"
|
||||||
|
sh 'git add .'
|
||||||
|
sh 'git commit -m "ci: version bump"'
|
||||||
|
sh 'git push origin HEAD:jenkins-jobs'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
kubernetes/deployment.yaml
Normal file
24
kubernetes/deployment.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: $APP_NAME
|
||||||
|
labels:
|
||||||
|
app: $APP_NAME
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: $APP_NAME
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: $APP_NAME
|
||||||
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: my-registry-key
|
||||||
|
containers:
|
||||||
|
- name: $APP_NAME
|
||||||
|
image: $IMAGE_REPO:$IMAGE_NAME
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
11
kubernetes/service.yaml
Normal file
11
kubernetes/service.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: $APP_NAME
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: $APP_NAME
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 8080
|
||||||
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>java-maven-app</artifactId>
|
<artifactId>java-maven-app</artifactId>
|
||||||
<version>1.1.4</version>
|
<version>1.1.5</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Sun Nov 29 08:01:35 UTC 2020
|
#Sat Dec 05 14:30:39 UTC 2020
|
||||||
version=1.1.4
|
version=1.1.5
|
||||||
groupId=com.example
|
groupId=com.example
|
||||||
artifactId=java-maven-app
|
artifactId=java-maven-app
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Test set: AppTest
|
Test set: AppTest
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.096 sec
|
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.126 sec
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<testsuite tests="1" failures="0" name="AppTest" time="0.01" errors="0" skipped="0">
|
<testsuite tests="1" failures="0" name="AppTest" time="0.007" errors="0" skipped="0">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
|
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
|
||||||
<property name="sun.boot.library.path" value="/usr/local/openjdk-8/jre/lib/amd64"/>
|
<property name="sun.boot.library.path" value="/usr/local/openjdk-8/jre/lib/amd64"/>
|
||||||
@@ -60,5 +60,5 @@
|
|||||||
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
|
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
|
||||||
<property name="sun.cpu.isalist" value=""/>
|
<property name="sun.cpu.isalist" value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
<testcase classname="AppTest" name="testApp" time="0.01"/>
|
<testcase classname="AppTest" name="testApp" time="0.007"/>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
Reference in New Issue
Block a user