diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..959d68c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/CI/Docker/volumes/* diff --git a/Ansible-Code/README.md b/Ansible-Code/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Ansible-Code/ansible.cfg b/Ansible-Code/ansible.cfg new file mode 100644 index 0000000..5c72eac --- /dev/null +++ b/Ansible-Code/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +remote_user = ubuntu +inventory = infra diff --git a/Ansible-Code/defaults/main.yml b/Ansible-Code/defaults/main.yml new file mode 100644 index 0000000..a60fad3 --- /dev/null +++ b/Ansible-Code/defaults/main.yml @@ -0,0 +1,2 @@ +--- +jenkins_java_args: -Djava.awt.headless=true -Djenkins.install.runSetupWizard=false diff --git a/Ansible-Code/git.sh b/Ansible-Code/git.sh new file mode 100644 index 0000000..fbcd71a --- /dev/null +++ b/Ansible-Code/git.sh @@ -0,0 +1,6 @@ +#!/bin/bash +git diff +git add . +read -p 'Enter commit message: ' message +git commit -m "$message" +git push origin master diff --git a/Ansible-Code/infra b/Ansible-Code/infra new file mode 100644 index 0000000..990d642 --- /dev/null +++ b/Ansible-Code/infra @@ -0,0 +1,14 @@ +[local] +localhost ansible_connection=local + +[ci] +192.168.0.73 + +[rm] +192.168.0.74 + +[monitoring] +192.168.0.75 + +[worker] +192.168.0.76 diff --git a/Ansible-Code/tasks/main.yml b/Ansible-Code/tasks/main.yml new file mode 100644 index 0000000..fd94739 --- /dev/null +++ b/Ansible-Code/tasks/main.yml @@ -0,0 +1,78 @@ +# This playbook will configure the CI infrastructure +# This is the centralized directory to mount volumes in docker +- name: Create work directory (/home/ubuntu/docker) + file: + name: docker + state: directory +# Jenkins home directory. For reusablity +- name: Create jenkins directory + file: + name: docker/jenkins_home + state: directory + recurse: yes + mode: 0777 +# For storing tomcat-users.xml file +- name: Creat tomcat directory + file: + name: docker/tomcat + state: directory + recurse: yes +- name: Copy tomcat configurations + copy: + src: files/tomcat-users.xml + dest: docker/tomcat/tomcat-users.xml +#- name: Copy Jenkins configurations +# template: +# src: templates/jenkins.xml.j2 +# dest: /home/ubuntu/docker/jenkins_home/config.xml +# owner: ubuntu +# group: ubuntu +# mode: 0777 +# Bring up the infrastructure +- name: Docker compose up +# async: 35 +# poll: 0 +#become: true +#become_user: root + docker_service: + project_name: ci + definition: + version: '2' + services: + jenkins: + image: jenkins:2.19.4-alpine + ports: + - "8080:8080" + - "50000:50000" + volumes: + - "/home/ubuntu/docker/jenkins_home:/var/jenkins_home" + container_name: compose-jenkins + + artifactory: + image: docker.bintray.io/jfrog/artifactory-oss + ports: + - "8081:8081" + volumes: + - /home/ubuntu/docker/artifactory/data:/var/opt/jfrog/artifactory/data + - /home/ubuntu/docker/artifactory/logs:/var/opt/jfrog/artifactory/logs + - /home/ubuntu/docker/artifactory/etc:/var/opt/jfrog/artifactory/etc + container_name: compose-artifactory-oss + + sonarqube: + image: sonarqube + ports: + - "9000:9000" + - "9092:9092" + container_name: compose-sonarqube + + tomcat: + image: tomcat + ports: + - "8888:8080" + volumes: + - /home/ubuntu/docker/tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml + container_name: compose-tomcat + register: test + +- debug: + var: test diff --git a/Ansible-Code/try1/ci.yml b/Ansible-Code/try1/ci.yml new file mode 100644 index 0000000..a8b65da --- /dev/null +++ b/Ansible-Code/try1/ci.yml @@ -0,0 +1,5 @@ +--- +- hosts: ci + become: true + roles: + - ci diff --git a/Ansible-Code/try1/demo.yml b/Ansible-Code/try1/demo.yml new file mode 100644 index 0000000..0bdaede --- /dev/null +++ b/Ansible-Code/try1/demo.yml @@ -0,0 +1,3 @@ +--- +# Site wide playbook +- include: ci.yml diff --git a/Ansible-Code/try1/library/jenkins_plugin.py b/Ansible-Code/try1/library/jenkins_plugin.py new file mode 100644 index 0000000..1394198 --- /dev/null +++ b/Ansible-Code/try1/library/jenkins_plugin.py @@ -0,0 +1,823 @@ +#!/usr/bin/python +# encoding: utf-8 + +# (c) 2016, Jiri Tyr +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils.urls import fetch_url +from ansible.module_utils.urls import url_argument_spec +import base64 +import hashlib +import json +import os +import tempfile +import time +import urllib + + +ANSIBLE_METADATA = {'status': ['preview'], + 'supported_by': 'community', + 'version': '1.0'} + +DOCUMENTATION = ''' +--- +module: jenkins_plugin +author: Jiri Tyr (@jtyr) +version_added: '2.2' +short_description: Add or remove Jenkins plugin +description: + - Ansible module which helps to manage Jenkins plugins. + +options: + group: + required: false + default: jenkins + description: + - Name of the Jenkins group on the OS. + jenkins_home: + required: false + default: /var/lib/jenkins + description: + - Home directory of the Jenkins user. + mode: + required: false + default: '0664' + description: + - File mode applied on versioned plugins. + name: + required: true + description: + - Plugin name. + owner: + required: false + default: jenkins + description: + - Name of the Jenkins user on the OS. + params: + required: false + default: null + description: + - Option used to allow the user to overwrite any of the other options. To + remove an option, set the value of the option to C(null). + state: + required: false + choices: [absent, present, pinned, unpinned, enabled, disabled, latest] + default: present + description: + - Desired plugin state. + - If the C(latest) is set, the check for new version will be performed + every time. This is suitable to keep the plugin up-to-date. + timeout: + required: false + default: 30 + description: + - Server connection timeout in secs. + updates_expiration: + required: false + default: 86400 + description: + - Number of seconds after which a new copy of the I(update-center.json) + file is downloaded. This is used to avoid the need to download the + plugin to calculate its checksum when C(latest) is specified. + - Set it to C(0) if no cache file should be used. In that case, the + plugin file will always be downloaded to calculate its checksum when + C(latest) is specified. + updates_url: + required: false + default: https://updates.jenkins-ci.org + description: + - URL of the Update Centre. + - Used as the base URL to download the plugins and the + I(update-center.json) JSON file. + url: + required: false + default: http://localhost:8080 + description: + - URL of the Jenkins server. + version: + required: false + default: null + description: + - Plugin version number. + - If this option is specified, all plugin dependencies must be installed + manually. + - It might take longer to verify that the correct version is installed. + This is especially true if a specific version number is specified. + - Quote the version to prevent the value to be interpreted as float. For + example if C(1.20) would be unquoted, it would become C(1.2). + with_dependencies: + required: false + choices: ['yes', 'no'] + default: 'yes' + description: + - Defines whether to install plugin dependencies. + +notes: + - Plugin installation should be run under root or the same user which owns + the plugin files on the disk. Only if the plugin is not installed yet and + no version is specified, the API installation is performed which requires + only the Web UI credentials. + - It's necessary to notify the handler or call the I(service) module to + restart the Jenkins service after a new plugin was installed. + - Pinning works only if the plugin is installed and Jenkis service was + successfully restarted after the plugin installation. + - It is not possible to run the module remotely by changing the I(url) + parameter to point to the Jenkins server. The module must be used on the + host where Jenkins runs as it needs direct access to the plugin files. +''' + +EXAMPLES = ''' +- name: Install plugin + jenkins_plugin: + name: build-pipeline-plugin + +- name: Install plugin without its dependencies + jenkins_plugin: + name: build-pipeline-plugin + with_dependencies: no + +- name: Make sure the plugin is always up-to-date + jenkins_plugin: + name: token-macro + state: latest + +- name: Install specific version of the plugin + jenkins_plugin: + name: token-macro + version: "1.15" + +- name: Pin the plugin + jenkins_plugin: + name: token-macro + state: pinned + +- name: Unpin the plugin + jenkins_plugin: + name: token-macro + state: unpinned + +- name: Enable the plugin + jenkins_plugin: + name: token-macro + state: enabled + +- name: Disable the plugin + jenkins_plugin: + name: token-macro + state: disabled + +- name: Uninstall plugin + jenkins_plugin: + name: build-pipeline-plugin + state: absent + +# +# Example of how to use the params +# +# Define a variable and specify all default parameters you want to use across +# all jenkins_plugin calls: +# +# my_jenkins_params: +# url_username: admin +# url_password: p4ssw0rd +# url: http://localhost:8888 +# +- name: Install plugin + jenkins_plugin: + name: build-pipeline-plugin + params: "{{ my_jenkins_params }}" + +# +# Example of a Play which handles Jenkins restarts during the state changes +# +- name: Jenkins Master play + hosts: jenkins-master + vars: + my_jenkins_plugins: + token-macro: + enabled: yes + build-pipeline-plugin: + version: "1.4.9" + pinned: no + enabled: yes + tasks: + - name: Install plugins without a specific version + jenkins_plugin: + name: "{{ item.key }}" + register: my_jenkins_plugin_unversioned + when: > + 'version' not in item.value + with_dict: "{{ my_jenkins_plugins }}" + + - name: Install plugins with a specific version + jenkins_plugin: + name: "{{ item.key }}" + version: "{{ item.value['version'] }}" + register: my_jenkins_plugin_versioned + when: > + 'version' in item.value + with_dict: "{{ my_jenkins_plugins }}" + + - name: Initiate the fact + set_fact: + jenkins_restart_required: no + + - name: Check if restart is required by any of the versioned plugins + set_fact: + jenkins_restart_required: yes + when: item.changed + with_items: "{{ my_jenkins_plugin_versioned.results }}" + + - name: Check if restart is required by any of the unversioned plugins + set_fact: + jenkins_restart_required: yes + when: item.changed + with_items: "{{ my_jenkins_plugin_unversioned.results }}" + + - name: Restart Jenkins if required + service: + name: jenkins + state: restarted + when: jenkins_restart_required + + - name: Wait for Jenkins to start up + uri: + url: http://localhost:8080 + status_code: 200 + timeout: 5 + register: jenkins_service_status + # Keep trying for 5 mins in 5 sec intervals + retries: 60 + delay: 5 + until: > + 'status' in jenkins_service_status and + jenkins_service_status['status'] == 200 + when: jenkins_restart_required + + - name: Reset the fact + set_fact: + jenkins_restart_required: no + when: jenkins_restart_required + + - name: Plugin pinning + jenkins_plugin: + name: "{{ item.key }}" + state: "{{ 'pinned' if item.value['pinned'] else 'unpinned'}}" + when: > + 'pinned' in item.value + with_dict: "{{ my_jenkins_plugins }}" + + - name: Plugin enabling + jenkins_plugin: + name: "{{ item.key }}" + state: "{{ 'enabled' if item.value['enabled'] else 'disabled'}}" + when: > + 'enabled' in item.value + with_dict: "{{ my_jenkins_plugins }}" +''' + +RETURN = ''' +plugin: + description: plugin name + returned: success + type: string + sample: build-pipeline-plugin +state: + description: state of the target, after execution + returned: success + type: string + sample: "present" +''' + + +class JenkinsPlugin(object): + def __init__(self, module): + # To be able to call fail_json + self.module = module + + # Shortcuts for the params + self.params = self.module.params + self.url = self.params['url'] + self.timeout = self.params['timeout'] + + # Crumb + self.crumb = {} + + if self._csrf_enabled(): + self.crumb = self._get_crumb() + + # Get list of installed plugins + self._get_installed_plugins() + + def _csrf_enabled(self): + csrf_data = self._get_json_data( + "%s/%s" % (self.url, "api/json"), 'CSRF') + + return csrf_data["useCrumbs"] + + def _get_json_data(self, url, what, **kwargs): + # Get the JSON data + r = self._get_url_data(url, what, **kwargs) + + # Parse the JSON data + try: + json_data = json.load(r) + except Exception: + e = get_exception() + self.module.fail_json( + msg="Cannot parse %s JSON data." % what, + details=e.message) + + return json_data + + def _get_url_data( + self, url, what=None, msg_status=None, msg_exception=None, + **kwargs): + # Compose default messages + if msg_status is None: + msg_status = "Cannot get %s" % what + + if msg_exception is None: + msg_exception = "Retrieval of %s failed." % what + + # Get the URL data + try: + response, info = fetch_url( + self.module, url, timeout=self.timeout, **kwargs) + + if info['status'] != 200: + self.module.fail_json(msg=msg_status, details=info['msg']) + except Exception: + e = get_exception() + self.module.fail_json(msg=msg_exception, details=e.message) + + return response + + def _get_crumb(self): + crumb_data = self._get_json_data( + "%s/%s" % (self.url, "crumbIssuer/api/json"), 'Crumb') + + if 'crumbRequestField' in crumb_data and 'crumb' in crumb_data: + ret = { + crumb_data['crumbRequestField']: crumb_data['crumb'] + } + else: + self.module.fail_json( + msg="Required fields not found in the Crum response.", + details=crumb_data) + + return ret + + def _get_installed_plugins(self): + plugins_data = self._get_json_data( + "%s/%s" % (self.url, "pluginManager/api/json?depth=1"), + 'list of plugins') + + # Check if we got valid data + if 'plugins' not in plugins_data: + self.module.fail_json(msg="No valid plugin data found.") + + # Create final list of installed/pined plugins + self.is_installed = False + self.is_pinned = False + self.is_enabled = False + + for p in plugins_data['plugins']: + if p['shortName'] == self.params['name']: + self.is_installed = True + + if p['pinned']: + self.is_pinned = True + + if p['enabled']: + self.is_enabled = True + + break + + def install(self): + changed = False + plugin_file = ( + '%s/plugins/%s.jpi' % ( + self.params['jenkins_home'], + self.params['name'])) + + if not self.is_installed and self.params['version'] is None: + if not self.module.check_mode: + # Install the plugin (with dependencies) + install_script = ( + 'd = Jenkins.instance.updateCenter.getPlugin("%s")' + '.deploy(); d.get();' % self.params['name']) + + if self.params['with_dependencies']: + install_script = ( + 'Jenkins.instance.updateCenter.getPlugin("%s")' + '.getNeededDependencies().each{it.deploy()}; %s' % ( + self.params['name'], install_script)) + + script_data = { + 'script': install_script + } + script_data.update(self.crumb) + data = urllib.urlencode(script_data) + + # Send the installation request + r = self._get_url_data( + "%s/scriptText" % self.url, + msg_status="Cannot install plugin.", + msg_exception="Plugin installation has failed.", + data=data) + + hpi_file = '%s/plugins/%s.hpi' % ( + self.params['jenkins_home'], + self.params['name']) + + if os.path.isfile(hpi_file): + os.remove(hpi_file) + + changed = True + else: + # Check if the plugin directory exists + if not os.path.isdir(self.params['jenkins_home']): + self.module.fail_json( + msg="Jenkins home directory doesn't exist.") + + md5sum_old = None + if os.path.isfile(plugin_file): + # Make the checksum of the currently installed plugin + md5sum_old = hashlib.md5( + open(plugin_file, 'rb').read()).hexdigest() + + if self.params['version'] in [None, 'latest']: + # Take latest version + plugin_url = ( + "%s/latest/%s.hpi" % ( + self.params['updates_url'], + self.params['name'])) + else: + # Take specific version + plugin_url = ( + "{0}/download/plugins/" + "{1}/{2}/{1}.hpi".format( + self.params['updates_url'], + self.params['name'], + self.params['version'])) + + if ( + self.params['updates_expiration'] == 0 or + self.params['version'] not in [None, 'latest'] or + md5sum_old is None): + + # Download the plugin file directly + r = self._download_plugin(plugin_url) + + # Write downloaded plugin into file if checksums don't match + if md5sum_old is None: + # No previously installed plugin + if not self.module.check_mode: + self._write_file(plugin_file, r) + + changed = True + else: + # Get data for the MD5 + data = r.read() + + # Make new checksum + md5sum_new = hashlib.md5(data).hexdigest() + + # If the checksum is different from the currently installed + # plugin, store the new plugin + if md5sum_old != md5sum_new: + if not self.module.check_mode: + self._write_file(plugin_file, data) + + changed = True + else: + # Check for update from the updates JSON file + plugin_data = self._download_updates() + + try: + sha1_old = hashlib.sha1(open(plugin_file, 'rb').read()) + except Exception: + e = get_exception() + self.module.fail_json( + msg="Cannot calculate SHA1 of the old plugin.", + details=e.message) + + sha1sum_old = base64.b64encode(sha1_old.digest()) + + # If the latest version changed, download it + if sha1sum_old != plugin_data['sha1']: + if not self.module.check_mode: + r = self._download_plugin(plugin_url) + self._write_file(plugin_file, r) + + changed = True + + # Change file attributes if needed + if os.path.isfile(plugin_file): + params = { + 'dest': plugin_file + } + params.update(self.params) + file_args = self.module.load_file_common_arguments(params) + + if not self.module.check_mode: + # Not sure how to run this in the check mode + changed = self.module.set_fs_attributes_if_different( + file_args, changed) + else: + # See the comment above + changed = True + + return changed + + def _download_updates(self): + updates_filename = 'jenkins-plugin-cache.json' + updates_dir = os.path.expanduser('~/.ansible/tmp') + updates_file = "%s/%s" % (updates_dir, updates_filename) + download_updates = True + + # Check if we need to download new updates file + if os.path.isfile(updates_file): + # Get timestamp when the file was changed last time + ts_file = os.stat(updates_file).st_mtime + ts_now = time.time() + + if ts_now - ts_file < self.params['updates_expiration']: + download_updates = False + + updates_file_orig = updates_file + + # Download the updates file if needed + if download_updates: + url = "%s/update-center.json" % self.params['updates_url'] + + # Get the data + r = self._get_url_data( + url, + msg_status="Remote updates not found.", + msg_exception="Updates download failed.") + + # Write the updates file + update_fd, updates_file = tempfile.mkstemp() + os.write(update_fd, r.read()) + + try: + os.close(update_fd) + except IOError: + e = get_exception() + self.module.fail_json( + msg="Cannot close the tmp updates file %s." % updates_file, + detail=str(e)) + + # Open the updates file + try: + f = open(updates_file) + except IOError: + e = get_exception() + self.module.fail_json( + msg="Cannot open temporal updates file.", + details=str(e)) + + i = 0 + for line in f: + # Read only the second line + if i == 1: + try: + data = json.loads(line) + except Exception: + e = get_exception() + self.module.fail_json( + msg="Cannot load JSON data from the tmp updates file.", + details=e.message) + + break + + i += 1 + + # Move the updates file to the right place if we could read it + if download_updates: + # Make sure the destination directory exists + if not os.path.isdir(updates_dir): + try: + os.makedirs(updates_dir, int('0700', 8)) + except OSError: + e = get_exception() + self.module.fail_json( + msg="Cannot create temporal directory.", + details=e.message) + + self.module.atomic_move(updates_file, updates_file_orig) + + # Check if we have the plugin data available + if 'plugins' not in data or self.params['name'] not in data['plugins']: + self.module.fail_json( + msg="Cannot find plugin data in the updates file.") + + return data['plugins'][self.params['name']] + + def _download_plugin(self, plugin_url): + # Download the plugin + r = self._get_url_data( + plugin_url, + msg_status="Plugin not found.", + msg_exception="Plugin download failed.") + + return r + + def _write_file(self, f, data): + # Store the plugin into a temp file and then move it + tmp_f_fd, tmp_f = tempfile.mkstemp() + + if isinstance(data, str): + os.write(tmp_f_fd, data) + else: + os.write(tmp_f_fd, data.read()) + + try: + os.close(tmp_f_fd) + except IOError: + e = get_exception() + self.module.fail_json( + msg='Cannot close the temporal plugin file %s.' % tmp_f, + details=str(e)) + + # Move the file onto the right place + self.module.atomic_move(tmp_f, f) + + def uninstall(self): + changed = False + + # Perform the action + if self.is_installed: + if not self.module.check_mode: + self._pm_query('doUninstall', 'Uninstallation') + + changed = True + + return changed + + def pin(self): + return self._pinning('pin') + + def unpin(self): + return self._pinning('unpin') + + def _pinning(self, action): + changed = False + + # Check if the plugin is pinned/unpinned + if ( + action == 'pin' and not self.is_pinned or + action == 'unpin' and self.is_pinned): + + # Perform the action + if not self.module.check_mode: + self._pm_query(action, "%sning" % action.capitalize()) + + changed = True + + return changed + + def enable(self): + return self._enabling('enable') + + def disable(self): + return self._enabling('disable') + + def _enabling(self, action): + changed = False + + # Check if the plugin is pinned/unpinned + if ( + action == 'enable' and not self.is_enabled or + action == 'disable' and self.is_enabled): + + # Perform the action + if not self.module.check_mode: + self._pm_query( + "make%sd" % action.capitalize(), + "%sing" % action[:-1].capitalize()) + + changed = True + + return changed + + def _pm_query(self, action, msg): + url = "%s/pluginManager/plugin/%s/%s" % ( + self.params['url'], self.params['name'], action) + data = urllib.urlencode(self.crumb) + + # Send the request + self._get_url_data( + url, + msg_status="Plugin not found. %s" % url, + msg_exception="%s has failed." % msg, + data=data) + + +def main(): + # Module arguments + argument_spec = url_argument_spec() + argument_spec.update( + group=dict(default='jenkins'), + jenkins_home=dict(default='/var/lib/jenkins'), + mode=dict(default='0644', type='raw'), + name=dict(required=True), + owner=dict(default='jenkins'), + params=dict(type='dict'), + state=dict( + choices=[ + 'present', + 'absent', + 'pinned', + 'unpinned', + 'enabled', + 'disabled', + 'latest'], + default='present'), + timeout=dict(default=30, type="int"), + updates_expiration=dict(default=86400, type="int"), + updates_url=dict(default='https://updates.jenkins-ci.org'), + url=dict(default='http://localhost:8080'), + url_password=dict(no_log=True), + version=dict(), + with_dependencies=dict(default=True, type='bool'), + ) + # Module settings + module = AnsibleModule( + argument_spec=argument_spec, + add_file_common_args=True, + supports_check_mode=True, + ) + + # Update module parameters by user's parameters if defined + if 'params' in module.params and isinstance(module.params['params'], dict): + module.params.update(module.params['params']) + # Remove the params + module.params.pop('params', None) + + # Force basic authentication + module.params['force_basic_auth'] = True + + # Convert timeout to float + try: + module.params['timeout'] = float(module.params['timeout']) + except ValueError: + e = get_exception() + module.fail_json( + msg='Cannot convert %s to float.' % module.params['timeout'], + details=str(e)) + + # Set version to latest if state is latest + if module.params['state'] == 'latest': + module.params['state'] = 'present' + module.params['version'] = 'latest' + + # Create some shortcuts + name = module.params['name'] + state = module.params['state'] + + # Initial change state of the task + changed = False + + # Instantiate the JenkinsPlugin object + jp = JenkinsPlugin(module) + + # Perform action depending on the requested state + if state == 'present': + changed = jp.install() + elif state == 'absent': + changed = jp.uninstall() + elif state == 'pinned': + changed = jp.pin() + elif state == 'unpinned': + changed = jp.unpin() + elif state == 'enabled': + changed = jp.enable() + elif state == 'disabled': + changed = jp.disable() + + # Print status of the change + module.exit_json(changed=changed, plugin=name, state=state) + + +if __name__ == '__main__': + main() diff --git a/Ansible-Code/try1/roles/ci/README.md b/Ansible-Code/try1/roles/ci/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Ansible-Code/try1/roles/ci/files/ci-compose.yml b/Ansible-Code/try1/roles/ci/files/ci-compose.yml new file mode 100644 index 0000000..6df94c9 --- /dev/null +++ b/Ansible-Code/try1/roles/ci/files/ci-compose.yml @@ -0,0 +1,34 @@ +version: '2' +services: + jenkins: + image: jenkins + ports: + - "8080:8080" + - "50000:50000" + volumes: + - /home/ubuntu/docker/jenkins_home:/var/jenkins_home + container_name: compose-jenkins + + artifactory: + image: docker.bintray.io/jfrog/artifactory-oss + ports: + - "8081:8081" + volumes: + - /home/ubuntu/docker/artifactory/data:/var/opt/jfrog/artifactory/data + - /home/ubuntu/docker/artifactory/logs:/var/opt/jfrog/artifactory/logs + - /home/ubuntu/docker/artifactory/etc:/var/opt/jfrog/artifactory/etc + container_name: compose-artifactory-oss + sonarqube: + image: sonarqube + ports: + - "9000:9000" + - "9092:9092" + container_name: compose-sonarqube + + tomcat: + image: tomcat + ports: + - "8888:8080" + volumes: + - /home/ubuntu/docker/tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml + container_name: compose-tomcat diff --git a/Ansible-Code/try1/roles/ci/files/tomcat-users.xml b/Ansible-Code/try1/roles/ci/files/tomcat-users.xml new file mode 100644 index 0000000..f6bcedd --- /dev/null +++ b/Ansible-Code/try1/roles/ci/files/tomcat-users.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + diff --git a/Ansible-Code/try1/roles/ci/tasks/ComposeUp.yml b/Ansible-Code/try1/roles/ci/tasks/ComposeUp.yml new file mode 100644 index 0000000..fd94739 --- /dev/null +++ b/Ansible-Code/try1/roles/ci/tasks/ComposeUp.yml @@ -0,0 +1,78 @@ +# This playbook will configure the CI infrastructure +# This is the centralized directory to mount volumes in docker +- name: Create work directory (/home/ubuntu/docker) + file: + name: docker + state: directory +# Jenkins home directory. For reusablity +- name: Create jenkins directory + file: + name: docker/jenkins_home + state: directory + recurse: yes + mode: 0777 +# For storing tomcat-users.xml file +- name: Creat tomcat directory + file: + name: docker/tomcat + state: directory + recurse: yes +- name: Copy tomcat configurations + copy: + src: files/tomcat-users.xml + dest: docker/tomcat/tomcat-users.xml +#- name: Copy Jenkins configurations +# template: +# src: templates/jenkins.xml.j2 +# dest: /home/ubuntu/docker/jenkins_home/config.xml +# owner: ubuntu +# group: ubuntu +# mode: 0777 +# Bring up the infrastructure +- name: Docker compose up +# async: 35 +# poll: 0 +#become: true +#become_user: root + docker_service: + project_name: ci + definition: + version: '2' + services: + jenkins: + image: jenkins:2.19.4-alpine + ports: + - "8080:8080" + - "50000:50000" + volumes: + - "/home/ubuntu/docker/jenkins_home:/var/jenkins_home" + container_name: compose-jenkins + + artifactory: + image: docker.bintray.io/jfrog/artifactory-oss + ports: + - "8081:8081" + volumes: + - /home/ubuntu/docker/artifactory/data:/var/opt/jfrog/artifactory/data + - /home/ubuntu/docker/artifactory/logs:/var/opt/jfrog/artifactory/logs + - /home/ubuntu/docker/artifactory/etc:/var/opt/jfrog/artifactory/etc + container_name: compose-artifactory-oss + + sonarqube: + image: sonarqube + ports: + - "9000:9000" + - "9092:9092" + container_name: compose-sonarqube + + tomcat: + image: tomcat + ports: + - "8888:8080" + volumes: + - /home/ubuntu/docker/tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml + container_name: compose-tomcat + register: test + +- debug: + var: test diff --git a/Ansible-Code/try1/roles/ci/tasks/InstallCompose.yml b/Ansible-Code/try1/roles/ci/tasks/InstallCompose.yml new file mode 100644 index 0000000..16f6a87 --- /dev/null +++ b/Ansible-Code/try1/roles/ci/tasks/InstallCompose.yml @@ -0,0 +1,41 @@ +--- +# Install Docker Engine +- name: Update cache + apt: + update_cache: yes +- name: Install apt-transport-https and ca-certificates + apt: + name: "{{item}}" + state: latest + with_items: + - apt-transport-https + - ca-certificates +- name: Add apt key + apt_key: + keyserver: hkp://ha.pool.sks-keyservers.net:80 + id: 58118E89F3A912897C070ADBF76221572C52609D +- name: Add docker.list + command: echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list +- name: Update apt cache again + apt: + update_cache: yes +- name: Install Docker Engine + apt: + name: docker-engine + state: latest +# command: wget -qO- https://get.docker.com/ | sh +# become: true +# become_user: root +- name: Start Docker Service + service: + name: docker + state: started +# Install Docker Compose +- name: Install python-pip + apt: + name: python-pip + state: latest +- name: Install Docker Compose + pip: + name: docker-compose + state: latest diff --git a/Ansible-Code/try1/roles/ci/tasks/Jenkins.yml b/Ansible-Code/try1/roles/ci/tasks/Jenkins.yml new file mode 100644 index 0000000..61d657d --- /dev/null +++ b/Ansible-Code/try1/roles/ci/tasks/Jenkins.yml @@ -0,0 +1,57 @@ +--- +- name: Create Jenkins group + group: + name: jenkins + state: present +- name: Create Jenkins user + user: + name: jenkins + group: jenkins +- name: Install Build Pipeline Plugin + jenkins_plugin: + name: build-pipeline-plugin + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install Publish Over SSH Plugin + jenkins_plugin: + name: publish-over-ssh + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install SSH Plugin + jenkins_plugin: + name: ssh + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install SonarQube Plugin + jenkins_plugin: + name: sonar + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin + jenkins_plugin: + name: artifactory + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin + jenkins_plugin: + name: git + params: "{{ jenkins_params_plugins }}" +- name: Install jenkins-python (Ansible Dependency) + pip: + name: python-jenkins + state: latest +- name: Install python-lxml (Ansible Dependency) + apt: + name: python-lxml + state: present +- name: Install Docker-py (Ansible Dependency) + pip: + name: docker-py + state: present +- name: Create Build job + jenkins_job: + config: "{{ lookup('template', 'templates/build.xml.j2') }}" + name: build + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_pass }}" diff --git a/Ansible-Code/try1/roles/ci/tasks/Jenkins.yml.bak b/Ansible-Code/try1/roles/ci/tasks/Jenkins.yml.bak new file mode 100644 index 0000000..f54d8ca --- /dev/null +++ b/Ansible-Code/try1/roles/ci/tasks/Jenkins.yml.bak @@ -0,0 +1,153 @@ +--- +- name: Create Jenkins group + group: + name: jenkins + state: present +- name: Create Jenkins user + user: + name: jenkins + group: jenkins +- name: Install Build Pipeline Plugin + jenkins_plugin: + name: build-pipeline-plugin + version: "1.5.6" + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install Build Pipeline Plugin Dependencies + jenkins_plugin: + name: parameterized-trigger + version: "2.17" + params: "{{ jenkins_params_plugins }}" +- name: Install Build Pipeline Plugin Dependencies + jenkins_plugin: + name: jquery + version: "1.11.2-0" + params: "{{ jenkins_params_plugins }}" +- name: Install Publish Over SSH Plugin + jenkins_plugin: + name: publish-over-ssh + version: "1.14" + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install SSH Plugin + jenkins_plugin: + name: ssh + version: "2.4" + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install SonarQube Plugin + jenkins_plugin: + name: sonar + version: "2.5" + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install SonarQube Plugin Dependencies + jenkins_plugin: + name: jquery + version: "1.11.2-0" + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin + jenkins_plugin: + name: artifactory + version: "2.8.2" + with_dependencies: yes + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin Dependencies + jenkins_plugin: + name: ivy + version: "1.17" + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin Dependencies + jenkins_plugin: + name: gradle + version: "1.15" + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin Dependencies + jenkins_plugin: + name: workflow-cps + version: "2.13" + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin Dependencies + jenkins_plugin: + name: credentials + version: "2.1.8" + params: "{{ jenkins_params_plugins }}" +- name: Install Artifactory Plugin Dependencies + jenkins_plugin: + name: workflow-step-api + version: "2.3" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin + jenkins_plugin: + name: git + version: "3.0.1" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: workflow-scm-step + version: "1.14.2" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: git-client + version: "2.1.0" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: mailer + version: "1.18" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: matrix-project + version: "1.7.1" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: promoted-builds + version: "2.27" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: scm-api + version: "1.3" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: ssh-credentials + version: "1.12" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: token-macro + version: "1.12.1" + params: "{{ jenkins_params_plugins }}" +- name: Install Git Plugin Dependencies + jenkins_plugin: + name: credentials + version: "2.1.8" + params: "{{ jenkins_params_plugins }}" +- name: Install jenkins-python (Ansible Dependency) + pip: + name: python-jenkins + state: latest +- name: Install python-lxml (Ansible Dependency) + apt: + name: python-lxml + state: present +- name: Install Docker-py (Ansible Dependency) + pip: + name: docker-py + state: present +#- name: Restart jenkins +# docker_container: +# name: compose-jenkins +# restart: yes +- name: Create Build job + jenkins_job: + config: "{{ lookup('template', 'templates/build.xml.j2') }}" + name: build + url: "{{ jenkins_url }}" + user: "{{ jenkins_user }}" + password: "{{ jenkins_pass }}" +# token: "{{ jenkins_token }}" diff --git a/Ansible-Code/try1/roles/ci/tasks/docker.yml b/Ansible-Code/try1/roles/ci/tasks/docker.yml new file mode 100644 index 0000000..a7b164f --- /dev/null +++ b/Ansible-Code/try1/roles/ci/tasks/docker.yml @@ -0,0 +1,2 @@ +--- +- name: diff --git a/Ansible-Code/try1/roles/ci/tasks/main.yml b/Ansible-Code/try1/roles/ci/tasks/main.yml new file mode 100644 index 0000000..e858ef7 --- /dev/null +++ b/Ansible-Code/try1/roles/ci/tasks/main.yml @@ -0,0 +1,4 @@ +--- +#- include: InstallCompose.yml +- include: ComposeUp.yml +- include: Jenkins.yml diff --git a/Ansible-Code/try1/roles/ci/templates/build.xml.j2 b/Ansible-Code/try1/roles/ci/templates/build.xml.j2 new file mode 100644 index 0000000..dafb98b --- /dev/null +++ b/Ansible-Code/try1/roles/ci/templates/build.xml.j2 @@ -0,0 +1,177 @@ + + + + + false + + + 2 + + + https://github.com/schoolofdevops/demo.git + + + + + */master + + + false + + + + true + false + false + false + + + H/2 * * * * + false + + + false + + CMADSession + CMADSession + + install + true + false + true + false + false + false + false + false + false + -1 + false + false + true + + + + + + Test + + SUCCESS + 0 + BLUE + true + + + + false +
+ Artifactory + http://192.168.0.73:8081/artifactory + + + libs-release-local + false + + + + libs-snapshot-local + false + + + None + + None +
+ true + + + + + + + + + + + false + false + + true + + + *password*,*secret*,*key* + + false + + false + false + + true + false + false + true + + false + false + false + true + false + + true + false + false + + + + + false + true + true +
+
+ + + + REL-BRANCH- + + + GLOBAL + + true + + +
+ Artifactory + http://192.168.0.73:8081/artifactory + + + libs-snapshot + false + + + + libs-release + false + + +
+ + + admin + MW5pdENyMG4= + + + false + false + +
+
+ + + + FAILURE + 2 + RED + true + +
diff --git a/Ansible-Code/try1/roles/ci/templates/hudson.plugins.copyartifact.TriggeredBuildSelector.xml.j2 b/Ansible-Code/try1/roles/ci/templates/hudson.plugins.copyartifact.TriggeredBuildSelector.xml.j2 new file mode 100644 index 0000000..e69de29 diff --git a/Ansible-Code/try1/roles/ci/templates/jenkins.xml.j2 b/Ansible-Code/try1/roles/ci/templates/jenkins.xml.j2 new file mode 100644 index 0000000..55aad8d --- /dev/null +++ b/Ansible-Code/try1/roles/ci/templates/jenkins.xml.j2 @@ -0,0 +1,81 @@ + + + + hudson.diagnosis.ReverseProxySetupMonitor + + 2.19.1 + 2 + NORMAL + true + + + false + false + + false + + ${JENKINS_HOME}/workspace/${ITEM_FULLNAME} + ${ITEM_ROOTDIR}/builds + + + + JAVA JDK + + + + + + jdk-8u112-oth-JPR + true + + + + + + + + + + 5 + 0 + + + + All + false + false + + + + + DevOps Demo + Pipeline for DevOps Demo Project + false + false + + + Build-Maven + job/Build-Maven/ + + 5 + + Lightbox + + false + false + false + false + false + 3 + false + + + All + 50000 + + + false + + + + diff --git a/Ansible-Code/try1/roles/ci/templates/org.jfrog.hudson.ArtifactoryBuilder.xml.j2 b/Ansible-Code/try1/roles/ci/templates/org.jfrog.hudson.ArtifactoryBuilder.xml.j2 new file mode 100644 index 0000000..cbbacf1 --- /dev/null +++ b/Ansible-Code/try1/roles/ci/templates/org.jfrog.hudson.ArtifactoryBuilder.xml.j2 @@ -0,0 +1,25 @@ + + + false + + + http://192.168.0.73:8081/artifactory + Artifactory + 300 + false + + + admin + cGFzc3dvcmQ= + + + false + false + + + + true + false + 0 + /var/jenkins_home/secrets/jfrog/certs/jfrog.proxy.crt + /var/jenkins_home/secrets/jfrog/certs/jfrog.proxy.key diff --git a/Ansible-Code/try1/roles/ci/vars/main.yml b/Ansible-Code/try1/roles/ci/vars/main.yml new file mode 100644 index 0000000..8499271 --- /dev/null +++ b/Ansible-Code/try1/roles/ci/vars/main.yml @@ -0,0 +1,12 @@ +--- +jenkins_url: http://192.168.0.73:8080 +jenkins_user: admin +jenkins_pass: 1nitCr0n +jenkins_token: ff8b7b71bd5e926830bf948d6d3a0900 + +jenkins_params_plugins: + url: http://192.168.0.73:8080 + url_username: admin + url_password: 1nitCr0n + jenkins_home: /home/ubuntu/docker/jenkins_home + validate_certs: False diff --git a/Ansible-Code/try1/roles/monitoring/README.md b/Ansible-Code/try1/roles/monitoring/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Ansible-Code/try1/roles/registryman/README.md b/Ansible-Code/try1/roles/registryman/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Ansible-Code/try1/roles/worker/README.md b/Ansible-Code/try1/roles/worker/README.md new file mode 100644 index 0000000..e69de29 diff --git a/CI/Docker/Ansible-Deploy/deploy.retry b/CI/Docker/Ansible-Deploy/deploy.retry new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/CI/Docker/Ansible-Deploy/deploy.retry @@ -0,0 +1 @@ +localhost diff --git a/CI/Docker/Ansible-Deploy/deploy.yml b/CI/Docker/Ansible-Deploy/deploy.yml new file mode 100644 index 0000000..5073b8b --- /dev/null +++ b/CI/Docker/Ansible-Deploy/deploy.yml @@ -0,0 +1,14 @@ +--- +- hosts: localhost + tasks: + - name: Get the artifact from Jenkins + get_url: + url: http://192.168.0.62:8080/job/Package/lastSuccessfulBuild/CMADSession$CMADSession/artifact/CMADSession/CMADSession/0.0.12-SNAPSHOT/CMADSession-0.0.12-SNAPSHOT.war + url_username: admin + url_password: admin + force_basic_auth: yes + dest: /tmp/cmad.war + mode: 0755 + - name: Deploy the application + shell: curl -T "/tmp/cmad.war" "http://admin:password@192.168.0.62:8888/manager/text/deploy?path=/cmad&update=true" + diff --git a/CI/Docker/Jenkins-Image/Jenkinsfile b/CI/Docker/Jenkins-Image/Jenkinsfile new file mode 100644 index 0000000..dde5d32 --- /dev/null +++ b/CI/Docker/Jenkins-Image/Jenkinsfile @@ -0,0 +1,14 @@ +FROM jenkins:2.19.4 + +MAINTAINER vijayboopathy + +USER root + +RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 && \ + echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" >> /etc/apt/sources.list && \ + apt-get update && \ + apt-get -y install ansible + +USER jenkins + +ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"] diff --git a/CI/Docker/Jenkins-Image/sources.list b/CI/Docker/Jenkins-Image/sources.list new file mode 100644 index 0000000..3ebd328 --- /dev/null +++ b/CI/Docker/Jenkins-Image/sources.list @@ -0,0 +1 @@ +deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main diff --git a/CI/Docker/docker-compose.yml b/CI/Docker/docker-compose.yml new file mode 100644 index 0000000..0f73bfb --- /dev/null +++ b/CI/Docker/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3' +services: + jenkins: + image: schoolofdevops/jenkins_ansible + ports: + - "8080:8080" + - "50000:50000" + volumes: + - ./volumes/jenkins/playbooks/deploy.yml:/var/jenkins_home/playbooks/deploy.yml + container_name: jenkins + + artifactory: + image: docker.bintray.io/jfrog/artifactory-oss + ports: + - "8081:8081" + container_name: artifactory + + sonarqube: + image: sonarqube + ports: + - "9000:9000" + - "9092:9092" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + container_name: sonarqube + + tomcat: + image: tomcat + ports: + - "8888:8080" + volumes: + - /home/ubuntu/devops-demos/CI/Docker/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml + container_name: tomcat diff --git a/CI/Docker/tomcat-users.xml b/CI/Docker/tomcat-users.xml new file mode 100644 index 0000000..ff93bb5 --- /dev/null +++ b/CI/Docker/tomcat-users.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/CI/Scripts/Docker_Installation.sh b/CI/Scripts/Docker_Installation.sh new file mode 100644 index 0000000..034a8df --- /dev/null +++ b/CI/Scripts/Docker_Installation.sh @@ -0,0 +1,24 @@ +# Install Docker on Ubuntu 14.04.4 x64 +# Ref https://docs.docker.com/engine/installation/linux/ubuntulinux/ +# No interactive for now. +export DEBIAN_FRONTEND=noninteractive +# Update your APT package index. +sudo apt-get -y update +# Update package information, ensure that APT works with the https method, and that CA certificates are installed. +sudo apt-get -y install apt-transport-https ca-certificates +# Add the new GPG key. +sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D +# Add docker.list +sudo echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list +# Update your APT package index. +sudo apt-get -y update +# Verify that APT is pulling from the right repository. +sudo apt-cache policy docker-engine +# Install the recommended package. +sudo apt-get -y install linux-image-extra-$(uname -r) +# Install Docker. +sudo apt-get -y install docker-engine +# Start the docker daemon. +sudo service docker start +# Validate docker version +docker -v diff --git a/CI/Scripts/Docker_compose_installtion.sh b/CI/Scripts/Docker_compose_installtion.sh new file mode 100644 index 0000000..7700026 --- /dev/null +++ b/CI/Scripts/Docker_compose_installtion.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Update apt repo +sudo apt update + +# Install python pip +sudo apt install python-pip -y + +# Install Docker Compose +sudo pip install docker-compose -y diff --git a/CI/Scripts/Elk_Script.sh b/CI/Scripts/Elk_Script.sh new file mode 100644 index 0000000..457174a --- /dev/null +++ b/CI/Scripts/Elk_Script.sh @@ -0,0 +1,11 @@ +#!/bin/bash +apt install git +cd /home/ubuntu +if ls 2> /dev/null | grep -q -i "docker-elk"; then + echo "ELK repo is already cloned" +else + git clone https://github.com/deviantony/docker-elk.git +fi +cd /home/ubuntu/docker-elk +sysctl -w vm.max_map_count=262144 +docker-compose up -d diff --git a/CI/Scripts/Prometheus.sh b/CI/Scripts/Prometheus.sh new file mode 100644 index 0000000..8e1b3bf --- /dev/null +++ b/CI/Scripts/Prometheus.sh @@ -0,0 +1,11 @@ +#!/bin/bash +apt install git -y +cd /home/ubuntu +if ls 2> /dev/null | grep -q -i "prometheus"; then + echo "Prometheus repo is already cloned" +else + git clone https://github.com/vegasbrianc/prometheus.git +fi +cd /home/ubuntu/prometheus +docker-compose up -d + diff --git a/CI/Scripts/Swarm_Start.sh b/CI/Scripts/Swarm_Start.sh new file mode 100644 index 0000000..ab48bdd --- /dev/null +++ b/CI/Scripts/Swarm_Start.sh @@ -0,0 +1,13 @@ +if docker service ls 2> /dev/null | grep -q -i "tomapp"; then + echo "Service is already running" +else +# docker service create --replicas 6 --publish 8080:8080 --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.53:5000 --name tomapp initcronregistry.org/tomcatapp + docker service create --replicas 3 --publish 8080:8080 --log-driver=syslog --log-opt syslog-address=tcp://192.168.0.56:5000 --name tomapp initcronregistry.org/tomcatapp + +fi + +#if docker service ls 2> /dev/null | grep -q -i "cadvisor"; then +# echo "Service is already running" +#else +# docker service create --replicas 3 --publish=9090:8080 --name cadvisor google/cadvisor +#fi diff --git a/CI/Scripts/image.sh b/CI/Scripts/image.sh new file mode 100644 index 0000000..377b291 --- /dev/null +++ b/CI/Scripts/image.sh @@ -0,0 +1,23 @@ +#!/bin/bash +cd /docker/jenkins_home/ +docker build -t tomcatapp . +#Username and Password for local docker registry +USER="admin" +PASS="1nitCr0n" +#Start of expect script +expect <