Compare commits
86 Commits
feature/an
...
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/*
|
.idea/*
|
||||||
|
target
|
||||||
8
Dockerfile
Normal file
8
Dockerfile
Normal 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
56
Jenkinsfile
vendored
@@ -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}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
plugin: aws_ec2
|
|
||||||
regions:
|
|
||||||
- eu-west-3
|
|
||||||
keyed_groups:
|
|
||||||
- key: tags
|
|
||||||
prefix: tag
|
|
||||||
- key: instance_type
|
|
||||||
prefix: instance_type
|
|
||||||
@@ -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
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
|
||||||
19
pom.xml
19
pom.xml
@@ -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>
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
apt update
|
|
||||||
apt install ansible -y
|
|
||||||
apt install python3-pip -y
|
|
||||||
pip3 install boto3 botocore
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user