-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfab
executable file
·107 lines (87 loc) · 3.3 KB
/
fab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -eu -o pipefail
# Configure your .ssh/config so it can access the following hosts with proper
# username and key:
# - contint.wikimedia.org (service alias to the actual server)
# - integration-cumin.integration.eqiad.wmflabs
_ssh_command_sudo() {
local host="$1"
local sudoer="$2"
local cmds
# strip new lines and leading space
cmds=$(echo "$3" | sed 's/^ *//' | sed '/^$/d')
if [[ "${4:-visible}" == "visible" ]]; then
# shellcheck disable=SC2001
echo "$cmds" | sed "s/^/\\[$host\\] /"
fi
ssh "$host" sudo -H -u "$sudoer" "$cmds"
}
_ssh_command_self() {
local host="$1"
local cmds
local esc_cmds
# strip new lines and leading space
cmds=$(echo "$2" | sed 's/^ *//' | sed '/^$/d')
esc_cmds=$(printf '%q' "$cmds")
# shellcheck disable=SC2001
echo "$cmds" | sed "s/^/\\[$host\\] /"
ssh "$host" sh -c "$esc_cmds"
}
_confirm() {
read -rp "$1 [Y/n] " response
test "$response" == "" || test "$response" == "y" || test "$response" == "Y"
}
_update_integration_config() {
local host="$1"
local git_dir="$2"
local diff_dir="$3"
local log_msg="$4"
_ssh_command_sudo "$host" zuul "git -C \"$git_dir\" remote update"
_ssh_command_sudo "$host" zuul "git -C \"$git_dir\" --no-pager log -p HEAD..origin/master \"$diff_dir\""
_confirm "Does the diff look good?"
_confirm "Did you log a message for the SAL in #wikimedia-releng (e.g. \"$log_msg\")"
_ssh_command_sudo "$host" zuul "git -C \"$git_dir\" rebase"
_ssh_command_sudo "$host" zuul "git -C \"$git_dir\" -c gc.auto=128 gc --auto --quiet" "invisible"
}
# Deploy a Zuul layout change.
deploy_zuul() {
local host='contint.wikimedia.org'
local git_dir='/etc/zuul/wikimedia'
local diff_dir='zuul/'
local log_msg='!log Reloading Zuul to deploy [url]'
_update_integration_config "$host" "$git_dir" "$diff_dir" "$log_msg"
_ssh_command_sudo "$host" root "/usr/sbin/service zuul reload"
}
# Update docker-pkg built images.
deploy_docker() {
local host='contint.wikimedia.org'
local git_dir='/etc/zuul/wikimedia'
local diff_dir='dockerfiles/'
local log_msg='!log Updating docker-pkg files on contint primary for [url]'
_update_integration_config "$host" "$git_dir" "$diff_dir" "$log_msg"
# docker-pkg does not attempt to pull images - T219398
_ssh_command_self "$host" '
docker pull docker-registry.wikimedia.org/buster
docker pull docker-registry.wikimedia.org/bullseye
docker pull docker-registry.wikimedia.org/bookworm
'
local docker_pkg='/srv/deployment/docker-pkg/venv/bin/docker-pkg'
local docker_pkg_config='/etc/docker-pkg/integration.yaml'
local dockerfiles='/etc/zuul/wikimedia/dockerfiles'
_ssh_command_self "$host" "$docker_pkg -c $docker_pkg_config --info build $dockerfiles"
}
# Pull a docker image onto the WMCS-hosted CI agents.
docker_pull_image() {
local image_name="$1"
local host='integration-cumin.integration.eqiad.wmflabs'
_ssh_command_sudo "$host" root "cumin --force 'name:agent-docker' 'docker pull $image_name'"
}
case "${1:-}" in
deploy_zuul) deploy_zuul ;;
deploy_docker) deploy_docker ;;
docker_pull_image) docker_pull_image "$2" ;;
*)
echo "usage: ./fab [ deploy_zuul | deploy_docker | docker_pull_image ]"
exit 1
;;
esac