Skip to content

Commit 975ec0b

Browse files
authored
Script for downloading snapshots using s5cmd and pigz (#120)
* add s5cmd to image * add pigz to test faster decompress * add downloading to script * add concurrency parameter * Add metrics to the download script
1 parent e69faa0 commit 975ec0b

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ ARG VERSION
44

55
RUN apk --update add gcc git curl alpine-sdk libc6-compat ca-certificates sqlite \
66
&& curl -SsL https://github.com/segmentio/chamber/releases/download/v2.13.2/chamber-v2.13.2-linux-amd64 -o /bin/chamber \
7-
&& chmod +x /bin/chamber
7+
&& curl -sL https://github.com/peak/s5cmd/releases/download/v2.1.0/s5cmd_2.1.0_Linux-64bit.tar.gz -o s5cmd.gz && tar -xzf s5cmd.gz -C /bin \
8+
&& chmod +x /bin/chamber \
9+
&& chmod +x /bin/s5cmd
10+
811

912
COPY . /go/src/${SRC}
1013
WORKDIR /go/src/${SRC}
@@ -15,11 +18,11 @@ RUN CGO_ENABLED=1 go install -ldflags="-X github.com/segmentio/ctlstore/pkg/vers
1518
RUN CGO_ENABLED=1 go install -ldflags="-X github.com/segmentio/ctlstore/pkg/version.version=$VERSION" ${SRC}/pkg/cmd/ctlstore-cli \
1619
&& cp ${GOPATH}/bin/ctlstore-cli /usr/local/bin
1720

18-
RUN apk del gcc git curl alpine-sdk libc6-compat
19-
2021
FROM alpine
21-
RUN apk --no-cache add sqlite
22+
RUN apk --no-cache add sqlite pigz
2223

24+
COPY --from=0 /go/src/github.com/segmentio/ctlstore/scripts/download.sh .
2325
COPY --from=0 /bin/chamber /bin/chamber
26+
COPY --from=0 /bin/s5cmd /bin/s5cmd
2427
COPY --from=0 /usr/local/bin/ctlstore /usr/local/bin/
2528
COPY --from=0 /usr/local/bin/ctlstore-cli /usr/local/bin/

scripts/download.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env sh
2+
3+
set -eo pipefail
4+
5+
CTLSTORE_BOOTSTRAP_URL=$1
6+
CONCURRENCY=${2:-20}
7+
STATS_IP=$3
8+
STATS_PORT=${4:-8125}
9+
10+
TAGS="downloaded:false"
11+
START=$(date +%s)
12+
END=$(date +%s)
13+
if [ ! -f /var/spool/ctlstore/ldb.db ]; then
14+
# busybox does not support sub-second resolution
15+
START=$(date +%s)
16+
17+
mkdir -p /var/spool/ctlstore
18+
cd /var/spool/ctlstore
19+
s5cmd -r 0 --log debug cp --concurrency $CONCURRENCY $CTLSTORE_BOOTSTRAP_URL .
20+
21+
TAGS="downloaded:true"
22+
if [[ ${CTLSTORE_BOOTSTRAP_URL: -2} == gz ]]; then
23+
echo "Decompressing"
24+
pigz -d snapshot.db.gz
25+
TAGS="$TAGS,compressed:true"
26+
fi
27+
28+
TAGS="$TAGS,concurrency:$CONCURRENCY"
29+
30+
mv snapshot.db ldb.db
31+
END=$(date +%s)
32+
echo "ldb.db ready in $(($END - $START)) seconds"
33+
else
34+
echo "Snapshot already present"
35+
fi
36+
37+
if [ ! -z "$STATS_IP" ]; then
38+
echo -n "ctlstore.reflector.init_snapshot_download_time:$(($END - $START))|h|#$TAGS" | nc -u -w1 $NODE_IP $STATS_PORT
39+
fi

0 commit comments

Comments
 (0)