Skip to content

Commit

Permalink
Tweak Dockerfile and add workflow for building remotely
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnvanwezel committed Jun 16, 2024
1 parent 408177e commit 4f4ca91
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 110 deletions.
109 changes: 48 additions & 61 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,105 +1,92 @@
FROM debian:bookworm-slim as base
FROM debian:bookworm-slim

ENV LANG C.UTF-8

ARG GHC_VERSION=9.6.3
ARG GHC_VERSION=9.6.5
ARG STACK_VERSION=recommended
ARG STACK_RESOLVER=nightly
ARG CABAL_VERSION=recommended
ARG HLS_VERSION=recommended
ARG LLVM_VERSION=17

ENV USERNAME=vscode \
ENV LANG=C.UTF-8 \
USERNAME=devcontainer \
USER_UID=1000 \
USER_GID=1000 \
DEBIAN_FRONTEND=noninteractive \
BOOTSTRAP_HASKELL_NONINTERACTIVE=yes \
BOOTSTRAP_HASKELL_NO_UPGRADE=yes \
GHC_VERSION=${GHC_VERSION} \
STACK_VERSION=${STACK_VERSION} \
STACK_RESOLVER=${STACK_RESOLVER} \
CABAL_VERSION=${CABAL_VERSION} \
HLS_VERSION=${HLS_VERSION} \
LLVM_VERSION=${LLVM_VERSION}
HLS_VERSION=${HLS_VERSION}

RUN ulimit -n 8192

RUN VERSION_CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d'=' -f2) && \
apt-get update && \
apt-get install -y --no-install-recommends software-properties-common wget && \
# I don't know why, nor do I have any mental capacity to figure it out,
# but we need to add the repository twice, otherwise it doesn't work (repo isn't being added)
add-apt-repository -y -s -n "deb http://apt.llvm.org/${VERSION_CODENAME}/ llvm-toolchain-${VERSION_CODENAME}-${LLVM_VERSION} main" && \
add-apt-repository -y -s -n "deb http://apt.llvm.org/${VERSION_CODENAME}/ llvm-toolchain-${VERSION_CODENAME}-${LLVM_VERSION} main" && \
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc && \
apt-get update && \
apt-get install -y --no-install-recommends apt-utils bash build-essential ca-certificates curl gcc git gnupg libffi-dev libffi8 libgmp-dev libgmp-dev libgmp10 libicu-dev libncurses-dev libncurses5 libnuma1 libnuma-dev libtinfo5 lsb-release make procps sudo xz-utils z3 zlib1g-dev clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION

RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends software-properties-common wget && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
bash \
build-essential \
curl \
git \
libffi-dev \
libffi8 \
libgmp-dev \
libgmp10 \
libncurses-dev \
libncurses5 \
libtinfo5 \
sudo \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/*
RUN groupadd --gid ${USER_GID} ${USERNAME} && \
useradd -ms /bin/bash -K MAIL_DIR=/dev/null --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} && \
echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME}

USER ${USER_UID}:${USER_GID}
WORKDIR /home/${USERNAME}
ENV PATH="/home/${USERNAME}/.local/bin:/home/${USERNAME}/.cabal/bin:/home/${USERNAME}/.ghcup/bin:$PATH"

# Add GHCUp and Cabal to the PATH
ENV PATH="/home/${USERNAME}/.local/bin:/home/${USERNAME}/.cabal/bin:/home/${USERNAME}/.ghcup/bin:$PATH"
RUN echo "export PATH=${PATH}" >> /home/${USERNAME}/.profile

ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=yes \
BOOTSTRAP_HASKELL_NO_UPGRADE=yes

FROM base as tooling

# Download and install GHCUp
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

# Set the GHC version.
# Download and install GHC and tooling
RUN ghcup install ghc ${GHC_VERSION} --set

# Install cabal-iinstall
RUN ghcup install cabal ${CABAL_VERSION} --set
RUN ghcup install stack ${STACK_VERSION} --set
RUN ghcup install hls ${HLS_VERSION} --set

# Update Cabal.
# Configure Cabal
RUN cabal update && cabal new-install cabal-install

# Configure cabal
RUN cabal user-config update -f && \
sed -i 's/-- ghc-options:/ghc-options: -haddock/g' ~/.cabal/config

# Install stack
RUN ghcup install stack ${STACK_VERSION} --set

# Set system-ghc, install-ghc and resolver for stack.
# Configure Stack
RUN ((stack ghc -- --version 2>/dev/null) || true) && \
# Set global defaults for stack.
stack config --system-ghc set system-ghc true --global && \
stack config --system-ghc set install-ghc false --global && \
stack config --system-ghc set resolver ${STACK_RESOLVER}

# Set global custom defaults for stack.
RUN printf "ghc-options:\n \"\$everything\": -haddock\n" >> /home/${USERNAME}/.stack/config.yaml

# Install hls
RUN ghcup install hls ${HLS_VERSION} --set

FROM tooling as packages

# Install global packages.
# Versions are pinned, since we don't want to accidentally break anything (by always installing latest).
RUN cabal install --haddock-hoogle --minimize-conflict-set \
fsnotify-0.4.1.0 \
haskell-dap-0.0.16.0 \
ghci-dap-0.0.22.0 \
haskell-debug-adapter-0.0.39.0 \
hlint-3.6.1 \
apply-refact-0.14.0.0 \
retrie-1.2.2 \
hoogle-5.0.18.3 \
ormolu-0.7.2.0

FROM packages as hoogle

# Generate hoogle db
# Install useful dependencies
RUN cabal update && \
cabal install --haddock-hoogle --minimize-conflict-set \
fsnotify-0.4.1.0 \
haskell-dap-0.0.16.0 \
ghci-dap-0.0.22.0 \
haskell-debug-adapter-0.0.39.0 \
hlint-3.6.1 \
apply-refact-0.14.0.0 \
retrie-1.2.2 \
hoogle-5.0.18.3 \
ormolu-0.7.2.0

# Download local Hoogle database
RUN hoogle generate --download --haskell

ENV DEBIAN_FRONTEND=dialog

ENTRYPOINT ["/bin/bash"]
16 changes: 2 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
{
"name": "DevContainer for Haskell (GHC, Stack, Cabal, HIE, LSP, DAP, etc.)",
"remoteUser": "vscode",
"remoteUser": "devcontainer",
"runArgs": [],
"build": {
"args": {
"USERNAME": "vscode",
"GHC_VERSION": "9.6.3",
"STACK_VERSION": "recommended",
"STACK_RESOLVER": "nightly",
"CABAL_VERSION": "recommended",
"HLS_VERSION": "recommended",
"LLVM_VERSION": "17"
},
"context": "..",
"dockerfile": "Dockerfile"
},
"image": "ghcr.io/marijnvanwezel/haskell-dev-env",
"customizations": {
"vscode": {
"extensions": [
Expand Down
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build development container

on:
push:
paths:
- '.devcontainer/Dockerfile'

jobs:
build:
runs-on: ubuntu-22.04
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
include:
- context: ./.devcontainer
file: Dockerfile
image: ghcr.io/marijnvanwezel/haskell-dev-env

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ matrix.image }}

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20

- name: Build and push image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ${{ matrix.context }}
file: ${{ matrix.file }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
# https://github.com/moby/buildkit#github-actions-cache-experimental
cache-from: type=gha
cache-to: type=gha,mode=max
28 changes: 0 additions & 28 deletions .github/workflows/docker-image.yml

This file was deleted.

1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "0.2.0",
"configurations": [

{
"type": "ghc",
"request": "launch",
Expand Down

0 comments on commit 4f4ca91

Please sign in to comment.