Compare commits
86 Commits
feature/k8
...
feature/je
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd21d95e93 | ||
|
|
9492a348d0 | ||
|
|
a87e8850de | ||
|
|
6123875bc8 | ||
|
|
1f54931484 | ||
|
|
18ecdca204 | ||
|
|
e1dbd4d042 | ||
|
|
36b85d75cc | ||
|
|
c120554c74 | ||
|
|
3e1d99e8d0 | ||
|
|
e71aab1655 | ||
|
|
762a6a9ffb | ||
|
|
e14b7b7012 | ||
|
|
106a7e447e | ||
|
|
b28d6ff9d9 | ||
|
|
4e33b70b24 | ||
|
|
d41bcec12b | ||
|
|
9dadc24128 | ||
|
|
12f88937ab | ||
|
|
8b1aa75d8e | ||
|
|
339109ec86 | ||
|
|
63f6c3d5bb | ||
|
|
ba9f0882ca | ||
|
|
0b043899f9 | ||
|
|
f31394abe3 | ||
|
|
e2633b0888 | ||
|
|
a1b5946b6d | ||
|
|
45817d153a | ||
|
|
0576e0033b | ||
|
|
44cf4ac38c | ||
|
|
04f35ad918 | ||
|
|
686259038b | ||
|
|
1978bd1fc9 | ||
|
|
b262ce98c8 | ||
|
|
24fdad6aaa | ||
|
|
e41eb6433d | ||
|
|
1ce128d916 | ||
|
|
2c6295012f | ||
|
|
48b35c0308 | ||
|
|
80ed88f4be | ||
|
|
f8698fee42 | ||
|
|
eea2109d66 | ||
|
|
a71dd16df8 | ||
|
|
8e3382a0ef | ||
|
|
1d4aac4b5a | ||
|
|
f65d9eb00e | ||
|
|
a026af6e2f | ||
|
|
02aef32659 | ||
|
|
e68743b02d | ||
|
|
ce28529588 | ||
|
|
a0deb05e4e | ||
|
|
126336f79e | ||
|
|
19eeb818ca | ||
|
|
ff51c37f0a | ||
|
|
948fbb8f12 | ||
|
|
679d67b80a | ||
|
|
661a008faa | ||
|
|
9cc6d90fe8 | ||
|
|
61821c6ef7 | ||
|
|
1fa470771d | ||
|
|
9c56ddc553 | ||
|
|
056eca7cf6 | ||
|
|
e637047b84 | ||
|
|
845783dbc6 | ||
|
|
cdacbeeec4 | ||
|
|
1228821c74 | ||
|
|
650570153a | ||
|
|
e5f3bc546b | ||
|
|
99d992ee76 | ||
|
|
273c10f041 | ||
|
|
e0be3b5f9d | ||
|
|
c4cba3ddc6 | ||
|
|
8fb1d04fa8 | ||
|
|
48aa2427b3 | ||
|
|
ed870a0c6b | ||
|
|
28932727d1 | ||
|
|
2ef267a3fb | ||
|
|
05f3e19201 | ||
|
|
5d8d48709e | ||
|
|
fa5460fa44 | ||
|
|
ae9b87113d | ||
|
|
86350ca4e1 | ||
|
|
51edfc3d66 | ||
|
|
c8da404d8b | ||
|
|
18a24797ed | ||
|
|
710e1151f8 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
.idea/*
|
||||
target
|
||||
@@ -2,7 +2,7 @@ FROM openjdk:8-jre-alpine
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
COPY ./target/java-maven-app-*.jar /usr/app/
|
||||
COPY ./target/java-maven-app-1.0-SNAPSHOT.jar /usr/app/
|
||||
WORKDIR /usr/app
|
||||
|
||||
CMD java -jar java-maven-app-*.jar
|
||||
ENTRYPOINT ["java", "-jar", "java-maven-app-1.0-SNAPSHOT.jar"]
|
||||
|
||||
71
Jenkinsfile
vendored
71
Jenkinsfile
vendored
@@ -1,69 +1,52 @@
|
||||
#!/usr/bin/env groovy
|
||||
|
||||
library identifier: 'jenkins-shared-library@master', retriever: modernSCM(
|
||||
[$class: 'GitSCMSource',
|
||||
remote: 'https://gitlab.com/nanuchi/jenkins-shared-library.git',
|
||||
credentialsId: 'gitlab-credentials'
|
||||
]
|
||||
)
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'Maven'
|
||||
}
|
||||
environment {
|
||||
IMAGE_NAME = 'nanajanashia/demo-app:java-maven-2.0'
|
||||
}
|
||||
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'
|
||||
}
|
||||
script {
|
||||
echo 'building application jar...'
|
||||
buildJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
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 docker image...'
|
||||
buildImage(env.IMAGE_NAME)
|
||||
dockerLogin()
|
||||
dockerPush(env.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"'
|
||||
echo 'deploying docker image to EC2...'
|
||||
|
||||
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'
|
||||
}
|
||||
def shellCmd = "bash ./server-cmds.sh ${IMAGE_NAME}"
|
||||
def ec2Instance = "ec2-user@35.180.251.121"
|
||||
|
||||
sshagent(['ec2-server-key']) {
|
||||
sh "scp -o StrictHostKeyChecking=no server-cmds.sh ${ec2Instance}:/home/ec2-user"
|
||||
sh "scp -o StrictHostKeyChecking=no docker-compose.yaml ${ec2Instance}:/home/ec2-user"
|
||||
sh "ssh -o StrictHostKeyChecking=no ${ec2Instance} ${shellCmd}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
docker-compose.yaml
Normal file
12
docker-compose.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
version: '3.8'
|
||||
services:
|
||||
java-maven-app:
|
||||
image: ${IMAGE}
|
||||
ports:
|
||||
- 8080:8080
|
||||
postgres:
|
||||
image: postgres:13
|
||||
ports:
|
||||
- 5432:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=my-pwd
|
||||
@@ -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
|
||||
8
pom.xml
8
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>java-maven-app</artifactId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -24,7 +24,11 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<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
|
||||
5
server-cmds.sh
Normal file
5
server-cmds.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export IMAGE=$1
|
||||
docker-compose -f docker-compose.yaml up --detach
|
||||
echo "success"
|
||||
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>
|
||||
16
src/test/java/AppTest.java
Normal file
16
src/test/java/AppTest.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import com.example.Application;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void testApp() {
|
||||
Application myApp = new Application();
|
||||
|
||||
String result = myApp.getStatus();
|
||||
|
||||
assertEquals("OK", result);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user