21 Commits

Author SHA1 Message Date
Nana Janashia
45e509506b Add optional step of preparing ansible server 2021-04-07 12:10:30 +02:00
Nana Janashia
3b6780360c Create ansible server env var 2021-04-07 12:04:09 +02:00
Nana Janashia
3208a0e63e Execute ansible command remotely 2021-04-07 11:59:04 +02:00
Nana Janashia
c70bfe4bbd Add remote execution 2021-04-07 11:57:06 +02:00
Nana Janashia
2b7f3b1471 Fix security warning for pem file 2021-04-07 11:43:54 +02:00
Nana Janashia
9573355ec3 Add jenkinsfile for ansible execution 2021-04-07 11:24:55 +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
8 changed files with 138 additions and 27 deletions

1
.gitignore vendored
View File

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

36
Jenkinsfile vendored
View File

@@ -1,28 +1,40 @@
#!/usr/bin/env groovy
pipeline {
agent any
environment {
ANSIBLE_SERVER = "167.99.136.157"
}
stages {
stage('test') {
stage("copy files to ansible server") {
steps {
script {
echo "Testing the application..."
echo "copying all neccessary files to ansible control node"
sshagent(['ansible-server-key']) {
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') {
}
}
stage("execute ansible playbook") {
steps {
script {
echo "Building the application..."
echo "calling ansible playbook to configure ec2 instances"
def remote = [:]
remote.name = "ansible-server"
remote.host = ANSIBLE_SERVER
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]){
remote.user = user
remote.identityFile = keyfile
sshScript remote: remote, script: "prepare-ansible-server.sh"
sshCommand remote: remote, command: "ansible-playbook my-playbook.yaml"
}
}
}
stage('deploy') {
steps {
script {
echo "Deploying the application..."
}
}
}
}
}

9
ansible/ansible.cfg Normal file
View File

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

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

29
ansible/my-playbook.yaml Normal file
View File

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

30
pom.xml
View File

@@ -6,7 +6,35 @@
<groupId>com.example</groupId>
<artifactId>java-maven-app</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.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>
<!-- 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>
<dependencies>
<dependency>

View File

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

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