Compare commits
9 Commits
deploy-to-
...
complete-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0023bf9bde | ||
|
|
b52b845526 | ||
|
|
3559bee477 | ||
|
|
86b41c173d | ||
|
|
ec07045f5b | ||
|
|
a9ad429d59 | ||
|
|
69c20e807e | ||
|
|
1c35a7f6c3 | ||
|
|
c22ccead98 |
24
Jenkinsfile
vendored
24
Jenkinsfile
vendored
@@ -5,6 +5,10 @@ pipeline {
|
||||
tools {
|
||||
maven 'Maven'
|
||||
}
|
||||
environment {
|
||||
ECR_REPO_URL = '664574038682.dkr.ecr.eu-west-3.amazonaws.com'
|
||||
IMAGE_REPO = "${ECR_REPO_URL}/java-maven-app"
|
||||
}
|
||||
stages {
|
||||
stage('increment version') {
|
||||
steps {
|
||||
@@ -16,6 +20,7 @@ pipeline {
|
||||
def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'
|
||||
def version = matcher[0][1]
|
||||
env.IMAGE_NAME = "$version-$BUILD_NUMBER"
|
||||
echo "############ ${IMAGE_REPO}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,18 +36,25 @@ pipeline {
|
||||
steps {
|
||||
script {
|
||||
echo "building the docker image..."
|
||||
withCredentials([usernamePassword(credentialsId: 'docker-hub-repo', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||
sh "docker build -t nanajanashia/demo-app:${IMAGE_NAME} ."
|
||||
sh "echo $PASS | docker login -u $USER --password-stdin"
|
||||
sh "docker push nanajanashia/demo-app:${IMAGE_NAME}"
|
||||
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') {
|
||||
environment {
|
||||
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
|
||||
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
|
||||
APP_NAME = 'java-maven-app'
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
echo 'deploying docker image to EC2...'
|
||||
echo 'deploying docker image...'
|
||||
sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -'
|
||||
sh 'envsubst < kubernetes/service.yaml | kubectl apply -f -'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +62,8 @@ pipeline {
|
||||
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"'
|
||||
|
||||
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>
|
||||
<artifactId>java-maven-app</artifactId>
|
||||
<version>1.1.4</version>
|
||||
<version>1.1.5</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
11
src/main/resources/static/index.html
Normal file
11
src/main/resources/static/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>MyApp</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Java Maven Application</h1>
|
||||
<!-- add image here <img src="" width="" /> -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sun Nov 29 08:01:35 UTC 2020
|
||||
version=1.1.4
|
||||
#Sat Dec 05 14:30:39 UTC 2020
|
||||
version=1.1.5
|
||||
groupId=com.example
|
||||
artifactId=java-maven-app
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-------------------------------------------------------------------------------
|
||||
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" ?>
|
||||
<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>
|
||||
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
|
||||
<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.cpu.isalist" value=""/>
|
||||
</properties>
|
||||
<testcase classname="AppTest" name="testApp" time="0.01"/>
|
||||
<testcase classname="AppTest" name="testApp" time="0.007"/>
|
||||
</testsuite>
|
||||
Reference in New Issue
Block a user