Skip to content

Commit 8a92be4

Browse files
committed
Merge branch 'release-0.1.0' into stable
2 parents 186274b + 42835ea commit 8a92be4

File tree

11 files changed

+280
-2
lines changed

11 files changed

+280
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## 0.1.0
4+
- Initial release

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
NAME = osixia/keepalived
2+
VERSION = 0.1.0
3+
4+
.PHONY: all build test tag_latest release
5+
6+
all: build
7+
8+
build:
9+
docker build -t $(NAME):$(VERSION) --rm image
10+
11+
test:
12+
env NAME=$(NAME) VERSION=$(VERSION) bats test/test.bats
13+
14+
tag_latest:
15+
docker tag -f $(NAME):$(VERSION) $(NAME):latest
16+
17+
release: build test tag_latest
18+
@if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi
19+
docker push $(NAME)
20+
@echo "*** Don't forget to run 'twgit release/hotfix finish' :)"

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
# docker-keepalived
2-
A docker image to run Keepalived
1+
# osixia/keepalived
2+
3+
A docker image to run Keepalived.
4+
> [keepalived.org](http://keepalived.org/)
5+
6+
## Quick start
7+
8+
This image need to be run with : --privileged --net=host
9+
10+
docker run --privileged --net=host -d osixia/keepalived

image/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM osixia/baseimage:0.10.4
2+
MAINTAINER Bertrand Gouny <[email protected]>
3+
4+
# Keepalived version
5+
ENV KEEPALIVED_VERSION 1.2.17
6+
7+
# Use baseimage-docker's init system.
8+
CMD ["/sbin/my_init"]
9+
10+
# Install Keepalived
11+
RUN apt-get -y update \
12+
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y \
13+
make gcc libssl-dev \
14+
&& curl -o keepalived.tar.gz -SL http://keepalived.org/software/keepalived-${KEEPALIVED_VERSION}.tar.gz \
15+
&& mkdir -p /osixia/keepalived-sources \
16+
&& tar -xzf keepalived.tar.gz --strip 1 -C /osixia/keepalived-sources \
17+
&& cd osixia/keepalived-sources \
18+
&& ./configure --with-kernel-dir=/lib/modules/$(uname -r)/build \
19+
&& make && make install \
20+
&& cd - && mkdir -p /etc/keepalived \
21+
&& apt-get remove -y --purge --auto-remove make gcc libssl-dev
22+
23+
# Add Keepalived assets
24+
ADD service/keepalived/assets /osixia/keepalived
25+
26+
# Clean all
27+
RUN rm keepalived.tar.gz \
28+
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
29+
30+
# Add default env variables
31+
ADD env.yml /etc/env.yml
32+
33+
# Add Keepalived container start config & daemon
34+
ADD service/keepalived/container-start.sh /etc/my_init.d/keepalived
35+
ADD service/keepalived/daemon.sh /etc/service/keepalived/run

image/env.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KEEPALIVED_INTERFACE: p4p1
2+
KEEPALIVED_PASSWORD: d0cker
3+
4+
# for electing MASTER, highest priority wins.
5+
# to be MASTER, make 50 more than other machines
6+
KEEPALIVED_PRIORITY: 150
7+
8+
KEEPALIVED_UNICAST_PEERS:
9+
- 192.168.1.10
10+
11+
KEEPALIVED_VIRTUAL_IPS:
12+
- 192.168.1.231
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add your custom keepalived.conf file here or mount one at docker run to /etc/keepalived/keepalived.conf
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
vrrp_instance vip-1 {
2+
interface {{ keepalived_interface }}
3+
4+
track_interface {
5+
{{ keepalived_interface }}
6+
}
7+
8+
state MASTER
9+
virtual_router_id 51
10+
priority {{ keepalived_priority }}
11+
nopreempt
12+
13+
unicast_peer {
14+
{{ keepalived_unicast_peers }}
15+
}
16+
17+
virtual_ipaddress {
18+
{{ keepalived_virtual_ips }}
19+
}
20+
21+
authentication {
22+
auth_type PASS
23+
auth_pass {{ keepalived_password }}
24+
}
25+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash -e
2+
3+
FIRST_START_DONE="/etc/docker-keepalived-first-start-done"
4+
5+
# container first start
6+
if [ ! -e "$FIRST_START_DONE" ]; then
7+
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 /osixia/keepalived/keepalived.conf ]; then
12+
echo "Error: No default keepalived.conf found in /osixia/keepalived/keepalived.conf"
13+
exit 1
14+
else
15+
16+
ln -s /osixia/keepalived/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+
# unicast peers
26+
KEEPALIVED_UNICAST_PEERS=($KEEPALIVED_UNICAST_PEERS)
27+
for peer in "${KEEPALIVED_UNICAST_PEERS[@]}"
28+
do
29+
# it's just a peer
30+
# stored in a variable
31+
if [ -n "${!peer}" ]; then
32+
sed -i "s|{{ keepalived_unicast_peers }}|${!peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
33+
# directly
34+
else
35+
sed -i "s|{{ keepalived_unicast_peers }}|${peer}\n {{ keepalived_unicast_peers }}|g" /etc/keepalived/keepalived.conf
36+
fi
37+
done
38+
sed -i "/{{ keepalived_unicast_peers }}/d" /etc/keepalived/keepalived.conf
39+
40+
# virtual ips
41+
KEEPALIVED_VIRTUAL_IPS=($KEEPALIVED_VIRTUAL_IPS)
42+
for vip in "${KEEPALIVED_VIRTUAL_IPS[@]}"
43+
do
44+
# it's just a peer
45+
# stored in a variable
46+
if [ -n "${!vip}" ]; then
47+
sed -i "s|{{ keepalived_virtual_ips }}|${!vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
48+
# directly
49+
else
50+
sed -i "s|{{ keepalived_virtual_ips }}|${vip}\n {{ keepalived_virtual_ips }}|g" /etc/keepalived/keepalived.conf
51+
fi
52+
done
53+
sed -i "/{{ keepalived_virtual_ips }}/d" /etc/keepalived/keepalived.conf
54+
fi
55+
56+
fi
57+
58+
touch $FIRST_START_DONE
59+
fi
60+
61+
exit 0

image/service/keepalived/daemon.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash -e
2+
exec /usr/local/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console -D -d

test/test.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
load test_helper
3+
4+
@test "image build" {
5+
6+
run build_image
7+
[ "$status" -eq 0 ]
8+
9+
}

0 commit comments

Comments
 (0)