use alpine

This commit is contained in:
Bertrand Gouny 2017-04-02 14:25:09 +02:00
parent 0b2ba5f4bf
commit b89cdbae27
7 changed files with 83 additions and 42 deletions

View File

@ -2,6 +2,8 @@
## 1.3.6 ## 1.3.6
- Fix startup.sh and finish.sh ip address removal - Fix startup.sh and finish.sh ip address removal
- Use linux alpine
- Add keepalived_script script user
## 1.3.5 ## 1.3.5
- Keepalived version 1.3.5 - Keepalived version 1.3.5

View File

@ -1,25 +1,29 @@
# Use osixia/light-baseimage # Use osixia/light-baseimage
# sources: https://github.com/osixia/docker-light-baseimage # sources: https://github.com/osixia/docker-light-baseimage
FROM osixia/light-baseimage:0.2.6 FROM osixia/alpine-light-baseimage:0.1.2
MAINTAINER Bertrand Gouny <bertrand.gouny@osixia.net> MAINTAINER Bertrand Gouny <bertrand.gouny@osixia.net>
# Keepalived version # Keepalived version
ENV KEEPALIVED_VERSION 1.3.5 ENV KEEPALIVED_VERSION 1.3.5
RUN addgroup -S keepalived_script && adduser -D -S -G keepalived_script keepalived_script
# Download, build and install Keepalived # Download, build and install Keepalived
RUN apt-get -y update \ RUN apk --no-cache add \
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl \ curl \
gcc \ gcc \
ipset \
ipset-dev \
iptables \
iptables-dev \ iptables-dev \
libipset-dev \ libnfnetlink \
libnl-3-dev \
libnl-genl-3-dev \
libnl-route-3-dev \
libnfnetlink-dev \ libnfnetlink-dev \
libssl-dev \ libnl3 \
libnl3-dev \
make \ make \
pkg-config \ musl-dev \
openssl \
openssl-dev \
&& curl -o keepalived.tar.gz -SL http://keepalived.org/software/keepalived-${KEEPALIVED_VERSION}.tar.gz \ && curl -o keepalived.tar.gz -SL http://keepalived.org/software/keepalived-${KEEPALIVED_VERSION}.tar.gz \
&& mkdir -p /container/keepalived-sources \ && mkdir -p /container/keepalived-sources \
&& tar -xzf keepalived.tar.gz --strip 1 -C /container/keepalived-sources \ && tar -xzf keepalived.tar.gz --strip 1 -C /container/keepalived-sources \
@ -27,11 +31,18 @@ RUN apt-get -y update \
&& ./configure --disable-dynamic-linking \ && ./configure --disable-dynamic-linking \
&& make && make install \ && make && make install \
&& cd - && mkdir -p /etc/keepalived \ && cd - && mkdir -p /etc/keepalived \
&& apt-get remove -y --purge --auto-remove curl make gcc pkg-config \
&& rm -f keepalived.tar.gz \ && rm -f keepalived.tar.gz \
&& rm -rf /container/keepalived-sources \ && rm -rf /container/keepalived-sources \
&& apt-get clean \ && apk --no-cache del \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* gcc \
ipset-dev \
iptables-dev \
libnfnetlink-dev \
libnl3-dev \
make \
musl-dev \
openssl-dev
# Add service directory to /container/service # Add service directory to /container/service
ADD service /container/service ADD service /container/service

View File

@ -1,16 +0,0 @@
KEEPALIVED_INTERFACE: eth0
KEEPALIVED_PASSWORD: d0cker
# For electing MASTER, highest priority wins.
# to be MASTER, make 50 more than other machines
KEEPALIVED_PRIORITY: 150
KEEPALIVED_UNICAST_PEERS:
- 192.168.1.10
- 192.168.1.11
KEEPALIVED_VIRTUAL_IPS:
- 192.168.1.231
- 192.168.1.232
KEEPALIVED_NOTIFY: /container/service/keepalived/assets/notify.sh

View File

@ -1 +1,18 @@
KEEPALIVED_COMMAND_LINE_ARGUMENTS: --log-detail --dump-conf KEEPALIVED_COMMAND_LINE_ARGUMENTS: --log-detail --dump-conf
KEEPALIVED_INTERFACE: eth0
KEEPALIVED_PASSWORD: d0cker
# For electing MASTER, highest priority wins.
# to be MASTER, make 50 more than other machines
KEEPALIVED_PRIORITY: 150
KEEPALIVED_UNICAST_PEERS:
- 192.168.1.10
- 192.168.1.11
KEEPALIVED_VIRTUAL_IPS:
- 192.168.1.231
- 192.168.1.232
KEEPALIVED_NOTIFY: /container/service/keepalived/assets/notify.sh

View File

@ -7,7 +7,20 @@ log-helper level eq trace && set -x
# try to delete virtual ips from interface # try to delete virtual ips from interface
for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS) for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS)
do do
ip addr del ${!vip}/32 dev ${KEEPALIVED_INTERFACE} || true IP_INFO=$(ip addr list | grep ${!vip}) || continue
IP_V6=$(echo "${IP_INFO}" | grep "inet6")
IP_IP=$(echo "${IP_INFO}" | awk '{print $2}')
# ipv4
if [ -z "${IP_V6}" ]; then
IP_INTERFACE=$(echo "${IP_INFO}" | awk '{print $5}')
# ipv6
else
echo "skipping address: ${IP_IP} - ipv6 not supported yet :("
continue
fi
ip addr del ${IP_IP} dev ${IP_INTERFACE} || true
done done
exit 0 exit 0

View File

@ -4,4 +4,4 @@
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper # https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
log-helper level eq trace && set -x log-helper level eq trace && set -x
exec /usr/local/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork --log-console ${KEEPALIVED_COMMAND_LINE_ARGUMENTS} exec /usr/local/sbin/keepalived -f /usr/local/etc/keepalived/keepalived.conf --dont-fork --log-console ${KEEPALIVED_COMMAND_LINE_ARGUMENTS}

View File

@ -11,30 +11,31 @@ if [ ! -e "$FIRST_START_DONE" ]; then
# #
# bootstrap config # bootstrap config
# #
sed -i --follow-symlinks "s|{{ KEEPALIVED_INTERFACE }}|$KEEPALIVED_INTERFACE|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_INTERFACE }}|$KEEPALIVED_INTERFACE|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
sed -i --follow-symlinks "s|{{ KEEPALIVED_PRIORITY }}|$KEEPALIVED_PRIORITY|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_PRIORITY }}|$KEEPALIVED_PRIORITY|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
sed -i --follow-symlinks "s|{{ KEEPALIVED_PASSWORD }}|$KEEPALIVED_PASSWORD|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_PASSWORD }}|$KEEPALIVED_PASSWORD|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
if [ -n "$KEEPALIVED_NOTIFY" ]; then if [ -n "$KEEPALIVED_NOTIFY" ]; then
sed -i --follow-symlinks "s|{{ KEEPALIVED_NOTIFY }}|notify \"$KEEPALIVED_NOTIFY\"|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_NOTIFY }}|notify \"$KEEPALIVED_NOTIFY\"|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
chown keepalived_script:keepalived_script $KEEPALIVED_NOTIFY
chmod +x $KEEPALIVED_NOTIFY chmod +x $KEEPALIVED_NOTIFY
else else
sed -i --follow-symlinks "/{{ KEEPALIVED_NOTIFY }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "/{{ KEEPALIVED_NOTIFY }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
fi fi
# unicast peers # unicast peers
for peer in $(complex-bash-env iterate KEEPALIVED_UNICAST_PEERS) for peer in $(complex-bash-env iterate KEEPALIVED_UNICAST_PEERS)
do do
sed -i --follow-symlinks "s|{{ KEEPALIVED_UNICAST_PEERS }}|${!peer}\n {{ KEEPALIVED_UNICAST_PEERS }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_UNICAST_PEERS }}|${!peer}\n {{ KEEPALIVED_UNICAST_PEERS }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
done done
sed -i --follow-symlinks "/{{ KEEPALIVED_UNICAST_PEERS }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "/{{ KEEPALIVED_UNICAST_PEERS }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
# virtual ips # virtual ips
for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS) for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS)
do do
sed -i --follow-symlinks "s|{{ KEEPALIVED_VIRTUAL_IPS }}|${!vip}\n {{ KEEPALIVED_VIRTUAL_IPS }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "s|{{ KEEPALIVED_VIRTUAL_IPS }}|${!vip}\n {{ KEEPALIVED_VIRTUAL_IPS }}|g" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
done done
sed -i --follow-symlinks "/{{ KEEPALIVED_VIRTUAL_IPS }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf sed -i "/{{ KEEPALIVED_VIRTUAL_IPS }}/d" ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf
touch $FIRST_START_DONE touch $FIRST_START_DONE
fi fi
@ -42,11 +43,24 @@ fi
# try to delete virtual ips from interface # try to delete virtual ips from interface
for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS) for vip in $(complex-bash-env iterate KEEPALIVED_VIRTUAL_IPS)
do do
ip addr del ${!vip}/32 dev ${KEEPALIVED_INTERFACE} || true IP_INFO=$(ip addr list | grep ${!vip}) || continue
IP_V6=$(echo "${IP_INFO}" | grep "inet6")
IP_IP=$(echo "${IP_INFO}" | awk '{print $2}')
# ipv4
if [ -z "${IP_V6}" ]; then
IP_INTERFACE=$(echo "${IP_INFO}" | awk '{print $5}')
# ipv6
else
echo "skipping address: ${IP_IP} - ipv6 not supported yet :("
continue
fi
ip addr del ${IP_IP} dev ${IP_INTERFACE} || true
done done
if [ ! -e "/etc/keepalived/keepalived.conf" ]; then if [ ! -e "/usr/local/etc/keepalived/keepalived.conf" ]; then
ln -sf ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf /etc/keepalived/keepalived.conf ln -sf ${CONTAINER_SERVICE_DIR}/keepalived/assets/keepalived.conf /usr/local/etc/keepalived/keepalived.conf
fi fi
exit 0 exit 0