commit 8538aa5f36ce61a44d9ff89fe4cba50547a80d38 Author: lhahn Date: Sun Aug 20 10:30:47 2023 +0200 Git initial commit diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..5f9e5b6 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# cloud-gocd + +Ansible role to provide GoCD as an alternative to Jenkins for CI/CD. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..165be45 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,24 @@ +--- +cloud_apps: /opt +cloud_storage: /opt/storage +cloud_stage: prod +cloud_update: false + +java_home: "{{ cloud_apps }}/java_jdk/java" + +www_group: www-data + + +gocd_version: 22.1.0 +gocd_build: 13913 + +gocd_source: "https://download.gocd.org/binaries/{{ gocd_version }}-{{ gocd_build }}/generic" +gocd_file: "go-server-{{ gocd_version }}-{{ gocd_build }}.zip" + +gocd_artifact_location: "{{ cloud_storage }}/gocd/gocd-artifacts" + +gocd_java_home: "{{ java_home }}" +gocd_java_xmx: 4G + +gocd_admin_user: gocd_admin +gocd_admin_pass: VerySecurePasswrd! diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100755 index 0000000..cb5467e --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart gocd + systemd: + name: gocd + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100755 index 0000000..f8e5fa5 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,17 @@ +--- +galaxy_info: + role_name: gocd + namespace: hahn-cloud + author: Lars Hahn + company: OpenDevChain + license: MIT + description: Role to setup GoCD for CI/CD + min_ansible_version: 2.7 + platforms: + - name: Debian + versions: + - 11 + galaxy_tags: + - gocd +dependencies: + - java diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100755 index 0000000..fbe8b10 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,104 @@ +--- +- name: install GoCD recommendations + apt: + update_cache: yes + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + pkg: + - "unzip" + - "apache2-utils" + - "python3-passlib" + +- name: setup GoCD group + group: + name: "{{ gocd_usr }}" + state: "present" + +- name: setup Gocd user + user: + name: "{{ gocd_usr }}" + group: "{{ gocd_grp }}" + groups: + - "{{ gocd_grp }}" + comment: Virtual GocD User + shell: /sbin/nologin + state: present + system: yes + +- name: setup GoCD directories + file: + state: directory + path: "{{ item }}" + owner: "{{ gocd_usr }}" + group: "{{ gocd_grp }}" + mode: 0750 + loop: + - "{{ gocd_main }}" + - "{{ gocd_data }}" + - "{{ gocd_home }}" + +- name: setup GoCD admin + htpasswd: + path: "{{ gocd_home }}/passwd.properties" + name: "{{ gocd_admin_user }}" + password: "{{ gocd_admin_pass }}" + owner: root + group: "{{ gocd_grp }}" + mode: 0640 + +- name: download GoCD and unarchive + unarchive: + src: "{{ gocd_source }}/{{ gocd_file }}" + dest: "{{ gocd_main }}" + remote_src: yes + owner: "{{ gocd_usr }}" + group: "{{ gocd_grp }}" + mode: "o=" + creates: "{{ gocd_inst }}" + register: gocd_installation + +- name: configure GoCD wrapper properties + lineinfile: + path: "{{ gocd_inst }}/wrapper-config/wrapper-properties.conf" + regexp: "^(#\\s*|){{ item.key }}=" + line: "{{ item.key }}={{item.value}}" + loop: + - key: wrapper.java.command + value: "{{ gocd_java_home }}/bin/java" + - key: wrapper.java.additional.105 + value: "-Xmx{{ gocd_java_xmx }}" + +- name: link installation dir + file: + state: link + src: "{{ gocd_inst }}" + dest: "{{ gocd_link }}" + owner: "{{ gocd_usr }}" + group: "{{ gocd_grp }}" + +- name: setup GoCD systemd unit + template: + src: etc/systemd/system/gocd.service.j2 + dest: /etc/systemd/system/gocd.service + notify: restart gocd + +- name: enable gocd systemd unit + systemd: + name: gocd + enabled: yes + daemon_reload: yes + state: started + +- name: Wait for GoCD to be started in order to configure artifact store + wait_for: + port: 8153 + delay: 10 + when: gocd_installation.changed + +- name: configure GoCD config after config setup by server + lineinfile: + path: "{{ gocd_inst }}/config/cruise-config.xml" + regexp: '^(\s*)(.*)$' + line: '\1{{ gocd_artifact_location }}' + backrefs: yes + notify: restart gocd diff --git a/templates/etc/systemd/system/gocd.service.j2 b/templates/etc/systemd/system/gocd.service.j2 new file mode 100755 index 0000000..13c00f6 --- /dev/null +++ b/templates/etc/systemd/system/gocd.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=go-server +After=syslog.target + +[Service] +Type=forking +ExecStart={{ gocd_link }}/bin/go-server start sysd +ExecStop={{ gocd_link }}/bin/go-server stop sysd +User={{ gocd_usr }} +Group={{ gocd_grp }} +KillMode=control-group +Environment=SYSTEMD_KILLMODE_WARNING=true + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100755 index 0000000..4d56c3e --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,9 @@ +--- +gocd_main: "{{ cloud_apps }}/gocd" +gocd_inst: "{{ gocd_main }}/go-server-{{ gocd_version }}" +gocd_link: "{{ gocd_main }}/inst" +gocd_home: "{{ gocd_main }}/home" +gocd_data: "{{ gocd_artifact_location }}" + +gocd_usr: gocd +gocd_grp: "{{ gocd_usr }}"