diff --git a/.dockerignore b/.dockerignore index 47a15aa..e8b08f9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ docs/ vendor/.cache/ vendor/shards/install/ +vendor/ci//bin/ .github/ bin/ data/ @@ -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 diff --git a/Dockerfile b/Dockerfile index d6bf46e..8a27bdd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/script/bootstrap b/script/bootstrap index 3554bce..39938ee 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -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 $@ diff --git a/script/compute-dep-shas b/script/compute-dep-shas new file mode 100755 index 0000000..e609dd5 --- /dev/null +++ b/script/compute-dep-shas @@ -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 diff --git a/script/unzipper b/script/unzipper index 1f9415a..f323ab3 100755 --- a/script/unzipper +++ b/script/unzipper @@ -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" @@ -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 @@ -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 @@ -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"