Compare commits
18 Commits
jenkins-sh
...
feature/an
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45e509506b | ||
|
|
3b6780360c | ||
|
|
3208a0e63e | ||
|
|
c70bfe4bbd | ||
|
|
2b7f3b1471 | ||
|
|
9573355ec3 | ||
|
|
851ef30959 | ||
|
|
feda16a9a8 | ||
|
|
0c2ab7794d | ||
|
|
31209ff01c | ||
|
|
fd26c2e81b | ||
|
|
4e6c3e791d | ||
|
|
b9c23ee70d | ||
|
|
2f9fd78922 | ||
|
|
7848de66a2 | ||
|
|
007c036d2a | ||
|
|
3da4e695d0 | ||
|
|
b7f48cdd4a |
46
Jenkinsfile
vendored
46
Jenkinsfile
vendored
@@ -1,36 +1,38 @@
|
||||
def gv
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'Maven'
|
||||
environment {
|
||||
ANSIBLE_SERVER = "167.99.136.157"
|
||||
}
|
||||
stages {
|
||||
stage("init") {
|
||||
stage("copy files to ansible server") {
|
||||
steps {
|
||||
script {
|
||||
gv = load "script.groovy"
|
||||
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 jar") {
|
||||
stage("execute ansible playbook") {
|
||||
steps {
|
||||
script {
|
||||
gv.buildJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage("build image") {
|
||||
steps {
|
||||
script {
|
||||
gv.buildImage()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage("deploy") {
|
||||
steps {
|
||||
script {
|
||||
gv.deployApp()
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
ansible/ansible.cfg
Normal file
9
ansible/ansible.cfg
Normal 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
|
||||
9
ansible/inventory_aws_ec2.yaml
Normal file
9
ansible/inventory_aws_ec2.yaml
Normal 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
29
ansible/my-playbook.yaml
Normal 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
30
pom.xml
@@ -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>
|
||||
|
||||
6
prepare-ansible-server.sh
Normal file
6
prepare-ansible-server.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
apt update
|
||||
apt install ansible -y
|
||||
apt install python3-pip -y
|
||||
pip3 install boto3 botocore
|
||||
Reference in New Issue
Block a user