28 Commits

Author SHA1 Message Date
Nana Janashia
92602e6c79 Update pom.xml 2021-10-27 06:27:59 +00:00
Nana Janashia
bcff7b9713 Add simple UI 2021-07-12 12:40:04 +02:00
Nana Janashia
851ef30959 Update pom.xml 2021-03-24 14:38:33 +00:00
Nana Janashia
feda16a9a8 Delete freestyle-build.sh 2021-01-01 14:25:12 +00:00
Nana Janashia
0c2ab7794d Add new file 2021-01-01 14:23:51 +00:00
Nana Janashia
31209ff01c Update Jenkinsfile 2020-12-04 09:06:55 +00:00
Nana Janashia
fd26c2e81b Update Jenkinsfile 2020-12-03 15:41:22 +00:00
Nana Janashia
4e6c3e791d Update Jenkinsfile 2020-12-03 15:25:12 +00:00
Nana Janashia
b9c23ee70d Update Jenkinsfile 2020-12-03 15:24:37 +00:00
Nana Janashia
2f9fd78922 Update Jenkinsfile 2020-12-03 15:23:58 +00:00
Nana Janashia
7848de66a2 add patch version to maven version 2020-11-28 11:34:52 +01:00
Nana Janashia
007c036d2a fixed building jar file 2020-11-22 11:33:45 +01:00
Nana Janashia
3da4e695d0 Update Jenkinsfile 2020-11-08 15:23:44 +00:00
Nana Janashia
b7f48cdd4a Update Jenkinsfile 2020-11-08 15:22:06 +00: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
7 changed files with 56 additions and 87 deletions

View File

@@ -1,8 +0,0 @@
FROM openjdk:8-jre-alpine
EXPOSE 8080
COPY ./target/java-maven-app-1.0-SNAPSHOT.jar /usr/app/
WORKDIR /usr/app
ENTRYPOINT ["java", "-jar", "java-maven-app-1.0-SNAPSHOT.jar"]

50
Jenkinsfile vendored
View File

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

19
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.example</groupId> <groupId>com.example</groupId>
<artifactId>java-maven-app</artifactId> <artifactId>java-maven-app</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.1.0-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>
@@ -22,13 +22,20 @@
</execution> </execution>
</executions> </executions>
</plugin> </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> </plugins>
</build> </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>

19
script.groovy Normal file
View File

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

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,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);
}
}