Compare commits
28 Commits
feature/je
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92602e6c79 | ||
|
|
bcff7b9713 | ||
|
|
851ef30959 | ||
|
|
feda16a9a8 | ||
|
|
0c2ab7794d | ||
|
|
31209ff01c | ||
|
|
fd26c2e81b | ||
|
|
4e6c3e791d | ||
|
|
b9c23ee70d | ||
|
|
2f9fd78922 | ||
|
|
7848de66a2 | ||
|
|
007c036d2a | ||
|
|
3da4e695d0 | ||
|
|
b7f48cdd4a | ||
|
|
d7839d4033 | ||
|
|
af78bcdf1e | ||
|
|
5a4e789475 | ||
|
|
9969d8b2cf | ||
|
|
3e129808aa | ||
|
|
f03d95e413 | ||
|
|
c8f9061ef6 | ||
|
|
6804a58c01 | ||
|
|
5ef50d2628 | ||
|
|
1c02e35f97 | ||
|
|
f298808592 | ||
|
|
a14a9d4f9a | ||
|
|
d267e0d112 | ||
|
|
833dd401b3 |
@@ -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"]
|
||||
64
Jenkinsfile
vendored
64
Jenkinsfile
vendored
@@ -1,54 +1,38 @@
|
||||
#!/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'
|
||||
]
|
||||
)
|
||||
def gv
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'Maven'
|
||||
}
|
||||
environment {
|
||||
IMAGE_NAME = 'nanajanashia/demo-app:java-maven-2.0'
|
||||
}
|
||||
stages {
|
||||
stage('build app') {
|
||||
steps {
|
||||
script {
|
||||
echo 'building application jar...'
|
||||
buildJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('build image') {
|
||||
stage("init") {
|
||||
steps {
|
||||
script {
|
||||
echo 'building docker image...'
|
||||
buildImage(env.IMAGE_NAME)
|
||||
dockerLogin()
|
||||
dockerPush(env.IMAGE_NAME)
|
||||
gv = load "script.groovy"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('deploy') {
|
||||
stage("build jar") {
|
||||
steps {
|
||||
script {
|
||||
echo 'deploying docker image to EC2...'
|
||||
|
||||
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}"
|
||||
}
|
||||
echo "building jar"
|
||||
//gv.buildJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage("build image") {
|
||||
steps {
|
||||
script {
|
||||
echo "building image"
|
||||
//gv.buildImage()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage("deploy") {
|
||||
steps {
|
||||
script {
|
||||
echo "deploying"
|
||||
//gv.deployApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
19
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>java-maven-app</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -22,13 +22,20 @@
|
||||
</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>
|
||||
<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>
|
||||
|
||||
19
script.groovy
Normal file
19
script.groovy
Normal 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
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export IMAGE=$1
|
||||
docker-compose -f docker-compose.yaml up --detach
|
||||
echo "success"
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user