diff --git a/data/ansible/fedora_copr_server/copr-hooks.service.j2 b/data/ansible/fedora_copr_server/copr-hooks.service.j2 new file mode 100644 index 000000000..6990d6831 --- /dev/null +++ b/data/ansible/fedora_copr_server/copr-hooks.service.j2 @@ -0,0 +1,16 @@ +{{ ansible_managed | comment }} +[Unit] +Description=Copr Custom Webhook Server +ConditionPathExists={{ copr_hooks_dir }} +After=network.target +[Service] +Environment="V10={{ v10 }}" "MASTER={{ nightly }}" +ExecStart=/usr/local/bin/copr-hooks-server +Restart=on-failure +RestartSec=10 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier={{ service_name }} +[Install] +WantedBy=multi-user.target + diff --git a/data/ansible/fedora_copr_server/coprhooks.conf.j2 b/data/ansible/fedora_copr_server/coprhooks.conf.j2 new file mode 100644 index 000000000..b01702bce --- /dev/null +++ b/data/ansible/fedora_copr_server/coprhooks.conf.j2 @@ -0,0 +1,3 @@ +{{ ansible_managed | comment }} +if $programname == '{{ service_name }}' then /var/log/{{ service_name }}/output.log +& stop \ No newline at end of file diff --git a/data/ansible/fedora_copr_server/go.yaml b/data/ansible/fedora_copr_server/go.yaml new file mode 100644 index 000000000..5e8552197 --- /dev/null +++ b/data/ansible/fedora_copr_server/go.yaml @@ -0,0 +1,122 @@ +--- +- name: create gopath directory + file: + state: directory + mode: 'u=rwx,go=rx' + dest: '{{ golang_gopath }}' + +- name: create download directory + file: + state: directory + mode: 'u=rwx,go=rx' + dest: '{{ golang_download_dir }}' + +- name: Register the current Go version (if any) + command: /usr/local/go/bin/go version + ignore_errors: yes + register: go_version + changed_when: false + +- name: Remove old installation of Go + become: yes + file: + path: /usr/local/go + state: absent + when: go_version is false or go_version.stdout != go_version_target + +- name: download Go language SDK + get_url: + url: '{{ golang_mirror }}/{{ golang_redis_filename }}' + dest: '{{ golang_download_dir }}/{{ golang_redis_filename }}' + mode: 'u=rw,go=r' + +- name: create Go language SDK installation directory + become: yes + file: + state: directory + owner: root + group: root + mode: 'u=rwx,go=rx' + dest: '{{ golang_install_dir }}' + +- name: install Go language SDK + become: yes + unarchive: + src: '{{ golang_download_dir }}/{{ golang_redis_filename }}' + remote_src: yes + extra_opts: '--strip-components=1' + dest: '{{ golang_install_dir }}' + owner: root + group: root + creates: '{{ golang_install_dir }}/bin' + +# Set Go language SDK environment variables +- name: make sure /etc/profile.d exists + become: yes + file: + path: /etc/profile.d + state: directory + owner: root + group: root + mode: 'u=rwx,go=rx' + +- name: export Go language SDK environment variables + become: yes + template: + src: golang.sh.j2 + dest: /etc/profile.d/golang.sh + owner: root + group: root + mode: 'u=rw,go=r' + +- name: Export GOROOT for root + become: yes + lineinfile: + path: ~/.bashrc + line: export GOROOT='{{ golang_install_dir }}' + insertafter: last + +- name: Add GOROOT to PATH for root + become: yes + lineinfile: + dest: ~/.bashrc + line: export PATH=$PATH:$GOROOT/bin + insertafter: last + +- name: Export GOPATH for root + become: yes + lineinfile: + dest: ~/.bashrc + line: export GOPATH='{{ golang_gopath }}' + insertafter: last + +- name: Add GOPATH to PATH for root + become: yes + lineinfile: + dest: ~/.bashrc + line: export PATH=$PATH:$GOPATH/bin + insertafter: last + +- name: Export GOROOT + lineinfile: + dest: ~/.bashrc + line: export GOROOT='{{ golang_install_dir }}' + insertafter: last + +- name: Add GOROOT to PATH + lineinfile: + dest: ~/.bashrc + line: export PATH=$PATH:$GOROOT/bin + insertafter: last + +- name: Export GOPATH + lineinfile: + dest: ~/.bashrc + line: export GOPATH='{{ golang_gopath }}' + insertafter: last + +- name: Add GOPATH to PATH + lineinfile: + dest: ~/.bashrc + line: export PATH=$PATH:$GOPATH/bin + insertafter: last \ No newline at end of file diff --git a/data/ansible/fedora_copr_server/golang.sh.j2 b/data/ansible/fedora_copr_server/golang.sh.j2 new file mode 100644 index 000000000..7bfc41c2e --- /dev/null +++ b/data/ansible/fedora_copr_server/golang.sh.j2 @@ -0,0 +1,12 @@ + +#!/bin/sh + +{{ ansible_managed | comment('plain') }} + +export GOROOT='{{ golang_install_dir }}' +export PATH=$PATH:$GOROOT/bin + +{% if golang_gopath not in (None, '') %} +export GOPATH="{{ golang_gopath }}" +export PATH=$PATH:$GOPATH/bin +{% endif %} \ No newline at end of file diff --git a/data/ansible/fedora_copr_server/main.yaml b/data/ansible/fedora_copr_server/main.yaml new file mode 100644 index 000000000..25b74889f --- /dev/null +++ b/data/ansible/fedora_copr_server/main.yaml @@ -0,0 +1,112 @@ + +- hosts: pkg + vars: + # Go language SDK version number + golang_version: '1.19.2' + go_version_target: "go version go{{ golang_version }} linux/amd64" + # Mirror to download the Go language SDK redistributable package from + golang_mirror: 'https://storage.googleapis.com/golang' + # Base installation directory the Go language SDK distribution + golang_install_dir: '/usr/local/go' + # Directory to store files downloaded for Go language SDK installation + golang_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}" + # Location for GOPATH environment variable + golang_gopath: "/home/{{ user }}/go" + # Filename of Go language SDK redistributable package + golang_redis_filename: 'go{{ golang_version }}.linux-amd64.tar.gz' + + copr_hooks_dir: "/home/{{ user }}/go/src/github.com/copr-hooks" + copr_hook_bin: "{{ golang_gopath }}/bin/copr-hooks-server" + service_name: coprhooks + + tasks: + + - name: Install dependencies + become: yes + apt: + name: + - git + - tar + state: present + - name: Install golang + include: go.yaml + + - name: Create copr-hooks directory + become: yes + file: + state: directory + mode: 'u=rwx,go=rx' + owner: "{{ user }}" + group: "{{ user }}" + dest: '{{ copr_hooks_dir }}' + become_user: "{{ user }}" + + - name: Clone Copr-Webhooks from github repository + git: + repo: https://github.com/gezimbll/Copr-WebHook.git + dest: '{{ copr_hooks_dir }}' + update: yes + force: yes + become: yes + + + - name: Install copr-hooks + shell: "go install copr-hooks-server.go" + environment: + PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" + args: + chdir: '{{ copr_hooks_dir }}' + + + - name: Copy copr-hooks to system executable + become: yes + copy: + src: "{{ copr_hook_bin }}" + remote_src: true + dest: "/usr/local/bin" + unsafe_writes: yes + + - name: Changing the permissions + become: yes + file: + path: /usr/local/bin/copr-hooks-server + owner: root + mode: 0755 + + - name: Create the service file + become: yes + template: + src: copr-hooks.service.j2 + dest: /etc/systemd/system/copr-hooks.service + + - name: Reload daemon and start the service + become: yes + ansible.builtin.systemd: + state: started + daemon_reload: true + name: copr-hooks.service + enabled: true + + - name: Create directory for reading logs + become: yes + file: + path: /var/log/{{ service_name }} + state: directory + + - name: Change log file permissions + become: yes + file: + path: /var/log/{{ service_name }} + owner: '{{ user }}' + group: '{{ user }}' + state: directory + + - name: Create the log file + become: yes + template: + src: coprhooks.conf.j2 + dest: /etc/rsyslog.d/coprhooks.conf + + - name: Restart rsyslog + become: yes + shell: "systemctl restart rsyslog.service"