Compare commits
2 Commits
feature/k8
...
feature/de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c53fe05e1 | ||
|
|
fab255d0da |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.idea/*
|
.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
|
|
||||||
71
Jenkinsfile
vendored
71
Jenkinsfile
vendored
@@ -1,71 +0,0 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
tools {
|
|
||||||
maven 'Maven'
|
|
||||||
}
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('build app') {
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn clean package'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 -'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
|
||||||
31
pom.xml
31
pom.xml
@@ -6,25 +6,34 @@
|
|||||||
|
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>java-maven-app</artifactId>
|
<artifactId>java-maven-app</artifactId>
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
<version>2.3.5.RELEASE</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>nexus-snapshots</id>
|
||||||
|
<url>http://167.99.248.163:8081/repository/maven-snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
def buildJar() {
|
|
||||||
echo "building the application..."
|
|
||||||
sh 'mvn package'
|
|
||||||
}
|
|
||||||
|
|
||||||
def buildImage() {
|
|
||||||
echo "building the docker image..."
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'docker-hub-repo', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
|
|
||||||
sh 'docker build -t nanajanashia/demo-app:jma-2.0 .'
|
|
||||||
sh "echo $PASS | docker login -u $USER --password-stdin"
|
|
||||||
sh 'docker push nanajanashia/demo-app:jma-2.0'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def deployApp() {
|
|
||||||
echo 'deploying the application...'
|
|
||||||
}
|
|
||||||
|
|
||||||
return this
|
|
||||||
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