Merge "Create git repos on gitea servers before gerrit"
This commit is contained in:
commit
cd9f48431a
@ -20,6 +20,14 @@
|
||||
facts:
|
||||
project_config_ref: "{{ hostvars.localhost.gitinfo.after }}"
|
||||
|
||||
- hosts: "gitea:!disabled"
|
||||
name: "Create repos on gitea servers"
|
||||
strategy: free
|
||||
max_fail_percentage: 1
|
||||
roles:
|
||||
- role: gitea-git-repos
|
||||
project_config_ref: "{{ hostvars.localhost.gitinfo.after }}"
|
||||
|
||||
- hosts: "review:!disabled"
|
||||
name: "Puppet-git: Run puppet on the Gerrit server"
|
||||
strategy: free
|
||||
|
1
playbooks/roles/gitea-git-repos/README.rst
Normal file
1
playbooks/roles/gitea-git-repos/README.rst
Normal file
@ -0,0 +1 @@
|
||||
Create git repos on a gitea server
|
3
playbooks/roles/gitea-git-repos/defaults/main.yaml
Normal file
3
playbooks/roles/gitea-git-repos/defaults/main.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
gitea_url: https://localhost:3000
|
||||
project_config_ref: master
|
||||
project_config_dest: /tmp/project_config
|
37
playbooks/roles/gitea-git-repos/tasks/main.yaml
Normal file
37
playbooks/roles/gitea-git-repos/tasks/main.yaml
Normal file
@ -0,0 +1,37 @@
|
||||
- name: Clone project-config
|
||||
git:
|
||||
repo: https://git.openstack.org/openstack-infra/project-config
|
||||
dest: "{{ project_config_dest }}"
|
||||
version: "{{ project_config_ref }}"
|
||||
- name: Get Gerrit project list
|
||||
set_fact:
|
||||
gerrit_projects: "{{ lookup('file', project_config_dest + '/gerrit/projects.yaml') | from_yaml }}"
|
||||
- name: Parse Gerrit org list
|
||||
set_fact:
|
||||
gerrit_orgs: "{{ gerrit_projects | map(attribute='project') | map('regex_search', '^(.*?)/') | list | unique | select | map('regex_replace', '/', '') | list }}"
|
||||
- name: debug
|
||||
debug:
|
||||
msg: "{{ gerrit_orgs }}"
|
||||
- name: Get Gitea org list
|
||||
# We assume that all the orgs we are interested in are owned by root
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/user/orgs"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 200
|
||||
register: gitea_org_list
|
||||
- name: Parse Gitea org list
|
||||
set_fact:
|
||||
gitea_orgs: "{{ gitea_org_list.json | map(attribute='username') | list }}"
|
||||
- name: Create orgs
|
||||
loop: "{{ gerrit_orgs }}"
|
||||
loop_control:
|
||||
loop_var: org
|
||||
include_tasks: 'setup-org.yaml'
|
||||
- name: Create repos
|
||||
loop: "{{ gerrit_projects }}"
|
||||
loop_control:
|
||||
loop_var: project
|
||||
include_tasks: 'setup-repo.yaml'
|
56
playbooks/roles/gitea-git-repos/tasks/setup-org.yaml
Normal file
56
playbooks/roles/gitea-git-repos/tasks/setup-org.yaml
Normal file
@ -0,0 +1,56 @@
|
||||
- name: Process org
|
||||
debug:
|
||||
msg: "Processing org {{ org }}"
|
||||
- name: Create org
|
||||
when: org not in gitea_orgs
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/admin/users/root/orgs"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 201
|
||||
method: POST
|
||||
body_format: json
|
||||
body:
|
||||
username: "{{ org }}"
|
||||
- name: Get org team list
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/orgs/{{ org }}/teams"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 200
|
||||
register: gitea_org_team_list
|
||||
- name: Get org owners
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/teams/{{ (gitea_org_team_list.json | selectattr('name', 'equalto', 'Owners') | list)[0]['id'] }}/members"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 200
|
||||
register: gitea_org_members
|
||||
- name: Add Gerrit user to org
|
||||
when: "'gerrit' not in gitea_org_members.json | map(attribute='username')"
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/teams/{{ (gitea_org_team_list.json | selectattr('name', 'equalto', 'Owners') | list)[0]['id'] }}/members/gerrit"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 204
|
||||
method: PUT
|
||||
- name: Get org repo list
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/orgs/{{ org }}/repos"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 200
|
||||
register: gitea_org_repo_list
|
||||
- name: Parse org repo list
|
||||
set_fact:
|
||||
gitea_org_repos: "{{ gitea_org_repo_list.json | map(attribute='name') | list }}"
|
41
playbooks/roles/gitea-git-repos/tasks/setup-repo.yaml
Normal file
41
playbooks/roles/gitea-git-repos/tasks/setup-repo.yaml
Normal file
@ -0,0 +1,41 @@
|
||||
- name: debug
|
||||
debug:
|
||||
msg: "{{ project }}"
|
||||
- name: Parse project name
|
||||
set_fact:
|
||||
org: "{{ project.project | regex_replace('^(.*)/(.*)$', '\\1') }}"
|
||||
repo: "{{ project.project | regex_replace('^(.*)/(.*)$', '\\2') }}"
|
||||
- name: Create repo
|
||||
when: repo not in gitea_org_repos
|
||||
uri:
|
||||
url: "{{ gitea_url }}/api/v1/org/{{ org }}/repos"
|
||||
user: root
|
||||
password: "{{ gitea_root_password }}"
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
status_code: 201
|
||||
method: POST
|
||||
body_format: json
|
||||
body:
|
||||
auto_init: false
|
||||
description: "{{ project.description | default('') }}"
|
||||
name: "{{ repo }}"
|
||||
private: false
|
||||
register: create_repo_result
|
||||
- name: Get created repo id
|
||||
when: "create_repo_result.json is defined"
|
||||
set_fact:
|
||||
repo_id: "{{ create_repo_result.json['id'] }}"
|
||||
- name: Prepare sql query
|
||||
when: "repo_id is defined"
|
||||
set_fact:
|
||||
sql_statement: |
|
||||
start transaction;
|
||||
delete from repo_unit where repo_id = {{ repo_id }} and `type` in (2, 3, 5, 7);
|
||||
insert into repo_unit (repo_id, `type`, config, created_unix) values ({{ repo_id }}, 7, "{""ExternalTrackerURL"":""https://storyboard.openstack.org/#!/project/{{ org }}/{{ repo }}"",""ExternalTrackerFormat"":""https://storyboard.openstack.org/#!/story/{index}"",""ExternalTrackerStyle"":""""}", unix_timestamp());
|
||||
commit;
|
||||
- name: Adjust repo settings
|
||||
when: "sql_statement is defined"
|
||||
become: true
|
||||
command: |
|
||||
docker exec giteadocker_mariadb_1 bash -c 'mysql --password="$MYSQL_ROOT_PASSWORD" -e "{{ sql_statement }}" gitea'
|
Loading…
Reference in New Issue
Block a user