storagenode: docker image autoupdate binaries

Get storagenode and storagenode-updater binaries during
run of the container to not to release new docker image
on each new version of the storagenode binary.

Change-Id: Ic0eb4a9c18a98598dfd9b96c1d352c7399496fd2
This commit is contained in:
Yaroslav Vorobiov 2020-08-05 12:43:49 +03:00
parent a9c9f080bb
commit 244c488b10
5 changed files with 141 additions and 22 deletions

View File

@ -178,14 +178,14 @@ satellite-image: satellite_linux_arm satellite_linux_arm64 satellite_linux_amd64
-f cmd/satellite/Dockerfile .
.PHONY: storagenode-image
storagenode-image: storagenode_linux_arm storagenode_linux_arm64 storagenode_linux_amd64 ## Build storagenode Docker image
storagenode-image: ## Build storagenode Docker image
${DOCKER_BUILD} --pull=true -t storjlabs/storagenode:${TAG}${CUSTOMTAG}-amd64 \
-f cmd/storagenode/Dockerfile .
${DOCKER_BUILD} --pull=true -t storjlabs/storagenode:${TAG}${CUSTOMTAG}-arm32v6 \
--build-arg=GOARCH=arm --build-arg=DOCKER_ARCH=arm32v6 \
--build-arg=GOARCH=arm --build-arg=DOCKER_ARCH=arm32v6 --build-arg=APK_ARCH=armhf \
-f cmd/storagenode/Dockerfile .
${DOCKER_BUILD} --pull=true -t storjlabs/storagenode:${TAG}${CUSTOMTAG}-arm64v8 \
--build-arg=GOARCH=arm --build-arg=DOCKER_ARCH=arm64v8 \
--build-arg=GOARCH=arm --build-arg=DOCKER_ARCH=arm64v8 --build-arg=APK_ARCH=aarch64 \
-f cmd/storagenode/Dockerfile .
.PHONY: uplink-image
uplink-image: uplink_linux_arm uplink_linux_arm64 uplink_linux_amd64 ## Build uplink Docker image

View File

@ -1,24 +1,33 @@
ARG DOCKER_ARCH
ARG APK_ARCH
# Fetch ca-certificates file for arch independent builds below
FROM alpine as ca-cert
# Fetch ca-certificates file and supervisor apk pkg with dependecies for arch independent builds below
FROM alpine as alpine
RUN apk -U add ca-certificates
RUN echo ${APK_ARCH:-x86_64} > /etc/apk/arch
RUN mkdir /tmp/apk-supervisor
RUN apk fetch --no-cache -R -o /tmp/apk-supervisor supervisor
FROM ${DOCKER_ARCH:-amd64}/alpine
ARG TAG
ARG GOARCH
ENV GOARCH ${GOARCH}
ARG VERSION_SERVER_URL
ENV GOARCH ${GOARCH:-amd64}
ENV VERSION_SERVER_URL ${VERSION_SERVER_URL:-https://version.storj.io}
EXPOSE 28967
WORKDIR /app
COPY --from=ca-cert /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY release/${TAG}/storagenode_linux_${GOARCH:-amd64} /app/storagenode
EXPOSE 14002
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=alpine /tmp/apk-supervisor/* /var/lib/apk-supervisor/
COPY cmd/storagenode/entrypoint /entrypoint
COPY cmd/storagenode/dashboard.sh /app/dashboard.sh
COPY cmd/storagenode/supervisord.conf /etc/supervisord.conf
COPY cmd/storagenode/systemctl /bin/systemctl
WORKDIR /app
ENTRYPOINT ["/entrypoint"]
# Remove after the alpha
ENV ADDRESS="" \
EMAIL="" \
WALLET="" \
STORAGE="2.0TB" \
SETUP="false"
SETUP="false" \
AUTO_UPDATE="true"

View File

@ -1,20 +1,90 @@
#!/bin/sh
set -euo pipefail
if [[ "${SETUP:-}" == "true" ]]
then
./storagenode setup --config-dir config --identity-dir identity
else
function get_default_url {
process=$1
version=$2
echo $(wget -O - "${VERSION_SERVER_URL}/processes/${process}/${version}/url?os=linux&arch=${GOARCH}")
}
function get_binary {
binary=$1
url=$2
wget -O - ${url} | unzip -p - > /app/${binary}
chmod u+x /app/${binary}
}
if [[ ! -f "storagenode-updater" ]]; then
echo "downloading storagenode-updater"
get_binary storagenode-updater $(get_default_url storagenode-updater minimum)
if ./storagenode-updater should-update storagenode-updater \
--binary-location /app/storagenode-updater \
--identity-dir identity \
--version.server-address=${VERSION_SERVER_URL} 2>/dev/null
then
echo "updating storagenode-updater"
get_binary storagenode-updater $(get_default_url storagenode-updater suggested)
fi
fi
if [[ ! -f "storagenode" ]]; then
echo "downloading storagenode"
if ./storagenode-updater should-update storagenode \
--identity-dir identity \
--version.server-address=${VERSION_SERVER_URL} 2>/dev/null
then
get_binary storagenode $(get_default_url storagenode suggested)
else
get_binary storagenode $(get_default_url storagenode minimum)
fi
fi
RUN_PARAMS="${RUN_PARAMS:-} --config-dir config"
RUN_PARAMS="${RUN_PARAMS:-} --identity-dir identity"
RUN_PARAMS="${RUN_PARAMS:-} --metrics.app-suffix=-alpha"
RUN_PARAMS="${RUN_PARAMS:-} --metrics.interval=30m"
RUN_PARAMS="${RUN_PARAMS:-} --contact.external-address=${ADDRESS}"
RUN_PARAMS="${RUN_PARAMS:-} --operator.email=${EMAIL}"
RUN_PARAMS="${RUN_PARAMS:-} --operator.wallet=${WALLET}"
RUN_PARAMS="${RUN_PARAMS:-} --console.address=:14002"
RUN_PARAMS="${RUN_PARAMS:-} --storage.allocated-disk-space=${STORAGE}"
exec ./storagenode run $RUN_PARAMS "$@"
if [[ -n "${VERSION_SERVER_URL:-}" ]]; then
RUN_PARAMS="${RUN_PARAMS:-} --version.server-address=${VERSION_SERVER_URL}"
fi
if [[ -n "${ADDRESS:-}" ]]; then
RUN_PARAMS="${RUN_PARAMS:-} --contact.external-address=${ADDRESS}"
fi
if [[ -n "${EMAIL:-}" ]]; then
RUN_PARAMS="${RUN_PARAMS:-} --operator.email=${EMAIL}"
fi
if [[ -n "${WALLET:-}" ]]; then
RUN_PARAMS="${RUN_PARAMS:-} --operator.wallet=${WALLET}"
fi
if [[ -n "${STORAGE:-}" ]]; then
RUN_PARAMS="${RUN_PARAMS:-} --storage.allocated-disk-space=${STORAGE}"
fi
if [[ "${AUTO_UPDATE:-}" != "true" ]]; then
AUTO_UPDATE="false"
fi
if [[ "${SETUP:-}" == "true" ]]; then
exec ./storagenode setup $RUN_PARAMS ${*}
else
# install supervisor
if ! apk list supervisor 2>/dev/null | grep "supervisor"; then
echo "installing supervisor"
mkdir -p /var/log/supervisor
# permorm installation during runtime to not use dockerfile RUN directive to support arch-independent build process
apk add --no-cache --repositories-file=/dev/null /var/lib/apk-supervisor/*.apk
sed -i \
"s#^command=/app/storagenode-updater\$#command=/app/storagenode-updater run --binary-location /app/storagenode ${RUN_PARAMS} ${*}#" \
/etc/supervisord.conf
sed -i \
"s#^command=/app/storagenode\$#command=/app/storagenode run ${RUN_PARAMS} ${*}#" \
/etc/supervisord.conf
fi
exec /usr/bin/supervisord -c /etc/supervisord.conf
fi

View File

@ -0,0 +1,32 @@
[supervisord]
user=root
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/run/supervisord.pid
childlogdir=/var/log/supervisor
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[inet_http_server]
port = 127.0.0.1:9001
[supervisorctl]
serverurl = http://127.0.0.1:9001
[program:storagenode-updater]
command=/app/storagenode-updater
autostart=%(ENV_AUTO_UPDATE)s
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stdout
stderr_logfile_maxbytes=0
[program:storagenode]
command=/app/storagenode
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stdout
stderr_logfile_maxbytes=0

8
cmd/storagenode/systemctl Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
if [[ "$*" != "show --property=MainPID storagenode" ]]; then
echo "invalid command" >&2
exit 1
fi
printf "MainPID=$(supervisorctl pid storagenode)"