Skip to content

Commit

Permalink
feat: start cron via entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman committed Jan 14, 2025
1 parent af6a667 commit b7ce84d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
16 changes: 10 additions & 6 deletions 010-pin-cids.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/env sh

# Mount this file into docker container:
# docker run \
Expand All @@ -9,22 +9,26 @@

set -e

WGET_ARGS="--quiet --no-check-certificate"
GATEWAY=${GATEWAY:-https://ipfs.io}

echo "Fetching list of CIDs to pin"

LIST=$(mktemp)
wget https://raw.githubusercontent.com/lidofinance/csm-rewards/refs/heads/artifact/cids -O$LIST
trap "rm $LIST" EXIT

wget https://raw.githubusercontent.com/lidofinance/csm-rewards/refs/heads/artifact/cids -O$LIST $WGET_ARGS

echo "Bootstrap pinned CIDs"
while IFS= read -r cid; do
{
set -x
ipfs pin add $cid && continue
ipfs pin add ${cid} && continue || echo "Fetching ${cid} from remote"

FILE=$(mktemp)
wget $GATEWAY/ipfs/$cid -O$FILE --no-check-certificate
wget $GATEWAY/ipfs/${cid} -O$FILE $WGET_ARGS
ipfs add $FILE && rm $FILE
ipfs pin add $cid
}
done < $LIST
rm $LIST

echo "CIDs bootstrap complete!"
10 changes: 4 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ services:
restart: unless-stopped
volumes:
- ./010-pin-cids.sh:/container-init.d/010-pin-cids.sh
- .ipfs/:/data/ipfs
entrypoint: []
command:
- ./entrypoint.sh:/entrypoint.sh
entrypoint:
- /sbin/tini
- --
- timeout
- 600s
- /usr/local/bin/start_ipfs
- /entrypoint.sh
command:
- daemon
- --migrate=true
- --agent-version-suffix=docker
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

# NOTE: crond has to be invoked by root, otherwise it won't be able to run a job.
# crontab files have to have uid=0, and it's impossible to do via chown with no
# root privileges. So all the crond-related commands are in the entrypoint.

INIT_DIR=/container-init.d
CRONTABS=$INIT_DIR/crontabs
BOOTSTRAP_SCRIPT=$INIT_DIR/010-pin-cids.sh

if [ ! -e $CRONTABS ]; then mkdir -p $CRONTABS; fi
if [ ! -e $BOOTSTRAP_SCRIPT ]; then echo "Make sure $BOOTSTRAP_SCRIPT is mounted" && exit 1; fi

printf "@hourly timeout 600s $BOOTSTRAP_SCRIPT >&2\n" > $CRONTABS/ipfs
echo "Starting crond" && /bin/crond -c$CRONTABS

exec /usr/local/bin/start_ipfs "$@"

0 comments on commit b7ce84d

Please sign in to comment.