summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-05-13 17:16:34 +0300
committerLars Wirzenius <liw@liw.fi>2021-05-13 17:16:34 +0300
commit9acbe58646ea92cf63070df4bd9a7aa3f0cdfb13 (patch)
treeeeda6d4f8cdcb130d743273d62266418ff2c9629
parente479b2862228b2faf68896da48571307c9211779 (diff)
downloadansibleness-9acbe58646ea92cf63070df4bd9a7aa3f0cdfb13.tar.gz
move mirror-git from Hetzner to local, and automatically clone repos
-rw-r--r--ansible/files/mirror-git.sh67
-rw-r--r--ansible/files/mirror-list17
-rw-r--r--ansible/hosts2
-rw-r--r--ansible/mirror-git.vm.liw.fi.hz5
-rw-r--r--ansible/mirror-git.vm.liw.fi.yml118
-rw-r--r--ansible/mirror-git.yml65
6 files changed, 151 insertions, 123 deletions
diff --git a/ansible/files/mirror-git.sh b/ansible/files/mirror-git.sh
new file mode 100644
index 0000000..be52661
--- /dev/null
+++ b/ansible/files/mirror-git.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+LIST=/etc/mirror-git.list
+# LIST=mirror-list
+
+set -euo pipefail
+
+die() {
+ echo "$@" 1>&2
+ exit 1
+}
+
+setup_clone() {
+ local dir="$1"
+ local fromurl="$2"
+ local tourl="$3"
+
+ if [ ! -e "$dir" ]; then
+ git clone -q "$fromurl" "$dir"
+ cd "$dir"
+ git remote rename origin gitlab
+ git remote add origin "$tourl"
+ fi
+
+}
+
+current_branch() {
+ git rev-parse --abbrev-ref HEAD
+}
+
+uncommitted() {
+ git status --short | grep '^ M ' >/dev/null
+}
+
+ssh-keyscan gitlab.com git.liw.fi >"$HOME/.ssh/known_hosts"
+
+grep '^[^#]' "$LIST" |
+ while read -r fromurl tourl; do
+ dir="$HOME/mirrors/$tourl"
+ fromurl="https://gitlab.com/$fromurl.git"
+ tourl="ssh://git@git.liw.fi/$tourl"
+
+ echo
+ echo "=============================================="
+ echo "from: $fromurl"
+ echo "via : $dir"
+ echo "to : $tourl"
+
+ setup_clone "$dir" "$fromurl" "$tourl"
+
+ cd "$dir"
+ case "$(current_branch)" in
+ master | main)
+ if uncommitted; then
+ die "there are uncommitted changes"
+ fi
+ git remote update --prune
+ git pull -q --rebase gitlab HEAD
+ git push -q origin HEAD
+ ;;
+ *)
+ die "not in main or master branch"
+ ;;
+ esac
+ done
+echo
+echo all mirror OK
diff --git a/ansible/files/mirror-list b/ansible/files/mirror-list
new file mode 100644
index 0000000..0e2ffb7
--- /dev/null
+++ b/ansible/files/mirror-list
@@ -0,0 +1,17 @@
+larswirzenius/bumper bumper-rs
+larswirzenius/clab clab
+larswirzenius/contractor2 contractor2
+larswirzenius/ewww ewww
+larswirzenius/gtdfh gtdfh.liw.fi
+larswirzenius/ideas ideas
+larswirzenius/jt jt2
+larswirzenius/obnam obnam2
+larswirzenius/obnam.org obnam.org
+larswirzenius/puomi puomi
+larswirzenius/summain summain-rs
+larswirzenius/vmadm vmadm
+larswirzenius/vmdb2 vmdb2
+larswirzenius/vmdb2-web vmdb2.liw.fi
+larswirzenius/yuck yuck
+subplot/subplot subplot
+subplot/subplot-web subplot.liw.fi
diff --git a/ansible/hosts b/ansible/hosts
index bd375e4..4a5143c 100644
--- a/ansible/hosts
+++ b/ansible/hosts
@@ -54,6 +54,8 @@ oomph3
train-dev
train-dev-docker
+mirror-git
+
[ick_workers]
ick3-unstable hostname=ick3-unstable debian_codename=unstable pbuilder_othermirror_distro=unstable
ick3-stretch hostname=ick3-stretch debian_codename=stretch pbuilder_othermirror_distro=unstable
diff --git a/ansible/mirror-git.vm.liw.fi.hz b/ansible/mirror-git.vm.liw.fi.hz
deleted file mode 100644
index e10d6af..0000000
--- a/ansible/mirror-git.vm.liw.fi.hz
+++ /dev/null
@@ -1,5 +0,0 @@
-defaults:
- type: cx11
- image: debian-10
-hosts:
- - name: git
diff --git a/ansible/mirror-git.vm.liw.fi.yml b/ansible/mirror-git.vm.liw.fi.yml
deleted file mode 100644
index 64db345..0000000
--- a/ansible/mirror-git.vm.liw.fi.yml
+++ /dev/null
@@ -1,118 +0,0 @@
-- hosts: git
- remote_user: root
- roles:
- - role: sane_debian_system
- - role: unix_users
- - role: self-updating-system
- - smarthost-client
- tasks:
- - name: "install git and more"
- apt:
- state: present
- name:
- - git
- - moreutils
- - name: "clone subplot-web"
- become: yes
- become_user: liw
- shell: |
- cd /home/liw
- rm -rf subplot-web
- git clone https://gitlab.com/larswirzenius/subplot-web.git
- cd subplot-web
- git remote rename origin gitlab
- git remote add origin ssh://git@git.liw.fi/subplot.liw.fi
- ssh-keyscan gitlab.com git.liw.fi > /home/liw/.ssh/known_hosts
- - name: "install list of repositories to mirror"
- copy:
- content: |
- /home/liw/subplot-web
- /home/liw/subplot
- /home/liw/obnam2
- /home/liw/obnam.org
- /home/liw/vmdb2-web
- /home/liw/vmadm
- /home/liw/gtdfh.liw.fi
- dest: /etc/mirror-git.list
- - name: "install script to mirror gitlab to git.liw.fi"
- copy:
- content: |
- #!/bin/bash
-
- set -euo pipefail
-
- die()
- {
- echo "$@" 1>&2
- exit 1
- }
-
- current_branch()
- {
- git rev-parse --abbrev-ref HEAD
- }
-
- uncommitted () {
- git status --short | grep '^ M ' > /dev/null
- }
-
- while read dir
- do
- echo
- echo "repo: $dir"
- cd "$dir"
- case "$(current_branch)" in
- master|main)
- if uncommitted
- then
- die "there are uncommitted changes"
- fi
- git remote update --prune
- git pull --rebase gitlab HEAD
- git push origin HEAD
- ;;
- *)
- die "not in main or master branch"
- ;;
- esac
- done < /etc/mirror-git.list
- echo OK
- dest: /usr/local/bin/gitlab-to-git.liw.fi
- mode: 0755
- - name: "set up cron job to mirror git"
- cron:
- name: "mirror git"
- user: liw
- hour: "*"
- minute: "*/5"
- job: |
- chronic /usr/local/bin/gitlab-to-git.liw.fi
- vars:
- sane_debian_system_version: 2
- unix_users_version: 2
-
- sane_debian_system_hostname: mirror-git
- sane_debian_system_codename: buster
- sane_debian_system_mirror: deb.debian.org
-
- unix_users:
- - username: root
- authorized_keys: |
- {{ liw_ssh_pub }}
- - username: liw
- comment: Lars Wirzenius
- sudo: true
- authorized_keys: |
- {{ liw_ssh_pub }}
- ssh_key: |
- {{ lookup('pipe', 'pass show ssh/liw@mirror-git') }}
- ssh_key_pub: |
- {{ lookup('pipe', 'pass show ssh/liw@mirror-git.pub') }}
-
- mailname: mirror-git.vm.liw.fi
-
- hostname: "{{ sane_debian_system_hostname }}"
- relayhost: pieni.net:587
- smarthost: pieni.net
- smarthost_user: pienirelay
- smarthost_password: "{{ lookup('pipe', 'pass show pieni.net/pienirelay') }}"
diff --git a/ansible/mirror-git.yml b/ansible/mirror-git.yml
new file mode 100644
index 0000000..049ffb2
--- /dev/null
+++ b/ansible/mirror-git.yml
@@ -0,0 +1,65 @@
+- hosts: mirror-git
+ remote_user: debian
+ become: yes
+ roles:
+ - role: sane_debian_system
+ - role: unix_users
+ - role: self-updating-system
+ - smarthost-client
+ tasks:
+ - name: "install git and more"
+ apt:
+ state: present
+ name:
+ - git
+ - moreutils
+ - psmisc
+
+ - name: "install list of repositories to mirror"
+ copy:
+ src: mirror-list
+ dest: /etc/mirror-git.list
+
+ - name: "install script to mirror gitlab to git.liw.fi"
+ copy:
+ src: mirror-git.sh
+ dest: /usr/local/bin/gitlab-to-git.liw.fi
+ mode: 0755
+
+ - name: "set up cron job to mirror git"
+ cron:
+ name: "mirror git"
+ user: liw
+ hour: "*"
+ minute: "*/5"
+ job: |
+ chronic /usr/local/bin/gitlab-to-git.liw.fi
+ vars:
+ sane_debian_system_version: 2
+ unix_users_version: 2
+
+ sane_debian_system_hostname: mirror-git
+ sane_debian_system_codename: buster
+ sane_debian_system_mirror: deb.debian.org
+
+ unix_users:
+ - username: root
+ authorized_keys: |
+ {{ liw_ssh_pub }}
+ - username: liw
+ comment: Lars Wirzenius
+ sudo: true
+ authorized_keys: |
+ {{ liw_ssh_pub }}
+ ssh_key: |
+ {{ lookup('pipe', 'pass show ssh/liw@mirror-git') }}
+ ssh_key_pub: |
+ {{ lookup('pipe', 'pass show ssh/liw@mirror-git.pub') }}
+
+ mailname: mirror-git.vm.liw.fi
+
+ hostname: "{{ sane_debian_system_hostname }}"
+ relayhost: pieni.net:587
+ smarthost: pieni.net
+ smarthost_user: pienirelay
+ smarthost_password: "{{ lookup('pipe', 'pass show pieni.net/pienirelay') }}"