Skip to content

Commit

Permalink
Merge pull request #9 from GrantBirki/bootstrap-fixes
Browse files Browse the repository at this point in the history
add a helper script to recompute shas
  • Loading branch information
GrantBirki authored Sep 5, 2024
2 parents b22be3d + 4af645e commit 13754f5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
docs/
vendor/.cache/
vendor/shards/install/
vendor/ci//bin/
.github/
bin/
data/
Expand All @@ -12,3 +13,12 @@ docker-compose.yml
docker-compose.override.yml
docker-compose.production.yml
tmp/
.ameba.yml
script/release
script/deploy
script/update
script/lint
script/format
script/acceptance
script/all
script/test
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ WORKDIR /app
RUN apt-get update && apt-get install -y unzip

# copy core scripts
COPY script/preinstall script/preinstall
COPY script/bootstrap script/bootstrap
COPY script/postinstall script/postinstall
COPY script/unzipper script/unzipper
COPY script/ script/

# copy all vendored dependencies
COPY vendor/shards/cache/ vendor/shards/cache/
Expand Down
4 changes: 4 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ if [[ "$@" == *"--ci"* ]]; then
ci_flags="--skip-postinstall --skip-executables"
fi

# install the shards
SHARDS_CACHE_PATH="$SHARDS_CACHE_PATH" SHARDS_INSTALL_PATH="$SHARDS_INSTALL_PATH" shards install --local --frozen $ci_flags $@

# shards install often wipes out our custom shards sha256 file so we need to recompute it if they are gone
script/compute-dep-shas

script/postinstall $@
31 changes: 31 additions & 0 deletions script/compute-dep-shas
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# set the working directory to the root of the project
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
VENDOR_DIR="$DIR/vendor"
SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"
SHARDS_CACHED="$VENDOR_DIR/shards/cache"

SHARD_SHA_FILE=".shard.vendor.cache.sha256"

file="vendor/shards/install/.shards.info"

if [ -f "$VENDOR_DIR/shards/install/.shards.info" ]; then

# Use yq to parse the file and extract shard names and versions
shards=$(yq eval '.shards | to_entries | .[] | "\(.key)|\(.value.git)|\(.value.version)"' $file)

# Loop over each shard
echo "$shards" | while IFS= read -r shard; do
# Extract name and version
name=$(echo $shard | cut -d'|' -f1)
version=$(echo $shard | cut -d'|' -f3)

# if the shard sha256 file does not exist, try to compute and create it
if [ ! -f "$SHARDS_INSTALL_PATH/name/$SHARD_SHA_FILE" ]; then
shard_cache_sha=$(shasum -a 256 "$SHARDS_CACHED/$name-$version.shard" | cut -d' ' -f1)
cat > "$SHARDS_INSTALL_PATH/$name/$SHARD_SHA_FILE" <<< "$shard_cache_sha"
fi
done
fi
15 changes: 11 additions & 4 deletions script/unzipper
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SHARDS_CACHE_PATH="$VENDOR_DIR/.cache/shards"
SHARDS_INSTALL_PATH="$VENDOR_DIR/shards/install"
SHARDS_CACHED="$VENDOR_DIR/shards/cache"

SHARD_SHA_FILE=".shard.vendor.cache.sha256"

TRASHDIR=$(mktemp -d /tmp/bootstrap.XXXXXXXXXXXXXXXXX)
cleanup() {
rm -rf "$TRASHDIR"
Expand Down Expand Up @@ -39,6 +41,11 @@ if [ ! -f "$VENDOR_DIR/shards/install/.shards.info" ]; then
# cleanup the TRASHDIR
rm -rf "$TRASHDIR/shard"
rm -rf "$TRASHDIR/cache"

shard_cache_sha=$(shasum -a 256 "$shard" | cut -d' ' -f1)

# write the new sha to the $SHARD_SHA_FILE file
cat > "$SHARDS_INSTALL_PATH/$shard_name/$SHARD_SHA_FILE" <<< "$shard_cache_sha"
done

else
Expand All @@ -57,8 +64,8 @@ else

shard_cache_sha=$(shasum -a 256 "$SHARDS_CACHED/$name-$version.shard" | cut -d' ' -f1)
shard_current_sha=""
if [ -f "$SHARDS_INSTALL_PATH/$name/.shard.vendor.cache.sha256" ]; then
shard_current_sha=$(cat "$SHARDS_INSTALL_PATH/$name/.shard.vendor.cache.sha256")
if [ -f "$SHARDS_INSTALL_PATH/$name/$SHARD_SHA_FILE" ]; then
shard_current_sha=$(cat "$SHARDS_INSTALL_PATH/$name/$SHARD_SHA_FILE")
fi

if [ "$shard_cache_sha" != "$shard_current_sha" ]; then
Expand All @@ -74,8 +81,8 @@ else
mv -f "$TRASHDIR/shard/"* "$SHARDS_INSTALL_PATH/" 2>/dev/null || true
mv -f "$TRASHDIR/cache/"* "$SHARDS_CACHE_PATH/github.com/" 2>/dev/null || true

# write the new sha to the .shard.vendor.cache.sha256 file
cat > "$SHARDS_INSTALL_PATH/$name/.shard.vendor.cache.sha256" <<< "$shard_cache_sha"
# write the new sha to the $SHARD_SHA_FILE file
cat > "$SHARDS_INSTALL_PATH/$name/$SHARD_SHA_FILE" <<< "$shard_cache_sha"

# cleanup the TRASHDIR
rm -rf "$TRASHDIR/shard"
Expand Down

0 comments on commit 13754f5

Please sign in to comment.