26 Commits

Author SHA1 Message Date
Nana Janashia
d7e9360e2c fix 2020-11-08 17:28:39 +01:00
Nana Janashia
6b1d998791 add library def inside Jenkinsfile 2020-11-08 17:25:26 +01:00
Nana Janashia
922c8df4c6 add ind commands 2020-11-08 17:12:58 +01:00
Nana Janashia
946909a1b0 add param to dockerbuild 2020-11-08 16:41:07 +01:00
Nana Janashia
5aab8caed6 fix lib call 2020-11-08 16:30:28 +01:00
Nana Janashia
63a5e576a8 fix lib call 2020-11-08 16:27:28 +01:00
Nana Janashia
aa6f394e65 fix lib call 2020-11-08 16:20:19 +01:00
Nana Janashia
15a05dc886 Update Jenkinsfile 2020-11-08 15:15:26 +00:00
Nana Janashia
81b557f424 Update Jenkinsfile 2020-11-08 15:14:14 +00:00
Nana Janashia
6e6e1fdcb6 Update Jenkinsfile 2020-11-08 15:12:19 +00:00
Nana Janashia
75f780bd0c fix lib call 2020-11-08 16:05:48 +01:00
Nana Janashia
6a5572a5f7 call library functions in jenkinsfile 2020-11-08 15:58:31 +01:00
Nana Janashia
d7839d4033 Update Jenkinsfile 2020-11-07 16:28:59 +00:00
Nana Janashia
af78bcdf1e Add new file 2020-11-07 15:45:27 +00:00
Nana Janashia
5a4e789475 Update Jenkinsfile 2020-11-07 15:44:58 +00:00
Nana Janashia
9969d8b2cf Update Jenkinsfile 2020-11-06 12:49:54 +00:00
Nana Janashia
3e129808aa Update Jenkinsfile 2020-11-06 12:40:11 +00:00
Nana Janashia
f03d95e413 Update Jenkinsfile 2020-11-06 12:38:49 +00:00
Nana Janashia
c8f9061ef6 Update Jenkinsfile 2020-11-06 12:38:24 +00:00
Nana Janashia
6804a58c01 Update Jenkinsfile 2020-11-06 12:36:28 +00:00
Nana Janashia
5ef50d2628 Update Jenkinsfile 2020-11-06 12:35:52 +00:00
Nana Janashia
1c02e35f97 Update Jenkinsfile 2020-11-06 12:33:08 +00:00
Nana Janashia
f298808592 Update Jenkinsfile 2020-11-06 12:32:13 +00:00
Nana Janashia
a14a9d4f9a Update Jenkinsfile 2020-11-06 12:24:57 +00:00
Nana Janashia
d267e0d112 Update Jenkinsfile 2020-10-31 15:31:43 +00:00
Nana Janashia
833dd401b3 Add new file 2020-10-31 15:27:05 +00:00
8 changed files with 32 additions and 97 deletions

1
.gitignore vendored
View File

@@ -1,2 +1 @@
.idea/* .idea/*
target

58
Jenkinsfile vendored
View File

@@ -1,52 +1,48 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library identifier: 'jenkins-shared-library@master', retriever: modernSCM( library identifier: 'jenkins-shared-library@master', retriever: modernSCM(
[$class: 'GitSCMSource', [$class: 'GitSCMSource',
remote: 'https://gitlab.com/nanuchi/jenkins-shared-library.git', remote: 'https://gitlab.com/nanuchi/jenkins-shared-library.git',
credentialsId: 'gitlab-credentials' credentialsId: 'gitlab-credentials'
] ]
) )
def gv
pipeline { pipeline {
agent any agent any
tools { tools {
maven 'Maven' maven 'Maven'
} }
environment {
IMAGE_NAME = 'nanajanashia/demo-app:java-maven-2.0'
}
stages { stages {
stage('build app') { stage("init") {
steps {
script {
echo 'building application jar...'
buildJar()
}
}
}
stage('build image') {
steps { steps {
script { script {
echo 'building docker image...' gv = load "script.groovy"
buildImage(env.IMAGE_NAME)
dockerLogin()
dockerPush(env.IMAGE_NAME)
} }
} }
} }
stage('deploy') { stage("build jar") {
steps { steps {
script { script {
echo 'deploying docker image to EC2...' buildJar()
}
def shellCmd = "bash ./server-cmds.sh ${IMAGE_NAME}" }
def ec2Instance = "ec2-user@35.180.251.121" }
stage("build and push image") {
sshagent(['ec2-server-key']) { steps {
sh "scp -o StrictHostKeyChecking=no server-cmds.sh ${ec2Instance}:/home/ec2-user" script {
sh "scp -o StrictHostKeyChecking=no docker-compose.yaml ${ec2Instance}:/home/ec2-user" buildImage 'nanajanashia/demo-app:jma-3.0'
sh "ssh -o StrictHostKeyChecking=no ${ec2Instance} ${shellCmd}" dockerLogin()
} dockerPush 'nanajanashia/demo-app:jma-3.0'
}
}
}
stage("deploy") {
steps {
script {
gv.deployApp()
} }
} }
} }

View File

@@ -1,12 +0,0 @@
version: '3.8'
services:
java-maven-app:
image: ${IMAGE}
ports:
- 8080:8080
postgres:
image: postgres:13
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=my-pwd

21
pom.xml
View File

@@ -8,27 +8,6 @@
<artifactId>java-maven-app</artifactId> <artifactId>java-maven-app</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.5.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</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> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

5
script.groovy Normal file
View File

@@ -0,0 +1,5 @@
def deployApp() {
echo 'deploying the application...'
}
return this

View File

@@ -1,5 +0,0 @@
#!/usr/bin/env bash
export IMAGE=$1
docker-compose -f docker-compose.yaml up --detach
echo "success"

View File

@@ -1,11 +0,0 @@
<!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>

View File

@@ -1,16 +0,0 @@
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);
}
}