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 29, 2024
1 parent 5681f67 commit da618ba
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,40 @@ RUN DEBIAN_FRONTEND=noninteractive \
&& 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

# FIXME: Consider moving this script into a Nix `writeShellApplication` trivial builder within the closure...
RUN cat <<EOF >> $HOME/.bashrc
# n.b. GitHub Codespaces are populated with \$GH_TOKEN already set
source $(grep -m 1 -e '-env.sh$' store-paths.txt)
EOF

# This enforce those settings in DevContainer whatever "Settings Sync" user preferences
RUN mkdir -p $HOME/.vscode-server/data/Machine/ \
&& cat <<EOF >> $HOME/.vscode-server/data/Machine/settings.json
{
"haskell.manageHLS": "PATH"
}
EOF

# FIXME: Consider moving this script into a Nix `writeShellApplication` trivial builder within the closure...
RUN mkdir -p /usr/local/bin/ \
&& cat <<EOF >> /usr/local/bin/haskell-language-server
#! /usr/bin/env bash

# The script remove itself to assert it is executed only once ...
rm /usr/local/bin/haskell-language-server

# n.b. GitHub Codespaces are populated with $GH_TOKEN already set
if [ -z "\$GH_TOKEN" ]; then
echo "A GitHub token is required for downloading HLS cache (optionnal)."
read -p "Would you like to enter your GitHub token now? (y/n) " yn
case \$yn in
[Yy]* )
read -sp "Enter your GitHub token: " GH_TOKEN;
export GH_TOKEN;;
[Nn]* )
return;;
* )
echo "Invalid response. Please answer yes (y) or no (n).";
return;;
esac
fi
CACHE_DIR="\$HOME/.cache"
if [ ! -d "\$CACHE_DIR" ]; then
echo "Attempting to download HLS cache from GitHub Artifact for faster first launch ..."
mkdir -p \$CACHE_DIR
pushd \$CACHE_DIR > /dev/null
PROJECT_DIR=\$(find /workspaces/ -mindepth 1 -maxdepth 1 -type d)
CACHE_DIR="$HOME/.cache"
mkdir -p $CACHE_DIR
pushd $CACHE_DIR > /dev/null
PROJECT_DIR=$(find /workspaces/ -mindepth 1 -maxdepth 1 -type d)
if [ -n "\$PROJECT_DIR" ]; then
CACHE_REV=\$(git -C "\$PROJECT_DIR" rev-parse HEAD)
gh run download -n "cache-\$CACHE_REV-$COMPILER_NIX_NAME"
gh run download -n "cache-\$(git -C "$PROJECT_DIR" rev-parse HEAD)-$COMPILER_NIX_NAME"
fi
popd > /dev/null
else
cabal update
fi
source \$(grep -m 1 -e '-env.sh$' store-paths.txt)

haskell-language-server \$@
EOF

0 comments on commit da618ba

Please sign in to comment.