From 8ae83c55553e91c0f026be77b711e6593bbc0078 Mon Sep 17 00:00:00 2001 From: Nana Janashia Date: Sat, 3 Apr 2021 14:03:51 +0200 Subject: [PATCH] Initi commit --- Jenkinsfile | 38 --------------------------------- Jenkinsfile-v1 | 38 +++++++++++++++++++++++++++++++++ Jenkinsfile-v2 | 34 +++++++++++++++++++++++++++++ ansible/ansible.cfg | 9 ++++++++ ansible/docker-and-compose.yaml | 29 +++++++++++++++++++++++++ ansible/inventory_aws_ec2.yaml | 9 ++++++++ script.groovy | 19 ----------------- 7 files changed, 119 insertions(+), 57 deletions(-) delete mode 100644 Jenkinsfile create mode 100644 Jenkinsfile-v1 create mode 100644 Jenkinsfile-v2 create mode 100644 ansible/ansible.cfg create mode 100644 ansible/docker-and-compose.yaml create mode 100644 ansible/inventory_aws_ec2.yaml delete mode 100644 script.groovy diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 51f3419..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,38 +0,0 @@ -def gv - -pipeline { - agent any - stages { - stage("init") { - steps { - script { - gv = load "script.groovy" - } - } - } - stage("build jar") { - steps { - script { - echo "building jar" - //gv.buildJar() - } - } - } - stage("build image") { - steps { - script { - echo "building image" - //gv.buildImage() - } - } - } - stage("deploy") { - steps { - script { - echo "deploying" - //gv.deployApp() - } - } - } - } -} \ No newline at end of file diff --git a/Jenkinsfile-v1 b/Jenkinsfile-v1 new file mode 100644 index 0000000..bf38b40 --- /dev/null +++ b/Jenkinsfile-v1 @@ -0,0 +1,38 @@ +pipeline { + agent any + stages { + stage("copy playbook to ansible-server") { + steps { + script { + echo "copying ansible folder to ansible server" + + + } + } + } + stage("copy ssh keys for Ansible") { + steps { + script { + echo "copying ssh keys for ec2 instances" + + } + } + } + stage("execute ansible playbook from the ansible-server") { + steps { + script { + echo "executing ansible-playbook" + + def remote = [:] + remote.host = "157.230.120.252" + remote.allowAnyHosts = true + + withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', usernameVariable: 'user')]) { + remote.user = user + sshCommand remote: remote, command: "ls -lrt" + } + } + } + } + } +} \ No newline at end of file diff --git a/Jenkinsfile-v2 b/Jenkinsfile-v2 new file mode 100644 index 0000000..836999a --- /dev/null +++ b/Jenkinsfile-v2 @@ -0,0 +1,34 @@ +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...' + } + } + } + } +} \ No newline at end of file diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..0f5e329 --- /dev/null +++ b/ansible/ansible.cfg @@ -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 \ No newline at end of file diff --git a/ansible/docker-and-compose.yaml b/ansible/docker-and-compose.yaml new file mode 100644 index 0000000..b11ccad --- /dev/null +++ b/ansible/docker-and-compose.yaml @@ -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 \ No newline at end of file diff --git a/ansible/inventory_aws_ec2.yaml b/ansible/inventory_aws_ec2.yaml new file mode 100644 index 0000000..8d94d50 --- /dev/null +++ b/ansible/inventory_aws_ec2.yaml @@ -0,0 +1,9 @@ +--- +plugin: aws_ec2 +regions: + - eu-west-3 +keyed_groups: + - key: tags + prefix: tag + - key: instance_type + prefix: instance_type \ No newline at end of file diff --git a/script.groovy b/script.groovy deleted file mode 100644 index 79ddb88..0000000 --- a/script.groovy +++ /dev/null @@ -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 \ No newline at end of file