Created
May 30, 2025 08:22
-
-
Save mpickering/ede013c8eaa9295ae028017e98eeb7bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
usage() { | |
echo "$0 (job-name)" | |
exit 1 | |
} | |
if [[ -z "$JOB_NAME" ]]; then | |
JOB_NAME="$1" | |
shift | |
fi | |
if [[ -z "$JOB_NAME" ]]; then | |
usage | |
fi | |
COMMIT="$1" | |
if [[ -z "$COMMIT" ]]; then | |
COMMIT="master" | |
shift | |
fi | |
echo "$COMMIT" | |
jobs_yaml=$(curl "https://gitlab.haskell.org/ghc/ghc/-/raw/$COMMIT/.gitlab/jobs.yaml") | |
DOCKER_REV=$(curl "https://gitlab.haskell.org/ghc/ghc/-/raw/$COMMIT/.gitlab-ci.yml" | grep " DOCKER_REV" | sed 's/ DOCKER_REV: \(.*\)/\1/') | |
echo "DOCKER_REV: $DOCKER_REV" | |
sel() { | |
echo "$jobs_yaml" | tail -n +2 | jq -r ".\"$JOB_NAME\"$1" | |
} | |
if [[ -z "$BUILD_FLAVOUR" ]]; then | |
BUILD_FLAVOUR="validate" | |
fi | |
IMAGE=$(sel ".image" | sed -e "s/\$DOCKER_REV/$DOCKER_REV/") | |
echo ${IMAGE} | |
VARIABLES=$(sel ".variables | to_entries | .[] | select(.value | . != null and . != \"\") | \"ENV \(.key) \(.value)\"") | |
echo "$VARIABLES" | |
RUN_SCRIPT=$(sel ".script | join(\" && \")") | |
echo $RUN_SCRIPT | |
tmp="$(mktemp -d)" | |
mkdir -p "$tmp" | |
cat >"$tmp/run_script" <<EOF | |
#! /usr/bin/env bash | |
set -e | |
$(sel ".script | join (\" \n\")") | |
EOF | |
cat "$tmp/run_script" | |
#C=$(docker container create --name="ghc-docker" $IMAGE) | |
#RUN sudo sed -i -e 's/deb.debian.org/archive.debian.org/g' \ | |
# -e 's|security.debian.org|archive.debian.org/|g' \ | |
# -e '/stretch-updates/d' /etc/apt/sources.list | |
#RUN git -C ghc remote add sheaf https://gitlab.haskell.org/sheaf/ghc.git | |
#RUN git -C ghc fetch sheaf | |
#RUN git -C ghc checkout $COMMIT && \ | |
# git -C ghc submodule update --init | |
cat >"$tmp/Dockerfile" <<EOF | |
FROM $IMAGE | |
RUN git config --global user.email "$(git config --global --get user.email)" && \ | |
git config --global user.name "$(git config --global --get user.name)" | |
RUN if which apt-get; then \ | |
sudo apt-get update && sudo apt-get install -y vim htop tmux gdb strace; \ | |
elif which apk; then \ | |
sudo apk add vim htop tmux gdb strace; \ | |
elif which dnf; then \ | |
sudo dnf install -y vim htop tmux gdb strace; \ | |
fi | |
RUN git config --global http.version HTTP/1.1 | |
RUN mkdir -p ghc && cd ghc && git init | |
RUN cd ghc && git remote add origin https://push:[email protected]/ghc/ghc.git | |
RUN cd ghc && git fetch --depth 1 origin $COMMIT && git checkout $COMMIT && \ | |
git submodule update --init | |
WORKDIR /home/ghc/ghc | |
$VARIABLES | |
ENV CPUS 6 | |
COPY "\$tmp/run_script" . | |
RUN sudo chmod +x run_script | |
CMD bash -c 'while true; do sleep 60; done;' | |
EOF | |
iidfile="$(mktemp)" | |
rm $iidfile | |
docker build --no-cache --iidfile="$iidfile" "$tmp" | |
image="$(cat "$iidfile")" | |
rm -f "$iidfile" | |
#rm -R "$tmp" | |
echo "Development environment image is:" | |
echo " $image" | |
cidfile="$(mktemp -u)" | |
docker create --cidfile="$cidfile" "$image" | |
container="$(cat "$cidfile")" | |
rm -f "$cidfile" | |
echo | |
echo "Development environment container is:" | |
echo " $container" | |
echo | |
echo "To start another shell in container run:" | |
echo | |
echo " docker exec -it $container bash -i" | |
echo | |
docker start "$container" | |
docker exec -it "$container" bash -i | |
echo | |
echo "To drop container run:" | |
echo | |
echo " docker container rm --force --volumes $container" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment