Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create manuela-dev repo in gitea #295

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions ansible/playbooks/clone_upstream_repos_gitea.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Industrial repo cloning
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Fail if any needed parameter is undefined
ansible.builtin.assert:
that:
- repo_name is defined
- upstream_repo_url is defined

- name: Find needed route
ansible.builtin.shell: |
oc get routes -n vp-gitea gitea-route -o jsonpath='{.spec.host}'
register: route_raw

- name: Find gitea_admin username
ansible.builtin.shell: |
oc extract -n vp-gitea secret/gitea-admin-secret --to=- --keys=username 2>/dev/null
register: gitea_username_raw

- name: Find gitea_admin password
ansible.builtin.shell: |
oc extract -n vp-gitea secret/gitea-admin-secret --to=- --keys=password 2>/dev/null
register: gitea_password_raw

- name: Set some basic facts
ansible.builtin.set_fact:
gitea_route: "https://{{ route_raw.stdout }}"
gitea_username: "{{ gitea_username_raw.stdout }}"
gitea_password: "{{ gitea_password_raw.stdout }}"

- name: Set some more route facts
ansible.builtin.set_fact:
gitea_repos_route: "{{ gitea_route }}/api/v1/repos/{{ gitea_username }}/{{ repo_name }}"
gitea_migrate_route: "{{ gitea_route }}/api/v1/repos/migrate"

- name: Does repo already exist
ansible.builtin.uri:
url: "{{ gitea_repos_route }}"
register: repo_exists
failed_when: false

- name: If the repo already exists then stop here
ansible.builtin.meta: end_play
when: repo_exists.status == 200

- name: Migrate repository
ansible.builtin.uri:
url: "{{ gitea_migrate_route }}"
user: "{{ gitea_username }}"
password: "{{ gitea_password }}"
force_basic_auth: true
method: POST
body_format: json
body: "{ \"repo_name\": \"{{ repo_name }}\", \"clone_addr\": \"{{ upstream_repo_url }}\" }"
return_content: true
status_code: [201]
12 changes: 12 additions & 0 deletions values-datacenter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ clusterGroup:
# repoURL: https://github.com/vendor/applications.git
# targetRevision: main

imperative:
# For additional overrides that apply to the jobs, please refer to
# https://github.com/validatedpatterns/clustergroup-chart/
# schedule: "*/10 * * * *" # Default schedule
jobs:
- name: clone-upstream-repos-gitea
playbook: ./ansible/playbooks/clone_upstream_repos_gitea.yml
extravars:
- "repo_name=manuela-dev"
- "upstream_repo_url=https://github.com/validatedpatterns-demos/manuela-dev"
timeout: 180

managedClusterGroups:
factory:
name: factory
Expand Down