Skip to content

Commit cf4cc7d

Browse files
lpasqualiafabiani
authored and
afabiani
committed
Implemented: (GeoNode#274)
- geonode-project#252: fix startup of containers on restart - added support for docker swarm - added support to debug geonode-project with vagrant (cherry picked from commit 7a13662)
1 parent 7fb35c7 commit cf4cc7d

10 files changed

+387
-96
lines changed

.env.sample

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ LDAP_GROUP_PROFILE_MEMBER_ATTR=uniqueMember
220220

221221
# expressed in KB
222222
# CELERY__MAX_MEMORY_PER_CHILD="200000"
223-
# ##
223+
# ##
224224
# Note right autoscale value must coincide with worker concurrency value
225-
# CELERY__AUTOSCALE_VALUES="1,4"
225+
# CELERY__AUTOSCALE_VALUES="1,4"
226226
# CELERY__WORKER_CONCURRENCY="4"
227227
# ##
228228
# CELERY__OPTS="--without-gossip --without-mingle -Ofair -B -E"
@@ -238,4 +238,4 @@ POSTGRESQL_MAX_CONNECTIONS=200
238238
RESTART_POLICY_CONDITION="on-failure"
239239
RESTART_POLICY_DELAY="5s"
240240
RESTART_POLICY_MAX_ATTEMPTS="3"
241-
RESTART_POLICY_WINDOW=120s
241+
RESTART_POLICY_WINDOW=120s

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ local_settings.py
6363

6464
.idea/
6565
.vscode/
66+
.vagrant/
67+
Vagrantfile

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,43 @@ POSTGRESQL_MAX_CONNECTIONS=200
251251
```
252252

253253
In this case PostgreSQL will run accepting 200 maximum connections.
254+
255+
## Test project generation and docker-compose build Vagrant usage
256+
257+
Testing with [vagrant](https://www.vagrantup.com/docs) is very simple, a build and restart to ensure services repartition on
258+
startup is done by issuing:
259+
260+
```bash
261+
vagrant plugin install vagrant-reload
262+
#choose what to test
263+
cp Vagrantfile.compose Vagrantfile
264+
vagrant up
265+
# check services are up upon reboot
266+
vagrant ssh geonode-compose -c 'docker ps'
267+
vagrant destroy -f
268+
cp Vagrantfile.stack Vagrantfile
269+
vagrant up
270+
# check services are up upon reboot
271+
vagrant ssh geonode-compose -c 'docker service ls'
272+
vagrant destroy -f
273+
```
274+
275+
for direct deveolpment on geonode-project after first `vagrant up` to rebuild after changes to project, you can do `vagrant reload` like this:
276+
277+
```bash
278+
vagrant up
279+
```
280+
281+
What vagrant does (swarm or comnpose cases):
282+
283+
- starts a vm for test on docker swarm:
284+
- configures a GeoNode project from template every time from your working directory (so you can develop directly on geonode-project).
285+
- rebuilds everytime everything with cache [1] to avoid banning from docker hub with no login.
286+
- starts, reboots.
287+
288+
- starts a vm for test on plain docker service with docker-compose:
289+
- configures a GeoNode project from template every time from your working directory (so you can develop directly on geonode-project).
290+
- rebuilds everytime everything with cache [1] to avoid banning from docker hub with no login.
291+
- starts, reboots.
292+
293+
[1] to achieve `docker-compose build --no-cache` just destroy vagrant boxes `vagrant destroy -f`

Vagrantfile

-70
Original file line numberDiff line numberDiff line change
@@ -1,70 +0,0 @@
1-
# Vagrant 1.7+ automatically inserts a different
2-
# insecure keypair for each new VM created. The easiest way
3-
# to use the same keypair for all the machines is to disable
4-
# this feature and rely on the legacy insecure key.
5-
# config.ssh.insert_key = false
6-
#
7-
# Note:
8-
# As of Vagrant 1.7.3, it is no longer necessary to disable
9-
# the keypair creation when using the auto-generated inventory.
10-
$geonode_source_path=/home/luca/Development/geonode-project
11-
$script1 = <<-'SCRIPT'
12-
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
13-
sudo chmod +x /usr/local/bin/docker-compose
14-
sudo apt-get install \
15-
apt-transport-https \
16-
ca-certificates \
17-
curl \
18-
gnupg \
19-
lsb-release
20-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
21-
echo \
22-
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
23-
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
24-
sudo apt-get update
25-
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
26-
sudo adduser vagrant docker
27-
sudo docker swarm init
28-
SCRIPT
29-
30-
$script2 = <<-'SCRIPT'
31-
if [ -d "$HOME/antani" ]; then
32-
cd $HOME/antani
33-
[ -f $HOME/antani/.env ] && docker-compose down
34-
cd ..
35-
sudo rm -rf $HOME/antani
36-
fi
37-
SCRIPT
38-
39-
$script3 = <<-'SCRIPT'
40-
sudo apt-get update
41-
sudo apt-get -y install python3-pip python3-virtualenv virtualenvwrapper
42-
SCRIPT
43-
44-
Vagrant.configure(2) do |config|
45-
boxes = {
46-
'ubuntu01' => 'ubuntu/focal64'
47-
}
48-
machine_id = 0
49-
boxes.each do | key, value |
50-
config.vm.box = "#{value}"
51-
machine_id = machine_id + 1
52-
53-
54-
config.vm.define "#{key}" do |node|
55-
node.vm.hostname = "#{key}"
56-
#node.vm.network "private_network", ip: "192.168.68.#{20+machine_id}"
57-
# Only execute once the Ansible provisioner,
58-
# when all the machines are up and ready.
59-
60-
config.vm.provision "shell", inline: $script1, privileged: false
61-
config.vm.provision "shell", inline: $script2, run: 'always', privileged: false
62-
#edit source path suiting your needs
63-
config.vm.provision "file", source: $geonode_source_path, destination: "$HOME/geonode-project", run: 'always'
64-
config.vm.provision "shell", inline: $script3, run: 'always', privileged: false
65-
config.vm.provision :shell, path: "antani-vagrant.sh", run: 'always', privileged: false
66-
67-
68-
end
69-
end
70-
end

Vagrantfile.compose

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
$geonode_source_path='.'
2+
3+
$script1 = <<-'SCRIPT'
4+
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
5+
sudo chmod +x /usr/local/bin/docker-compose
6+
sudo apt-get install \
7+
apt-transport-https \
8+
ca-certificates \
9+
curl \
10+
gnupg \
11+
lsb-release
12+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
13+
echo \
14+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
15+
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
16+
sudo apt-get update
17+
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
18+
sudo adduser vagrant docker
19+
SCRIPT
20+
21+
$script2 = <<-'SCRIPT'
22+
if [ -d "/home/vagrant/antani" ]; then
23+
cd /home/vagrant/antani
24+
docker-compose down
25+
cd ..
26+
rm -rf /home/vagrant/antani
27+
fi
28+
rm -rf /home/vagrant/geonode-project
29+
SCRIPT
30+
31+
$script3 = <<-'SCRIPT'
32+
sudo apt-get update
33+
sudo apt-get -y install python3-pip python3-virtualenv virtualenvwrapper
34+
SCRIPT
35+
36+
$script4 = <<-'SCRIPT'
37+
sudo reboot
38+
SCRIPT
39+
40+
Vagrant.configure(2) do |config|
41+
boxes = {
42+
'geonode-compose' => 'ubuntu/focal64'
43+
}
44+
machine_id = 0
45+
boxes.each do | key, value |
46+
config.vm.box = "#{value}"
47+
machine_id = machine_id + 1
48+
config.vm.define "#{key}" do |node|
49+
node.vm.hostname = "#{key}"
50+
config.vm.provision "shell", inline: $script1, privileged: false
51+
config.vm.provision "shell", inline: $script2, run: 'always', privileged: true
52+
config.vm.provision "file", source: $geonode_source_path, destination: "$HOME/geonode-project", run: 'always'
53+
config.vm.provision "shell", inline: $script3, run: 'always', privileged: false
54+
config.vm.provision :shell, path: "antani-vagrant-compose.sh", run: 'always', privileged: false
55+
config.vm.provision "shell", inline: $script4, run: 'always', privileged: false
56+
end
57+
end
58+
end

Vagrantfile.stack

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
$geonode_source_path='.'
2+
3+
$script1 = <<-'SCRIPT'
4+
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
5+
sudo chmod +x /usr/local/bin/docker-compose
6+
sudo apt-get install \
7+
apt-transport-https \
8+
ca-certificates \
9+
curl \
10+
gnupg \
11+
lsb-release
12+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
13+
echo \
14+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
15+
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
16+
sudo apt-get update
17+
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
18+
sudo adduser vagrant docker
19+
SCRIPT
20+
21+
$script2 = <<-'SCRIPT'
22+
if [ -d "/home/vagrant/antani" ]; then
23+
cd /home/vagrant/antani
24+
docker service rm geonode-stack
25+
cd ..
26+
rm -rf /home/vagrant/antani
27+
fi
28+
rm -rf /home/vagrant/geonode-project
29+
SCRIPT
30+
31+
$script3 = <<-'SCRIPT'
32+
sudo apt-get update
33+
sudo apt-get -y install python3-pip python3-virtualenv virtualenvwrapper
34+
SCRIPT
35+
36+
$script4 = <<-'SCRIPT'
37+
sudo reboot
38+
SCRIPT
39+
40+
Vagrant.configure(2) do |config|
41+
boxes = {
42+
'geonode-swarm' => 'ubuntu/focal64'
43+
}
44+
machine_id = 0
45+
boxes.each do | key, value |
46+
config.vm.box = "#{value}"
47+
machine_id = machine_id + 1
48+
config.vm.define "#{key}" do |node|
49+
node.vm.hostname = "#{key}"
50+
config.vm.provision "shell", inline: $script1, privileged: false
51+
config.vm.provision "shell", inline: $script2, run: 'always', privileged: true
52+
config.vm.provision "file", source: $geonode_source_path, destination: "$HOME/geonode-project", run: 'always'
53+
config.vm.provision "shell", inline: $script3, run: 'always', privileged: false
54+
config.vm.provision :shell, path: "antani-vagrant-swarm.sh", run: 'always', privileged: false
55+
config.vm.provision "shell", inline: $script4, run: 'always', privileged: false
56+
end
57+
end
58+
end

antani-vagrant-compose.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#!/usr/bin/env bash
3+
# this is the antani script to create an antani canary project.
4+
5+
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
6+
mkvirtualenv --python=/usr/bin/python3 antani
7+
pip install Django==3.2
8+
rm -rf antani
9+
django-admin startproject --template=/home/vagrant/geonode-project -e py,sh,md,rst,json,yml,ini,env,sample,properties -n monitoring-cron -n Dockerfile antani
10+
cd /home/vagrant/antani
11+
cp .env.sample .env
12+
chown -R vagrant:vagrant /home/vagrant/antani
13+
sudo docker-compose build
14+
sudo docker-compose up -d

antani-vagrant-swarm.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#!/usr/bin/env bash
3+
# this is the antani script to create an antani canary project.
4+
sudo docker swarm init
5+
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
6+
mkvirtualenv --python=/usr/bin/python3 antani
7+
pip install Django==3.2
8+
rm -rf antani
9+
django-admin startproject --template=/home/vagrant/geonode-project -e py,sh,md,rst,json,yml,ini,env,sample,properties -n monitoring-cron -n Dockerfile antani
10+
cd /home/vagrant/antani
11+
cp .env.sample .env
12+
chown -R vagrant:vagrant /home/vagrant/antani
13+
sudo docker-compose -f ./geonode-stack.yml build
14+
sudo docker stack deploy -c ./geonode-stack.yml geonode-stack

0 commit comments

Comments
 (0)