Compare commits
5 Commits
feature/k8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92602e6c79 | ||
|
|
bcff7b9713 | ||
|
|
851ef30959 | ||
|
|
feda16a9a8 | ||
|
|
0c2ab7794d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.idea/*
|
||||
target
|
||||
@@ -1,8 +0,0 @@
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
COPY ./target/java-maven-app-*.jar /usr/app/
|
||||
WORKDIR /usr/app
|
||||
|
||||
CMD java -jar java-maven-app-*.jar
|
||||
61
Jenkinsfile
vendored
61
Jenkinsfile
vendored
@@ -1,71 +1,38 @@
|
||||
#!/usr/bin/env groovy
|
||||
def gv
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'Maven'
|
||||
}
|
||||
stages {
|
||||
stage('increment version') {
|
||||
stage("init") {
|
||||
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"
|
||||
gv = load "script.groovy"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('build app') {
|
||||
stage("build jar") {
|
||||
steps {
|
||||
script {
|
||||
echo "building the application..."
|
||||
sh 'mvn clean package'
|
||||
echo "building jar"
|
||||
//gv.buildJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('build image') {
|
||||
stage("build image") {
|
||||
steps {
|
||||
script {
|
||||
echo "building the docker image..."
|
||||
withCredentials([usernamePassword(credentialsId: 'docker-hub', 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}"
|
||||
}
|
||||
echo "building image"
|
||||
//gv.buildImage()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('deploy') {
|
||||
stage("deploy") {
|
||||
steps {
|
||||
script {
|
||||
withKubeConfig([credentialsId: 'k8s-credentials', serverUrl: 'https://7293fae4-4c9d-4629-bc82-262d0a2b8e3c.eu-central-2.linodelke.net']) {
|
||||
withCredentials([usernamePassword(credentialsId: 'docker-hub', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||
sh "kubectl create secret docker-registry my-registry-key --docker-server=docker.io --docker-username=$USER --docker-password=$PASS"
|
||||
}
|
||||
sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -'
|
||||
}
|
||||
echo "deploying"
|
||||
//gv.deployApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('commit version update') {
|
||||
steps {
|
||||
script {
|
||||
withCredentials([usernamePassword(credentialsId: 'gitlab-credentials', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
||||
// git config here for the first time run
|
||||
sh 'git config --global user.email "jenkins@example.com"'
|
||||
sh 'git config --global 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'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: java-maven-app
|
||||
labels:
|
||||
app: java-maven-app
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: java-maven-app
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: java-maven-app
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: my-registry-key
|
||||
containers:
|
||||
- name: java-maven-app
|
||||
image: nanajanashia/demo-app:$IMAGE_NAME
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: java-maven-app
|
||||
spec:
|
||||
selector:
|
||||
app: java-maven-app
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 8080
|
||||
11
pom.xml
11
pom.xml
@@ -22,6 +22,17 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- to handle any Java version mismatch, add the following configuration for maven-compiler-plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
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>
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user