diff --git a/docker/Dockerfile.go_build b/docker/Dockerfile.go_build index 771c40212..d103db966 100644 --- a/docker/Dockerfile.go_build +++ b/docker/Dockerfile.go_build @@ -1,3 +1,4 @@ +# 2020-10-16 02:02:54 FROM frolvlad/alpine-glibc as builder RUN apk add git go g++ RUN mkdir -p /go/src/github.com/chrislusf/ @@ -12,11 +13,15 @@ WORKDIR seaweedfs/weed RUN go install FROM alpine AS final +RUN \ + apk add --no-cache --update bind-tools bash && \ + rm -rf /tmp/* LABEL author="Chris Lu" COPY --from=builder /root/go/bin/weed /usr/bin/ RUN mkdir -p /etc/seaweedfs COPY --from=builder /go/src/github.com/chrislusf/seaweedfs/docker/filer.toml /etc/seaweedfs/filer.toml COPY --from=builder /go/src/github.com/chrislusf/seaweedfs/docker/entrypoint.sh /entrypoint.sh +COPY --from=builder /go/src/github.com/chrislusf/seaweedfs/docker/start.sh /start.sh # volume server gprc port EXPOSE 18080 @@ -38,5 +43,6 @@ RUN mkdir -p /data/filerldb2 VOLUME /data RUN chmod +x /entrypoint.sh +RUN chmod +x /start.sh -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/start.sh"] diff --git a/docker/start.sh b/docker/start.sh new file mode 100644 index 000000000..200bcf776 --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- +# 2020-10-09 20:03:59 + +######################################################################################################################################################################################################################## + +sleep 3 + +# Read all commands +ARGS="" +IP="" +CIP="" +for ARG in $@; do + # Detect a *peers command + if [[ $ARG == *"peers="* ]]; then + # TODO detect quotes after the = + OPTION=$(expr "$ARG" : '\(.*=\)') + VALUE=$(expr "$ARG" : '.*=\(.*\)') + + echo "Detected ${OPTION}" + + # Split all peers + PEERS="" + IFS=',' read -ra ADDRS <<< "$VALUE" + for ADDR in "${ADDRS[@]}"; do + # Get HOST:PORT + HOST=$(expr "$ADDR" : '\(.*\):') + PORT=$(expr "$ADDR" : '.*:\(.*\)') + # Add directly IP peers + if [[ $HOST =~ ^[0-9\.]+$ ]]; then + PEERS=${PEERS:+${PEERS},}${HOST}:${PORT} + else + echo "Getting IPs for ${HOST}" + + # Get all tasks ips + typeset -i nbt + nbt=0 + SECONDS=0 + + echo "Waiting for the min peers count (${CLUSTER_SIZE})" + + while [[ $nbt -lt ${CLUSTER_SIZE} ]]; do + tips=$(dig @127.0.0.11 +short tasks.${HOST}) + nbt=$(echo $tips | wc -w) + [[ $SECONDS -gt 120 ]] && break + sleep 1 + done + for tip in $tips; do + echo "Adding peer: ${tip}" + PEERS=${PEERS:+${PEERS},}${tip}:${PORT} + + cip=$(grep ${tip} /etc/hosts | awk '{print $1}' | head -1) + if [[ -n "$cip" ]]; then + echo "Found current ip: ${cip}" + CIP="-ip=${cip}" + fi + done + + # TODO handle normal hostnames correctly, in case no service is found + # # Get all direct ips + # ips=$(dig @127.0.0.11 +short ${HOST}) + # for ip in $ips; do + # echo "Adding peer: ${ip}" + # PEERS=${PEERS:+${PEERS},}${ip}:${PORT} + # done + fi + done + + ARG=${PEERS:+${OPTION}${PEERS}} + # Detect an ip command + elif [[ $ARG == *"ip="* ]]; then + # Save the IP as a fallback + IP=$ARG + # Not writing the ip for now + ARG="" + fi + ARGS=${ARGS:+${ARGS} }$ARG +done + +if ! [ -z "$CIP" ]; then + ARGS=${ARGS:+${ARGS} }$CIP +elif ! [ -z "$IP" ]; then + ARGS=${ARGS:+${ARGS} }$IP +fi + +exec /entrypoint.sh $ARGS + +########################################################################################################################################################################################################################