86 Commits

Author SHA1 Message Date
Nana Janashia
dd21d95e93 Update Jenkinsfile 2021-12-04 15:54:42 +00:00
Nana Janashia
9492a348d0 Add frontend and java compatibility config 2021-07-12 12:27:29 +02:00
Nana Janashia
a87e8850de Remove target from source code 2021-07-12 12:13:41 +02:00
Nana Janashia
6123875bc8 add changes 2020-11-22 15:03:10 +01:00
Nana Janashia
1f54931484 add changes 2020-11-22 14:46:01 +01:00
Nana Janashia
18ecdca204 fix 2020-11-22 14:35:13 +01:00
Nana Janashia
e1dbd4d042 fix 2020-11-22 14:32:48 +01:00
Nana Janashia
36b85d75cc pass image name to shell script 2020-11-22 14:30:13 +01:00
Nana Janashia
c120554c74 tag replacement in docker-compose 2020-11-22 14:19:34 +01:00
Nana Janashia
3e1d99e8d0 rm env set 2020-11-22 14:10:05 +01:00
Nana Janashia
e71aab1655 add shell script for executing 2020-11-22 14:04:09 +01:00
Nana Janashia
762a6a9ffb add shell script for executing 2020-11-22 13:59:25 +01:00
Nana Janashia
e14b7b7012 fix env var setup 2020-11-22 13:43:08 +01:00
Nana Janashia
106a7e447e fix ports 2020-11-22 13:28:47 +01:00
Nana Janashia
b28d6ff9d9 add docker-compose config 2020-11-22 13:27:04 +01:00
Nana Janashia
4e33b70b24 Delete test.sh 2020-11-22 11:48:37 +00:00
Nana Janashia
d41bcec12b Update Jenkinsfile 2020-11-22 11:46:58 +00:00
Nana Janashia
9dadc24128 Update test.sh 2020-11-22 11:46:37 +00:00
Nana Janashia
12f88937ab Update Jenkinsfile 2020-11-22 11:38:52 +00:00
Nana Janashia
8b1aa75d8e Update test.sh 2020-11-22 11:38:44 +00:00
Nana Janashia
339109ec86 Update Jenkinsfile 2020-11-22 11:14:16 +00:00
Nana Janashia
63f6c3d5bb Update Jenkinsfile 2020-11-22 11:10:37 +00:00
Nana Janashia
ba9f0882ca Update freestyle-build.sh 2020-11-22 11:00:46 +00:00
Nana Janashia
0b043899f9 Update Jenkinsfile 2020-11-22 11:00:27 +00:00
Nana Janashia
f31394abe3 Update Jenkinsfile 2020-11-22 11:00:15 +00:00
Nana Janashia
e2633b0888 Update freestyle-build.sh 2020-11-22 10:56:56 +00:00
Nana Janashia
a1b5946b6d fixed building jar file 2020-11-22 11:32:38 +01:00
Nana Janashia
45817d153a fixed port 2020-11-22 10:13:21 +01:00
Nana Janashia
0576e0033b fixed env var usage 2020-11-22 10:08:59 +01:00
Nana Janashia
44cf4ac38c adjustments 2020-11-22 09:58:37 +01:00
Nana Janashia
04f35ad918 Update Jenkinsfile 2020-11-08 15:26:35 +00:00
Nana Janashia
686259038b add shebang 2020-11-08 15:39:58 +01:00
Nana Janashia
1978bd1fc9 Update Jenkinsfile 2020-11-08 12:57:32 +00:00
Nana Janashia
b262ce98c8 Update Jenkinsfile 2020-11-08 12:56:40 +00:00
Nana Janashia
24fdad6aaa Update Jenkinsfile 2020-11-08 09:46:22 +00:00
Nana Janashia
e41eb6433d Update Jenkinsfile 2020-11-08 09:45:28 +00:00
Nana Janashia
1ce128d916 Update Jenkinsfile 2020-11-08 08:10:52 +00:00
Nana Janashia
2c6295012f Update Jenkinsfile 2020-11-08 08:10:25 +00:00
Nana Janashia
48b35c0308 Update Jenkinsfile 2020-11-08 08:09:54 +00:00
Nana Janashia
80ed88f4be Update Jenkinsfile 2020-11-08 08:09:11 +00:00
Nana Janashia
f8698fee42 Update Jenkinsfile 2020-11-07 17:43:27 +00:00
Nana Janashia
eea2109d66 Update Jenkinsfile 2020-11-07 17:43:18 +00:00
Nana Janashia
a71dd16df8 Update Jenkinsfile 2020-11-07 17:18:06 +00:00
Nana Janashia
8e3382a0ef Update Jenkinsfile 2020-11-07 17:07:02 +00:00
Nana Janashia
1d4aac4b5a Update Jenkinsfile 2020-11-07 17:04:52 +00:00
Nana Janashia
f65d9eb00e Update Jenkinsfile 2020-11-07 16:59:22 +00:00
Nana Janashia
a026af6e2f Update Jenkinsfile 2020-11-07 16:56:56 +00:00
Nana Janashia
02aef32659 Update Jenkinsfile 2020-11-07 16:53:58 +00:00
Nana Janashia
e68743b02d Update Jenkinsfile 2020-11-07 16:52:56 +00:00
Nana Janashia
ce28529588 Update Jenkinsfile 2020-11-07 16:51:48 +00:00
Nana Janashia
a0deb05e4e Update Jenkinsfile 2020-11-07 16:50:48 +00:00
Nana Janashia
126336f79e Update Jenkinsfile 2020-11-07 16:44:13 +00:00
Nana Janashia
19eeb818ca Update Jenkinsfile 2020-11-07 16:41:18 +00:00
Nana Janashia
ff51c37f0a Update Jenkinsfile 2020-11-07 16:40:39 +00:00
Nana Janashia
948fbb8f12 Update Jenkinsfile 2020-11-07 16:39:30 +00:00
Nana Janashia
679d67b80a Update Jenkinsfile 2020-11-07 16:37:49 +00:00
Nana Janashia
661a008faa Update Jenkinsfile 2020-11-07 16:36:06 +00:00
Nana Janashia
9cc6d90fe8 Update Jenkinsfile 2020-11-07 16:32:06 +00:00
Nana Janashia
61821c6ef7 Update Jenkinsfile 2020-11-06 12:47:14 +00:00
Nana Janashia
1fa470771d Delete script.groovy 2020-11-06 12:27:54 +00:00
Nana Janashia
9c56ddc553 Update Jenkinsfile 2020-11-06 12:26:25 +00:00
Nana Janashia
056eca7cf6 Update script.groovy 2020-11-06 11:26:50 +00:00
Nana Janashia
e637047b84 Update Jenkinsfile 2020-11-06 11:26:28 +00:00
Nana Janashia
845783dbc6 Update Jenkinsfile 2020-11-06 11:17:00 +00:00
Nana Janashia
cdacbeeec4 Update Jenkinsfile 2020-11-06 09:14:56 +00:00
Nana Janashia
1228821c74 Update Jenkinsfile 2020-11-06 09:10:05 +00:00
Nana Janashia
650570153a Update Jenkinsfile 2020-11-06 08:33:33 +00:00
Nana Janashia
e5f3bc546b Update Jenkinsfile 2020-11-06 08:28:39 +00:00
Nana Janashia
99d992ee76 Add new file 2020-11-05 17:47:49 +00:00
Nana Janashia
273c10f041 Update Jenkinsfile 2020-11-05 17:47:23 +00:00
Nana Janashia
e0be3b5f9d Update Jenkinsfile 2020-11-05 17:23:39 +00:00
Nana Janashia
c4cba3ddc6 Update Jenkinsfile-basic 2020-11-05 14:31:01 +00:00
Nana Janashia
8fb1d04fa8 Update Jenkinsfile 2020-11-05 14:30:29 +00:00
Nana Janashia
48aa2427b3 Add Jenkinsfile 2020-11-05 14:04:42 +00:00
Nana Janashia
ed870a0c6b Delete Jenkinsfile 2020-11-05 13:43:16 +00:00
Nana
28932727d1 add dockerfile 2020-11-01 14:00:03 +01:00
Nana
2ef267a3fb fix test 2020-11-01 13:04:44 +01:00
Nana Janashia
05f3e19201 Update freestyle-build.sh 2020-11-01 12:02:04 +00:00
Nana Janashia
5d8d48709e Update src/test/java/AppTest.java 2020-11-01 12:00:55 +00:00
Nana Janashia
fa5460fa44 Update freestyle-build.sh 2020-11-01 11:54:56 +00:00
Nana Janashia
ae9b87113d Update freestyle-build.sh 2020-11-01 11:34:40 +00:00
Nana Janashia
86350ca4e1 Update Jenkinsfile 2020-10-31 15:30:40 +00:00
Nana Janashia
51edfc3d66 Update Jenkinsfile 2020-10-31 15:29:57 +00:00
Nana Janashia
c8da404d8b Update Jenkinsfile 2020-10-31 15:29:01 +00:00
Nana Janashia
18a24797ed Add new file 2020-10-31 15:27:17 +00:00
Nana Janashia
710e1151f8 Add new file 2020-10-31 13:40:38 +00:00
13 changed files with 97 additions and 109 deletions

1
.gitignore vendored
View File

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

8
Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
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"]

56
Jenkinsfile vendored
View File

@@ -1,37 +1,51 @@
#!/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 { pipeline {
agent any agent any
tools {
maven 'Maven'
}
environment { environment {
ANSIBLE_SERVER = "167.99.136.157" IMAGE_NAME = 'nanajanashia/demo-app:java-maven-2.0'
} }
stages { stages {
stage("copy files to ansible server") { stage('build app') {
steps { steps {
script { script {
echo "copying all neccessary files to ansible control node" echo 'building application jar...'
sshagent(['ansible-server-key']) { buildJar()
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
sh 'scp $keyfile root@$ANSIBLE_SERVER:/root/ssh-key.pem'
} }
} }
} }
} stage('build image') {
}
stage("execute ansible playbook") {
steps { steps {
script { script {
echo "calling ansible playbook to configure ec2 instances" echo 'building docker image...'
def remote = [:] buildImage(env.IMAGE_NAME)
remote.name = "ansible-server" dockerLogin()
remote.host = ANSIBLE_SERVER dockerPush(env.IMAGE_NAME)
remote.allowAnyHosts = true }
}
}
stage('deploy') {
steps {
script {
echo 'deploying docker image to EC2...'
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]){ def shellCmd = "bash ./server-cmds.sh ${IMAGE_NAME}"
remote.user = user def ec2Instance = "ec2-user@35.180.251.121"
remote.identityFile = keyfile
sshScript remote: remote, script: "prepare-ansible-server.sh" sshagent(['ec2-server-key']) {
sshCommand remote: remote, command: "ansible-playbook my-playbook.yaml" 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}"
} }
} }
} }

View File

@@ -1,9 +0,0 @@
[defaults]
host_key_checking = False
inventory = inventory_aws_ec2.yaml
interpreter_python = /usr/bin/python3
enable_plugins = aws_ec2
remote_user = ec2-user
private_key_file = ~/ssh-key.pem

View File

@@ -1,9 +0,0 @@
---
plugin: aws_ec2
regions:
- eu-west-3
keyed_groups:
- key: tags
prefix: tag
- key: instance_type
prefix: instance_type

View File

@@ -1,29 +0,0 @@
---
- name: Install python3, docker, docker-compose
hosts: all
become: yes
gather_facts: False
tasks:
- name: Install python3 and docker
vars:
ansible_python_interpreter: /usr/bin/python
yum:
name:
- python3
- docker
update_cache: yes
state: present
- name: Install Docker-compose
get_url:
url: https://github.com/docker/compose/releases/download/1.27.4/docker-compose-Linux-{{lookup('pipe', 'uname -m')}}
dest: /usr/local/bin/docker-compose
mode: +x
- name: Start docker daemon
systemd:
name: docker
state: started
- name: Install docker python module
pip:
name:
- docker
- docker-compose

12
docker-compose.yaml Normal file
View 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

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.1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>
@@ -22,20 +22,13 @@
</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>

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
apt update
apt install ansible -y
apt install python3-pip -y
pip3 install boto3 botocore

View File

@@ -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
View File

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

View 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>

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