2024-04-10 16:35:38 +03:00
|
|
|
# We build the Docker image from a Dockerfile rather than from a Nix expression
|
|
|
|
# This is because VSCode DevContainer / GitHub Codespace run an install script
|
|
|
|
# at first launch that mostly consider your machine to be Debian-based.
|
2023-07-04 12:40:37 +03:00
|
|
|
FROM ubuntu:rolling
|
2024-04-10 16:35:38 +03:00
|
|
|
# TODO: But there is likely a better immutable way to build this image ...
|
|
|
|
# https://github.com/input-output-hk/devx-aux/issues/115
|
2023-07-04 12:40:37 +03:00
|
|
|
WORKDIR /workspaces
|
|
|
|
|
2023-08-03 00:23:06 +03:00
|
|
|
ARG PLATFORM="x86_64-linux"
|
|
|
|
ARG TARGET_PLATFORM=""
|
2024-04-08 12:27:17 +03:00
|
|
|
ARG COMPILER_NIX_NAME="ghc96"
|
|
|
|
ARG MINIMAL="false"
|
|
|
|
ARG IOG="true"
|
2024-04-10 11:20:07 +03:00
|
|
|
ARG IOG_FULL="false"
|
2023-08-03 00:23:06 +03:00
|
|
|
|
2024-02-27 15:45:59 +03:00
|
|
|
RUN DEBIAN_FRONTEND=noninteractive \
|
|
|
|
&& apt-get update \
|
2024-04-08 12:27:17 +03:00
|
|
|
&& apt-get -y install curl gh git grep jq nix rsync zstd \
|
2023-07-04 12:40:37 +03:00
|
|
|
&& curl -L https://raw.githubusercontent.com/input-output-hk/actions/latest/devx/support/fetch-docker.sh -o fetch-docker.sh \
|
|
|
|
&& chmod +x fetch-docker.sh \
|
|
|
|
&& SUFFIX='' \
|
2023-08-03 00:23:06 +03:00
|
|
|
&& if [ "$MINIMAL" = "true" ]; then SUFFIX="${SUFFIX}-minimal"; fi \
|
|
|
|
&& if [ "$IOG" = "true" ]; then SUFFIX="${SUFFIX}-iog"; fi \
|
2024-04-10 11:20:07 +03:00
|
|
|
&& if [ "$IOG_FULL" = "true" ]; then SUFFIX="${SUFFIX}-full"; fi \
|
2024-04-08 12:27:17 +03:00
|
|
|
&& ./fetch-docker.sh input-output-hk/devx $PLATFORM.$COMPILER_NIX_NAME$TARGET_PLATFORM${SUFFIX}-env | zstd -d | nix-store --import | tee store-paths.txt
|
2023-07-04 12:40:37 +03:00
|
|
|
|
2024-04-08 12:27:17 +03:00
|
|
|
RUN cat <<EOF >> $HOME/.bashrc
|
|
|
|
source $(grep -m 1 -e '-env.sh$' store-paths.txt)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# This enforce those settings in DevContainer whatever "Settings Sync" user preferences ...
|
2024-04-11 10:09:27 +03:00
|
|
|
# ... VSCode DevContainer and GitHub Codespace does not look for the same settings file ><'
|
|
|
|
RUN mkdir -p $HOME/.vscode-server/data/Machine/ \
|
|
|
|
&& mkdir -p $HOME/.vscode-remote/data/Machine/ \
|
|
|
|
&& bash -ic 'echo -e "{\n \
|
|
|
|
\"haskell.manageHLS\": \"PATH\",\n \
|
|
|
|
\"haskell.serverEnvironment\": { \"PATH\": \"$PATH\" },\n \
|
|
|
|
\"haskell.serverExecutablePath\": \"$(which haskell-language-server)\"\n \
|
|
|
|
}" > $HOME/.vscode-server/data/Machine/settings.json' \
|
|
|
|
&& cp $HOME/.vscode-server/data/Machine/settings.json $HOME/.vscode-remote/data/Machine/settings.json
|
2024-04-08 12:27:17 +03:00
|
|
|
|
|
|
|
# FIXME: Consider moving this script into a Nix `writeShellApplication` trivial builder within the closure ...
|
|
|
|
# ... but that means I should figure it out how to pass to it $COMPILER_NIX_NAME as input?
|
|
|
|
RUN mkdir -p /usr/local/bin/ \
|
|
|
|
&& cat <<EOF >> /usr/local/bin/post-create-command
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-04-10 16:35:38 +03:00
|
|
|
PROJECT_DIR=\$(find /workspaces/ -mindepth 1 -maxdepth 1 -type d ! -name '.*' -print -quit)
|
2024-04-08 12:27:17 +03:00
|
|
|
if [ -n "\$PROJECT_DIR" ]; then
|
|
|
|
pushd \$PROJECT_DIR > /dev/null
|
2024-04-10 16:35:38 +03:00
|
|
|
# GitHub Codespaces should have \$GITHUB_TOKEN already set.
|
|
|
|
if [ -n "\$GITHUB_TOKEN" ]; then
|
|
|
|
echo \$GITHUB_TOKEN | gh auth login --with-token
|
2024-04-08 12:27:17 +03:00
|
|
|
COMMIT_HASH=\$(git rev-parse HEAD)
|
|
|
|
echo "Attempting to download HLS cache from GitHub Artifact (cache-\$COMMIT_HASH-$COMPILER_NIX_NAME) for faster first launch ..."
|
|
|
|
gh run download -D .download -n "cache-\$COMMIT_HASH-$COMPILER_NIX_NAME"
|
|
|
|
rsync -a .download/work/cardano-base/cardano-base/dist-newstyle .
|
|
|
|
rm -r .download
|
|
|
|
else
|
2024-04-10 16:35:38 +03:00
|
|
|
echo "\\\$GITHUB_TOKEN is not set. Skipping HLS cache download."
|
2024-04-08 12:27:17 +03:00
|
|
|
fi
|
|
|
|
# HLS error (Couldn't load cradle for ghc libdir) if `cabal update` has never been run in project using cardano-haskell-packages ...
|
|
|
|
echo "Running `cabal update` ..."
|
|
|
|
bash -c "cabal update"
|
|
|
|
popd > /dev/null
|
|
|
|
fi
|
|
|
|
EOF
|
|
|
|
RUN chmod +x /usr/local/bin/post-create-command
|