-
Notifications
You must be signed in to change notification settings - Fork 226
/
Vagrantfile
155 lines (127 loc) · 6.1 KB
/
Vagrantfile
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This environment use only for reproducible tests for stateful Linux clickhouse-server installation
def total_cpus
require 'etc'
Etc.nprocessors
end
def get_provider
provider='virtualbox'
for arg in ARGV
if ['hyperv','docker'].include? arg
provider=arg
end
end
return provider
end
Vagrant.configure(2) do |config|
config.vm.box = "generic/ubuntu2404"
config.vm.box_check_update = false
if get_provider == "hyperv"
config.vm.synced_folder ".", "/vagrant", type: "smb", smb_user: "#{ENV['USERNAME']}@#{ENV['USERDOMAIN']}", smb_password: ENV['PASSWORD'], mount_options: ["vers=3.0","domain=#{ENV['USERDOMAIN']}", "user=#{ENV['USERNAME']}","username=#{ENV['USERDOMAIN']}@#{ENV['USERNAME']}","password=#{ENV['PASSWORD']}"]
else
config.vm.synced_folder ".", "/vagrant"
end
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
if Vagrant.has_plugin?("vagrant-timezone")
config.timezone.value = "UTC"
end
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.cpus = total_cpus
vb.memory = "2048"
vb.default_nic_type = "virtio"
vb.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL ]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
end
config.vm.provider "hyperv" do |hv|
hv.cpus = total_cpus
hv.maxmemory = "2048"
hv.memory = "2048"
hv.enable_virtualization_extensions = true
hv.linked_clone = true
hv.vm_integration_services = {
time_synchronization: true,
}
end
config.vm.define :clickhouse_backup do |clickhouse_backup|
clickhouse_backup.vm.network "private_network", ip: "172.16.2.109", nic_type: "virtio"
# port forwarding works only when pair with kubectl port-forward
# clickhouse-server
clickhouse_backup.vm.network "forwarded_port", guest_ip: "172.16.2.109", guest: 8123, host_ip: "127.0.0.1", host: 8123
clickhouse_backup.vm.network "forwarded_port", guest_ip: "172.16.2.109", guest: 9000, host_ip: "127.0.0.1", host: 9000
# clickhouse-backup
clickhouse_backup.vm.network "forwarded_port", guest_ip: "172.16.2.109", guest: 7171, host_ip: "127.0.0.1", host: 7171
clickhouse_backup.vm.host_name = "local-clickhouse-backup"
# vagrant plugin install vagrant-disksize
clickhouse_backup.disksize.size = '50GB'
end
config.vm.provision "shell", inline: <<-SHELL
set -xeuo pipefail
export DEBIAN_FRONTEND=noninteractive
# make linux fast again ;)
if [[ "0" == $(grep "mitigations" /etc/default/grub | wc -l) ]]; then
echo 'GRUB_CMDLINE_LINUX="noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off"' >> /etc/default/grub
echo 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off"' >> /etc/default/grub
grub-mkconfig
fi
systemctl enable systemd-timesyncd
systemctl start systemd-timesyncd
apt-get update
apt-get install --no-install-recommends -y apt-transport-https ca-certificates software-properties-common curl
apt-get install --no-install-recommends -y htop ethtool mc curl wget jq socat git make gcc libc-dev dirmngr
# clickhouse
GNUPGHOME=$(mktemp -d)
GNUPGHOME="$GNUPGHOME" gpg --no-default-keyring --keyring /usr/share/keyrings/clickhouse-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8919F6BD2B48D754
rm -r "$GNUPGHOME"
chmod +r /usr/share/keyrings/clickhouse-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg] https://packages.clickhouse.com/deb stable main" | tee /etc/apt/sources.list.d/clickhouse.list
apt-get update
apt-get install --no-install-recommends -y clickhouse-client clickhouse-server
# golang
export GOLANG_VERSION=1.23
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 52B59B1571A79DBC054901C0F6BC817356A3D45E
add-apt-repository ppa:longsleep/golang-backports
apt-get install --no-install-recommends -y golang-${GOLANG_VERSION}
ln -nvsf /usr/lib/go-${GOLANG_VERSION}/bin/go /bin/go
ln -nvsf /usr/lib/go-${GOLANG_VERSION}/bin/gofmt /bin/gofmt
mkdir -p /home/ubuntu/go/src/github.com/Altinity/
ln -nsvf /vagrant /home/ubuntu/go/src/github.com/Altinity/clickhouse-backup
# docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) test"
apt-get install --no-install-recommends -y docker-ce pigz
# docker compose
apt-get install -y --no-install-recommends python3-distutils
curl -sL https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
python3 /tmp/get-pip.py
pip3 install -U setuptools
pip3 install -U docker-compose
# gihub actions local
curl https://raw.githubusercontent.com/nektos/act/master/install.sh | bash
# run manual
# act -v -r -j build -s DOCKER_REPO=<repo_name> -s DOCKER_IMAGE=clickhouse-backup -s DOCKER_USER=<docker_user> -s DOCKER_TOKEN=<docker_token> -w /vagrant
systemctl restart clickhouse-server
export DOCKER_IMAGE=Altinity/clickhouse-backup
# export DOCKER_IMAGE=altinity/clickhouse-backup:latest
# export DOCKER_IMAGE=clickhousepro/clickhouse-backup:dev
pwd
cd /vagrant/
make clean build
mv -v clickhouse-backup/clickhouse-backup /bin/
clickhouse-backup list local
docker pull $DOCKER_IMAGE
docker run -u $(id -u clickhouse) --rm --network host -v "/var/lib/clickhouse:/var/lib/clickhouse" \
-e CLICKHOUSE_USER="default" \
-e CLICKHOUSE_PASSWORD="" \
-e S3_BUCKET="clickhouse-backup" \
-e S3_ACCESS_KEY="access_key" \
-e S3_SECRET_KEY="secret" \
${DOCKER_IMAGE} list local
SHELL
end