38 Commits

Author SHA1 Message Date
Nana Janashia
b739431651 Update Jenkinsfile 2021-03-21 13:40:15 +00:00
Nana Janashia
b78ed1bcf6 Update Jenkinsfile 2021-03-21 13:21:51 +00:00
Nana Janashia
00154a9e93 Update Jenkinsfile 2021-03-21 12:44:54 +00:00
Nana Janashia
df13897a25 Update Jenkinsfile 2021-03-21 11:11:15 +00:00
Nana Janashia
94db5c3efa Update Jenkinsfile 2021-03-21 10:20:42 +00:00
Nana Janashia
17291abd2e Update Jenkinsfile 2021-03-21 10:18:40 +00:00
Nana Janashia
d72a06f005 Update Jenkinsfile 2021-03-21 09:56:30 +00:00
Nana Janashia
0bd74fa092 Update Application.java 2021-03-21 09:56:06 +00:00
Nana Janashia
ac5c2b2106 Update Application.java 2021-03-21 09:48:22 +00:00
Nana Janashia
ddce6d49ac Update Jenkinsfile 2021-03-21 09:45:31 +00:00
Nana Janashia
ba406dd3a9 Update Jenkinsfile 2021-03-21 09:44:40 +00:00
Nana Janashia
997013ad3f Update Jenkinsfile 2021-03-21 08:55:14 +00:00
Nana Janashia
9fb3cfce01 Update Jenkinsfile 2021-03-21 08:53:32 +00:00
Nana Janashia
58f1a5cf3e Update Jenkinsfile 2021-03-21 08:44:59 +00:00
Nana Janashia
ee4f86c17a Update Jenkinsfile 2021-03-21 08:42:31 +00:00
Nana Janashia
94609f4347 Update Jenkinsfile 2021-03-21 08:40:58 +00:00
Nana Janashia
b10e682c11 Update Jenkinsfile 2021-03-21 08:30:52 +00:00
Nana Janashia
12135903ab Update Jenkinsfile 2021-03-21 08:21:44 +00:00
Nana Janashia
982fdd2438 Update Jenkinsfile 2021-03-21 08:20:13 +00:00
Nana Janashia
df3a84426f Update Jenkinsfile 2021-03-21 08:15:07 +00:00
Nana Janashia
b39bdc130f adjustments 2020-11-22 09:25:55 +01:00
Nana Janashia
7002a942d3 adjustments 2020-11-22 09:24:54 +01:00
Nana Janashia
5ee75f88dd Update Jenkinsfile 2020-11-18 12:44:07 +00:00
Nana Janashia
6a2de89154 Update Jenkinsfile 2020-11-18 12:15:37 +00:00
Nana Janashia
f6850fa35f Update Jenkinsfile 2020-11-18 12:10:01 +00:00
Nana Janashia
31ecf84171 Update Jenkinsfile 2020-11-18 12:08:28 +00:00
Nana Janashia
9b90eae493 Update Jenkinsfile 2020-11-18 12:01:49 +00:00
Nana Janashia
4056c657d3 Update Jenkinsfile 2020-11-18 12:00:08 +00:00
Nana Janashia
a5ed743178 Update Jenkinsfile 2020-11-18 11:59:09 +00:00
Nana Janashia
8afb0e62a3 Update Jenkinsfile 2020-11-12 09:42:08 +00:00
Nana Janashia
2b4921b5c8 Update Jenkinsfile 2020-11-12 09:37:37 +00:00
Nana Janashia
4f06b352e5 Update Jenkinsfile 2020-11-12 09:36:25 +00:00
Nana Janashia
c425e899d4 Update Jenkinsfile 2020-11-11 18:39:09 +00:00
Nana Janashia
15d6bf124f Update Jenkinsfile 2020-11-11 18:33:19 +00:00
Nana Janashia
b1440f702b Update Jenkinsfile 2020-11-11 16:55:32 +00:00
Nana Janashia
90bb5d1ddf Update Jenkinsfile 2020-11-11 16:46:57 +00:00
Nana Janashia
302893976c Update Jenkinsfile 2020-11-11 16:46:22 +00:00
Nana Janashia
a4a55e133b Update Jenkinsfile 2020-11-11 16:45:14 +00:00
10 changed files with 30 additions and 220 deletions

1
.gitignore vendored
View File

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

28
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('test') {
steps {
script {
echo "Testing the application..."
}
}
}
stage('build') {
steps {
script {
echo "Building the application..."
}
}
}
stage('deploy') {
steps {
script {
echo "Deploying the application..."
}
}
}
}
}

View File

@@ -1,52 +0,0 @@
pipeline {
agent any
environment {
ANSIBLE_SERVER = "157.230.120.252"
}
stages {
stage("copy ansible folder and ec2 access key to ansible-server") {
steps {
script {
sshagent(['ansible-server-key']) {
echo "copying ansible folder to ansible server"
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
echo "copying ssh keys for ec2 instances"
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
sh 'scp $keyfile root@$ANSIBLE_SERVER:/root/ssh-key.pem'
}
}
}
}
}
stage("execute ansible playbook from the ansible-server") {
environment {
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
}
steps {
script {
echo "executing ansible-playbook"
def remote = [:]
remote.name = "ansible-server"
remote.host = ANSIBLE_SERVER
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
remote.identityFile = keyfile
remote.user = user
sshCommand remote: remote, command: "ls -l"
// set AWS credentials
sshScript remote: remote, script: "ansible/prepare-server.sh"
sshCommand remote: remote, command: "export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}; export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}; ansible-playbook docker-and-compose.yaml"
}
}
}
}
}
}

View File

@@ -1,48 +0,0 @@
pipeline {
agent any
environment {
ANSIBLE_SERVER = "157.230.120.252"
}
stages {
stage("copy ansible folder and ec2 access key to ansible-server") {
steps {
script {
sshagent(['ansible-server-key']) {
echo "copying ansible folder to ansible server"
// ${ANSIBLE_SERVER}:/root without root will give jenkins@${ANSIBLE_SERVER}:/root
sh "scp -o StrictHostKeyChecking=no ansible/* root@${ANSIBLE_SERVER}:/root"
echo "copying ssh keys for ec2 instances"
withCredentials([sshUserPrivateKey(credentialsId: 'ec2-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
sh 'scp $keyfile root@$ANSIBLE_SERVER:/root/ssh-key.pem'
}
}
}
}
}
stage("execute ansible playbook from the ansible-server") {
environment {
AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id')
AWS_SECRET_ACCESS_KEY = credentials('jenkins_aws_secret_access_key')
}
steps {
script {
echo "executing ansible-playbook"
def remote = [:]
remote.name = "ansible-server"
remote.host = ANSIBLE_SERVER
remote.allowAnyHosts = true
withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
remote.identityFile = keyfile
remote.user = user
sshCommand remote: remote, command: "ls -l"
sshCommand remote: remote, command: "ansible-playbook docker-and-compose.yaml"
}
}
}
}
}
}

View File

@@ -1,34 +0,0 @@
def gv
pipeline {
agent any
stages {
stage("build jar") {
steps {
script {
echo "building the application..."
sh 'mvn package'
}
}
}
stage("build image") {
steps {
script {
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'
}
}
}
}
stage("deploy") {
steps {
script {
echo 'deploying the application...'
}
}
}
}
}

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

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,10 +0,0 @@
#!/usr/bin/env bash
apt update
apt install ansible -y
apt install python3-pip -y
pip3 install boto3 botocore
# export AWS_ACCESS_KEY_ID=$1
# export AWS_SECRET_ACCESS_KEY=$2

30
pom.xml
View File

@@ -6,35 +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>
<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> <dependencies>
<dependency> <dependency>