Skip to content

Commit 27de048

Browse files
committed
Merge branch 'release-0.2.0' into stable
2 parents 3f44f60 + 56e95ef commit 27de048

File tree

10 files changed

+193
-97
lines changed

10 files changed

+193
-97
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.2.0
4+
- Upgrade baseimage: light-baseimage:0.2.1
5+
- Makefile with build no cache
6+
37
## 0.1.9
48
- Upgrade baseimage: light-baseimage:0.1.5
59

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
NAME = osixia/keepalived
2-
VERSION = 0.1.9
2+
VERSION = 0.2.0
33

4-
.PHONY: all build test tag_latest release
4+
.PHONY: all build build-nocache test tag_latest release
55

66
all: build
77

88
build:
99
docker build -t $(NAME):$(VERSION) --rm image
1010

11+
build-nocache:
12+
docker build -t $(NAME):$(VERSION) --no-cache --rm image
13+
1114
test:
1215
env NAME=$(NAME) VERSION=$(VERSION) bats test/test.bats
1316

README.md

Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,64 @@
11
# osixia/keepalived
22

3-
[![](https://badge.imagelayers.io/osixia/keepalived:latest.svg)](https://imagelayers.io/?images=osixia/keepalived:latest 'Get your own badge on imagelayers.io')
3+
[![](https://badge.imagelayers.io/osixia/keepalived:latest.svg)](https://imagelayers.io/?images=osixia/keepalived:latest 'Get your own badge on imagelayers.io') | Latest release: 0.2.0 - Keepalived 1.2.19 - [Changelog](CHANGELOG.md) | [Docker Hub](https://hub.docker.com/r/osixia/keepalived/) 
44

55
A docker image to run Keepalived.
66
> [keepalived.org](http://keepalived.org/)
77
8+
- [Quick start](#quick-start)
9+
- [Beginner Guide](#beginner-guide)
10+
- [Use your own Backup Manager config](#use-your-own-backup-manager-config)
11+
- [Debug](#debug)
12+
- [Environment Variables](#environment-variables)
13+
- [Set your own environment variables](#set-your-own-environment-variables)
14+
- [Use command line argument](#use-command-line-argument)
15+
- [Link environment file](#link-environment-file)
16+
- [Make your own image or extend this image](#make-your-own-image-or-extend-this-image)
17+
- [Advanced User Guide](#advanced-user-guide)
18+
- [Extend osixia/keepalived:0.2.0 image](#extend-osixiakeepalived020-image)
19+
- [Make your own keepalived image](#make-your-own-keepalived-image)
20+
- [Tests](#tests)
21+
- [Under the hood: osixia/light-baseimage](#under-the-hood-osixialight-baseimage)
22+
- [Changelog](#changelog)
23+
824
## Quick start
925

1026
This image require the kernel module ip_vs loaded on the host (`modprobe ip_vs`) and need to be run with : --cap-add=NET_ADMIN --net=host
1127

12-
docker run --cap-add=NET_ADMIN --net=host -d osixia/keepalived
28+
docker run --cap-add=NET_ADMIN --net=host -d osixia/keepalived:0.2.0
29+
30+
## Beginner Guide
31+
32+
### Use your own Keepalived config
33+
This image comes with a keepalived config file that can be easily customized via environment variables for a quick bootstrap,
34+
but setting your own keepalived.conf is possible. 2 options:
35+
36+
- Link your config file at run time to `/container/service/keepalived/assets/keepalived.conf` :
37+
38+
docker run --volume /data/my-keepalived.conf:/container/service/keepalived/assets/keepalived.conf --detach osixia/keepalived:0.2.0
39+
40+
- Add your config file by extending or cloning this image, please refer to the [Advanced User Guide](#advanced-user-guide)
41+
42+
### Debug
43+
44+
The container default log level is **info**.
45+
Available levels are: `none`, `error`, `warning`, `info`, `debug` and `trace`.
46+
47+
Example command to run the container in `debug` mode:
48+
49+
docker run --detach osixia/keepalived:0.2.0 --loglevel debug
50+
51+
See all command line options:
52+
53+
docker run osixia/keepalived:0.2.0 --help
54+
1355

1456
## Environment Variables
1557

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 `/container/environment/env.yaml`. See examples below.
58+
Environment variables defaults are set in **image/environment/default.yaml**
59+
60+
See how to [set your own environment variables](#set-your-own-environment-variables)
61+
1762

1863
- **KEEPALIVED_INTERFACE**: Keepalived network interface. Defaults to `eth0`
1964
- **KEEPALIVED_PASSWORD**: Keepalived password. Defaults to `d0cker`
@@ -23,35 +68,76 @@ Environement variables defaults are set in **image/env.yaml**. You can modify en
2368
- 192.168.1.10
2469
- 192.168.1.11
2570

26-
If you want to set this variable at docker run command convert the yaml in python :
71+
If you want to set this variable at docker run command add the tag `#PYTHON2BASH:` and convert the yaml in python:
2772

28-
docker run -e KEEPALIVED_UNICAST_PEERS="[192.168.1.10', '192.168.1.11']" -d osixia/phpldapadmin
73+
docker run --env KEEPALIVED_UNICAST_PEERS="#PYTHON2BASH:['192.168.1.10', '192.168.1.11']" --detach osixia/keepalived:0.2.0
2974

3075
To convert yaml to python online : http://yaml-online-parser.appspot.com/
3176

3277

33-
- **KEEPALIVED_VIRTUAL_IPS** Add a read only user. Defaults to :
78+
- **KEEPALIVED_VIRTUAL_IPS** Keepalived virtual IPs. Defaults to :
3479

3580
- 192.168.1.231
3681
- 192.168.1.232
3782

38-
If you want to set this variable at docker run command convert the yaml in python, see above.
83+
If you want to set this variable at docker run command convert the yaml in python, see above.
3984

4085
- **KEEPALIVED_NOTIFY** Script to execute when node state change. Defaults to `/container/service/keepalived/assets/notify.sh`
4186

87+
- **KEEPALIVED_COMMAND_LINE_ARGUMENTS** Keepalived command line arguments; Defaults to `--log-detail --dump-conf`
88+
4289
### Set environment variables at run time :
4390

4491
Environment variable can be set directly by adding the -e argument in the command line, for example :
4592

46-
docker run -e KEEPALIVED_INTERFACE="eno1" -e KEEPALIVED_PASSWORD="password!" \
47-
-e KEEPALIVED_PRIORITY="100" -d osixia/keepalived
93+
docker run --env KEEPALIVED_INTERFACE="eno1" --env KEEPALIVED_PASSWORD="password!" \
94+
--env KEEPALIVED_PRIORITY="100" --detach osixia/keepalived
4895

4996
Or by setting your own `env.yaml` file as a docker volume to `/container/environment/env.yaml`
5097

51-
docker run -v /data/my-env.yaml:/container/environment/env.yaml \
52-
-d osixia/keepalived
98+
docker run --volume /data/my-env.yaml:/container/environment/env.yaml \
99+
--detach osixia/keepalived
100+
101+
### Set your own environment variables
102+
103+
#### Use command line argument
104+
Environment variables can be set by adding the --env argument in the command line, for example:
105+
106+
docker run --env KEEPALIVED_INTERFACE="eno1" --env KEEPALIVED_PASSWORD="password!" \
107+
--env KEEPALIVED_PRIORITY="100" --detach osixia/keepalived:0.2.0
108+
109+
110+
#### Link environment file
111+
112+
For example if your environment file is in : /data/environment/my-env.yaml
113+
114+
docker run --volume /data/environment/my-env.yaml:/container/environment/01-custom/env.yaml \
115+
--detach osixia/keepalived:0.2.0
116+
117+
Take care to link your environment file to `/container/environment/XX-somedir` (with XX < 99 so they will be processed before default environment files) and not directly to `/container/environment` because this directory contains predefined baseimage environment files to fix container environment (INITRD, LANG, LANGUAGE and LC_CTYPE).
118+
119+
#### Make your own image or extend this image
120+
121+
This is the best solution if you have a private registry. Please refer to the [Advanced User Guide](#advanced-user-guide) just below.
122+
123+
## Advanced User Guide
124+
125+
### Extend osixia/keepalived:0.2.0 image
126+
127+
If you need to add your custom TLS certificate, bootstrap config or environment files the easiest way is to extends this image.
128+
129+
Dockerfile example:
130+
131+
FROM osixia/osixia/keepalived:0.2.0
132+
MAINTAINER Your Name <[email protected]>
133+
134+
ADD keepalived.conf /container/service/keepalived/assets/keepalived.conf
135+
ADD environment /container/environment/01-custom
136+
ADD scripts.sh /container/service/keepalived/assets/notify.sh
137+
138+
139+
### Make your own keepalived image
53140

54-
## Manual build
55141

56142
Clone this project :
57143

@@ -61,12 +147,14 @@ Clone this project :
61147
Adapt Makefile, set your image NAME and VERSION, for example :
62148

63149
NAME = osixia/keepalived
64-
VERSION = 0.1.6
150+
VERSION = 0.2.0
65151

66152
becomes :
67153
NAME = billy-the-king/keepalived
68154
VERSION = 0.1.0
69155

156+
Add your custom scripts, environment files, config ...
157+
70158
Build your image :
71159

72160
make build
@@ -75,7 +163,7 @@ Run your image :
75163

76164
docker run -d billy-the-king/keepalived:0.1.0
77165

78-
## Tests
166+
### Tests
79167

80168
We use **Bats** (Bash Automated Testing System) to test this image:
81169

@@ -84,3 +172,13 @@ We use **Bats** (Bash Automated Testing System) to test this image:
84172
Install Bats, and in this project directory run :
85173

86174
make test
175+
176+
177+
### Under the hood: osixia/light-baseimage
178+
179+
This image is based on osixia/light-baseimage.
180+
More info: https://github.com/osixia/docker-light-baseimage
181+
182+
## Changelog
183+
184+
Please refer to: [CHANGELOG.md](CHANGELOG.md)

image/Dockerfile

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
FROM osixia/light-baseimage:0.1.5
1+
# Use osixia/light-baseimage
2+
# sources: https://github.com/osixia/docker-light-baseimage
3+
FROM osixia/light-baseimage:0.2.1
24
MAINTAINER Bertrand Gouny <[email protected]>
35

46
# Keepalived version
57
ENV KEEPALIVED_VERSION 1.2.19
68

7-
# Use baseimage's init system.
8-
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/run
9-
CMD ["/container/tool/run"]
10-
11-
# Install Keepalived
9+
# Download, build and install Keepalived
1210
RUN apt-get -y update \
13-
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y \
14-
curl \
15-
make \
16-
gcc \
17-
pkg-config \
18-
libssl-dev \
19-
libnl-3-dev \
20-
libnl-genl-3-dev \
11+
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
12+
curl \
13+
gcc \
14+
libnl-3-dev \
15+
libnl-genl-3-dev \
16+
libssl-dev \
17+
make \
18+
pkg-config \
2119
&& curl -o keepalived.tar.gz -SL http://keepalived.org/software/keepalived-${KEEPALIVED_VERSION}.tar.gz \
2220
&& mkdir -p /container/keepalived-sources \
2321
&& tar -xzf keepalived.tar.gz --strip 1 -C /container/keepalived-sources \
@@ -39,4 +37,4 @@ RUN /container/tool/install-service \
3937
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
4038

4139
# Add default env variables
42-
ADD env.yaml /container/environment/env.yaml
40+
ADD environment /container/environment/99-default
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ KEEPALIVED_VIRTUAL_IPS:
1414
- 192.168.1.232
1515

1616
KEEPALIVED_NOTIFY: /container/service/keepalived/assets/notify.sh
17+
18+
KEEPALIVED_COMMAND_LINE_ARGUMENTS: --log-detail --dump-conf

image/service/keepalived/container-start.sh

Lines changed: 0 additions & 56 deletions
This file was deleted.

image/service/keepalived/daemon.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash -e
2+
3+
# set -x (bash debug) if log level is trace
4+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
5+
log-helper level eq trace && set -x
6+
7+
exec /usr/local/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console ${KEEPALIVED_COMMAND_LINE_ARGUMENTS}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash -e
2+
3+
# set -x (bash debug) if log level is trace
4+
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
5+
log-helper level eq trace && set -x
6+
7+
FIRST_START_DONE="${CONTAINER_STATE_DIR}/docker-keepalived-first-start-done"
8+
# container first start
9+
if [ ! -e "$FIRST_START_DONE" ]; then
10+
11+
#
12+
# bootstrap config
13+
#
14+
sed -i --follow-symlinks "s|{{ keepalived_interface }}|$KEEPALIVED_INTERFACE|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
15+
sed -i --follow-symlinks "s|{{ keepalived_priority }}|$KEEPALIVED_PRIORITY|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
16+
sed -i --follow-symlinks "s|{{ keepalived_password }}|$KEEPALIVED_PASSWORD|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
17+
18+
if [ -n "$KEEPALIVED_NOTIFY" ]; then
19+
sed -i --follow-symlinks "s|{{ keepalived_notify }}|notify \"$KEEPALIVED_NOTIFY\"|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
20+
chmod +x $KEEPALIVED_NOTIFY
21+
else
22+
sed -i --follow-symlinks "/{{ keepalived_notify }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
23+
fi
24+
25+
# unicast peers
26+
for peer in $(complex-bash-env iterate KEEPALIVED_UNICAST_PEERS)
27+
do
28+
sed -i --follow-symlinks "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
29+
done
30+
sed -i --follow-symlinks "/{{ keepalived_unicast_peers }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
31+
32+
# virtual ips
33+
for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS)
34+
do
35+
sed -i --follow-symlinks "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
36+
done
37+
sed -i --follow-symlinks "/{{ keepalived_virtual_ips }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
38+
39+
touch $FIRST_START_DONE
40+
fi
41+
42+
if [ ! -e "/etc/backup-manager.conf" ]; then
43+
ln -sf ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf /etc/keepalived/keepalived.conf
44+
fi
45+
46+
exit 0

0 commit comments

Comments
 (0)