Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Mar 7, 2024
1 parent 2f4fa7f commit 7f331d4
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ RUN DEBIAN_FRONTEND=noninteractive \
&& SUFFIX='' \
&& if [ "$MINIMAL" = "true" ]; then SUFFIX="${SUFFIX}-minimal"; fi \
&& if [ "$IOG" = "true" ]; then SUFFIX="${SUFFIX}-iog"; fi \
&& ./fetch-docker.sh input-output-hk/devx $PLATFORM.$COMPILER_NIX_NAME$TARGET_PLATFORM${SUFFIX}-env | zstd -d | nix-store --import | tee store-paths.txt \
&& apt-get -y remove curl git jq nix zstd \
&& apt-get -y autoremove \
&& apt-get -y autoclean
&& ./fetch-docker.sh input-output-hk/devx $PLATFORM.$COMPILER_NIX_NAME$TARGET_PLATFORM${SUFFIX}-env | zstd -d | nix-store --import | tee store-paths.txt

# `tail -n 2 X | head -n 1` seems a bit fragile way to get `ghc8107-iog-env.sh` derivation path ...
RUN echo "source $(tail -n 2 store-paths.txt | head -n 1)" >> $HOME/.bashrc
RUN cat <<EOF >> $HOME/.bashrc
CACHE_DIR="$HOME/.cache"
if [ ! -d "$CACHE_DIR" ]; then
REPO_URL=$(git config --get remote.origin.url)
GITHUB_REPO=$(basename -s .git "$REPO_URL")
COMMIT_HASH=$(git rev-parse HEAD)
ARTIFACT_NAME="cache-${COMMIT_HASH}"
RUN_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/$GITHUB_REPO/actions/runs?branch=master&status=success&event=push&per_page=1" | jq -r --arg COMMIT_HASH "$COMMIT_HASH" '.workflow_runs[] | select(.head_sha==$COMMIT_HASH).id')
ARTIFACT_URL=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/$GITHUB_REPO/actions/runs/$RUN_ID/artifacts" | jq -r --arg ARTIFACT_NAME "$ARTIFACT_NAME" '.artifacts[] | select(.name==$ARTIFACT_NAME).archive_download_url')
if [ ! -z "$ARTIFACT_URL" ]; then
curl -L -o "artifact.zstd" -H "Authorization: token $GITHUB_TOKEN" "$ARTIFACT_URL" && zstd -d "artifact.zstd" --output-dir-flat "$CACHE_DIR" && rm artifact.zstd
fi
fi
# Handling the fragile way to get, e.g., `ghc8107-iog-env.sh` derivation path
echo "source $(tail -n 2 store-paths.txt | head -n 1)"
EOF

0 comments on commit 7f331d4

Please sign in to comment.