Git initial commit

This commit is contained in:
Lars Hahn 2023-08-20 10:30:47 +02:00
commit 8538aa5f36
8 changed files with 186 additions and 0 deletions

9
LICENSE Executable file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
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.

3
README.md Executable file
View File

@ -0,0 +1,3 @@
# cloud-gocd
Ansible role to provide GoCD as an alternative to Jenkins for CI/CD.

24
defaults/main.yml Executable file
View File

@ -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!

5
handlers/main.yml Executable file
View File

@ -0,0 +1,5 @@
---
- name: restart gocd
systemd:
name: gocd
state: restarted

17
meta/main.yml Executable file
View File

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

104
tasks/main.yml Executable file
View File

@ -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*)<artifactsDir>(.*)</artifactsDir>$'
line: '\1<artifactsDir>{{ gocd_artifact_location }}</artifactsDir>'
backrefs: yes
notify: restart gocd

View File

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

9
vars/main.yml Executable file
View File

@ -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 }}"