Skip to content

Commit 8eb1d69

Browse files
committed
Merge branch 'hotfix-0.1.6' into stable
2 parents fe6ead3 + ed7277f commit 8eb1d69

File tree

5 files changed

+122
-55
lines changed

5 files changed

+122
-55
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.1.6
4+
- Better way to add custom config
5+
- Improve documentation
6+
37
## 0.1.5
48
- Upgrade baseimage: osixia/light-baseimage:0.1.1
59

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NAME = osixia/keepalived
2-
VERSION = 0.1.5
2+
VERSION = 0.1.6
33

44
.PHONY: all build test tag_latest release
55

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,77 @@ A docker image to run Keepalived.
1010
This image require the kernel module ip_vs loaded on the host and need to be run with : --privileged --net=host
1111

1212
docker run --privileged --net=host -d osixia/keepalived
13+
14+
## Environment Variables
15+
16+
Environement variables defaults are set in **image/env.yaml**. You can modify environment variable values directly in this file and rebuild the image ([see manual build](#manual-build)). You can also override those values at run time with -e argument or by setting your own env.yaml file as a docker volume to `/etc/env.yaml`. See examples below.
17+
18+
- **KEEPALIVED_INTERFACE**: Keepalived network interface. Defaults to `eth0`
19+
- **KEEPALIVED_PASSWORD**: Keepalived password. Defaults to `d0cker`
20+
- **KEEPALIVED_PRIORITY** Keepalived node priority. Defaults to `150`
21+
22+
- **KEEPALIVED_UNICAST_PEERS** Keepalived unicast peers. Defaults to :
23+
- 192.168.1.10
24+
- 192.168.1.11
25+
26+
If you want to set this variable at docker run command convert the yaml in python :
27+
28+
docker run -e KEEPALIVED_UNICAST_PEERS="[192.168.1.10', '192.168.1.11']" -d osixia/phpldapadmin
29+
30+
To convert yaml to python online : http://yaml-online-parser.appspot.com/
31+
32+
33+
- **KEEPALIVED_VIRTUAL_IPS** Add a read only user. Defaults to :
34+
35+
- 192.168.1.231
36+
- 192.168.1.232
37+
38+
If you want to set this variable at docker run command convert the yaml in python, see above.
39+
40+
- **KEEPALIVED_NOTIFY** Script to execute when node state change. Defaults to `/container/service/keepalived/assets/notify.sh`
41+
42+
### Set environment variables at run time :
43+
44+
Environment variable can be set directly by adding the -e argument in the command line, for example :
45+
46+
docker run -e KEEPALIVED_INTERFACE="eno1" -e KEEPALIVED_PASSWORD="password!" \
47+
-e KEEPALIVED_PRIORITY="100" -d osixia/keepalived
48+
49+
Or by setting your own `env.yaml` file as a docker volume to `/etc/env.yaml`
50+
51+
docker run -v /data/my-env.yaml:/etc/env.yaml \
52+
-d osixia/keepalived
53+
54+
## Manual build
55+
56+
Clone this project :
57+
58+
git clone https://github.com/osixia/docker-keepalived
59+
cd docker-keepalived
60+
61+
Adapt Makefile, set your image NAME and VERSION, for example :
62+
63+
NAME = osixia/keepalived
64+
VERSION = 0.1.6
65+
66+
becomes :
67+
NAME = billy-the-king/keepalived
68+
VERSION = 0.1.0
69+
70+
Build your image :
71+
72+
make build
73+
74+
Run your image :
75+
76+
docker run -d billy-the-king/keepalived:0.1.0
77+
78+
## Tests
79+
80+
We use **Bats** (Bash Automated Testing System) to test this image:
81+
82+
> [https://github.com/sstephenson/bats](https://github.com/sstephenson/bats)
83+
84+
Install Bats, and in this project directory run :
85+
86+
make test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add your custom keepalived.conf file here or mount one at docker run to /etc/keepalived/keepalived.conf
1+
Add your custom keepalived.conf file here or mount one at docker run to /container/service/keepalived/assets/keepalived.conf

image/service/keepalived/container-start.sh

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,50 @@ FIRST_START_DONE="/etc/docker-keepalived-first-start-done"
55
# container first start
66
if [ ! -e "$FIRST_START_DONE" ]; then
77

8-
# config folder is empty use bootstrap config if available
9-
if [ ! -e /etc/keepalived/keepalived.conf ]; then
10-
echo "No keepalived.conf provided using image default one"
11-
if [ ! -e /container/service/keepalived/assets/keepalived.conf ]; then
12-
echo "Error: No default keepalived.conf found in /container/service/keepalived/assets/keepalived.conf"
13-
exit 1
14-
else
15-
16-
ln -s /container/service/keepalived/assets/keepalived.conf /etc/keepalived/keepalived.conf
17-
18-
#
19-
# bootstrap config
20-
#
21-
sed -i "s|{{ keepalived_interface }}|$KEEPALIVED_INTERFACE|g" /etc/keepalived/keepalived.conf
22-
sed -i "s|{{ keepalived_priority }}|$KEEPALIVED_PRIORITY|g" /etc/keepalived/keepalived.conf
23-
sed -i "s|{{ keepalived_password }}|$KEEPALIVED_PASSWORD|g" /etc/keepalived/keepalived.conf
24-
25-
if [ -n "$KEEPALIVED_NOTIFY" ]; then
26-
sed -i "s|{{ keepalived_notify }}|notify \"$KEEPALIVED_NOTIFY\"|g" /etc/keepalived/keepalived.conf
27-
else
28-
sed -i "/{{ keepalived_notify }}/d" /etc/keepalived/keepalived.conf
29-
fi
30-
31-
# unicast peers
32-
KEEPALIVED_UNICAST_PEERS=($KEEPALIVED_UNICAST_PEERS)
33-
for peer in "${KEEPALIVED_UNICAST_PEERS[@]}"
34-
do
35-
# it's just a peer
36-
# stored in a variable
37-
if [ -n "${!peer}" ]; then
38-
sed -i "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
39-
# directly
40-
else
41-
sed -i "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
42-
fi
43-
done
44-
sed -i "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf
8+
ln -s /container/service/keepalived/assets/keepalived.conf /etc/keepalived/keepalived.conf
9+
10+
#
11+
# bootstrap config
12+
#
13+
sed -i "s|{{ keepalived_interface }}|$KEEPALIVED_INTERFACE|g" /etc/keepalived/keepalived.conf
14+
sed -i "s|{{ keepalived_priority }}|$KEEPALIVED_PRIORITY|g" /etc/keepalived/keepalived.conf
15+
sed -i "s|{{ keepalived_password }}|$KEEPALIVED_PASSWORD|g" /etc/keepalived/keepalived.conf
16+
17+
if [ -n "$KEEPALIVED_NOTIFY" ]; then
18+
sed -i "s|{{ keepalived_notify }}|notify \"$KEEPALIVED_NOTIFY\"|g" /etc/keepalived/keepalived.conf
19+
else
20+
sed -i "/{{ keepalived_notify }}/d" /etc/keepalived/keepalived.conf
21+
fi
4522

46-
# virtual ips
47-
KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS)
48-
for vip in "${KEEPALIVED_VIRTUAL_IPS[@]}"
49-
do
50-
# it's just a peer
51-
# stored in a variable
52-
if [ -n "${!vip}" ]; then
53-
sed -i "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
54-
# directly
55-
else
56-
sed -i "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
57-
fi
58-
done
59-
sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf
23+
# unicast peers
24+
KEEPALIVED_UNICAST_PEERS=($KEEPALIVED_UNICAST_PEERS)
25+
for peer in "${KEEPALIVED_UNICAST_PEERS[@]}"
26+
do
27+
# it's just a peer
28+
# stored in a variable
29+
if [ -n "${!peer}" ]; then
30+
sed -i "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
31+
# directly
32+
else
33+
sed -i "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
6034
fi
61-
62-
fi
35+
done
36+
sed -i "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf
37+
38+
# virtual ips
39+
KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS)
40+
for vip in "${KEEPALIVED_VIRTUAL_IPS[@]}"
41+
do
42+
# it's just a peer
43+
# stored in a variable
44+
if [ -n "${!vip}" ]; then
45+
sed -i "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
46+
# directly
47+
else
48+
sed -i "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
49+
fi
50+
done
51+
sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf
6352

6453
touch $FIRST_START_DONE
6554
fi

0 commit comments

Comments
 (0)