diff --git a/.gitignore b/.gitignore index caf38ad..a037578 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,8 @@ tramp .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -100,3 +101,5 @@ tmtags Session.vim .netrwhist *~ + +dist-newstyle diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..1b85eff --- /dev/null +++ b/cabal.project @@ -0,0 +1,3 @@ +packages: . + +with-compiler: ghc-8.10.7 diff --git a/docker-haskell.cabal b/docker-haskell.cabal new file mode 100644 index 0000000..e7dcd72 --- /dev/null +++ b/docker-haskell.cabal @@ -0,0 +1,42 @@ +cabal-version: 2.4 +name: docker-haskell +version: 0.1.0.0 + +-- A short (one-line) description of the package. +-- synopsis: + +-- A longer description of the package. +-- description: + +-- A URL where users can report bugs. +-- bug-reports: + +-- The license under which the package is released. +license: MIT +author: Alistair Burrowes +maintainer: afburrowes@gmail.com + +-- A copyright notice. +-- copyright: +-- category: +extra-source-files: + README.md + +executable docker-haskell + main-is: Main.hs + + -- Modules included in this executable, other than Main. + other-modules: + Model.DebianDistribution, + Model.OperatingSystem, + Model.ProcessorArchitecture, + Model.ImageVariant + + -- LANGUAGE extensions used by modules in this package. + default-extensions: + LambdaCase + build-depends: base ^>=4.14.3.0, + ginger >= 0.10.4 && < 0.11, + text >= 1.2.4 && < 1.3, + hs-source-dirs: gen + default-language: Haskell2010 diff --git a/gen/Main.hs b/gen/Main.hs new file mode 100644 index 0000000..87abcff --- /dev/null +++ b/gen/Main.hs @@ -0,0 +1,24 @@ +module Main where + +import System.IO +import System.IO.Error +import qualified Data.Text as Text +import Text.Ginger + +main :: IO () +main = do + _ <- runGingerT (makeContextM scopeLookup (putStr . Text.unpack . htmlSource)) tpl + pure () + +loadFile :: FilePath -> IO String +loadFile fn = openFile fn ReadMode >>= hGetContents + +loadFileMay :: FilePath -> IO (Maybe String) +loadFileMay fn = + tryIOError (loadFile fn) >>= + \case + Right contents -> + return (Just contents) + Left err -> do + print err -- remove this line if you want to fail silently + return Nothing diff --git a/gen/Model/DebianDistribution.hs b/gen/Model/DebianDistribution.hs new file mode 100644 index 0000000..0c5b786 --- /dev/null +++ b/gen/Model/DebianDistribution.hs @@ -0,0 +1,4 @@ +module Model.DebianDistribution where + +data DebianDistribution = + DDBuster diff --git a/gen/Model/ImageVariant.hs b/gen/Model/ImageVariant.hs new file mode 100644 index 0000000..c8a079b --- /dev/null +++ b/gen/Model/ImageVariant.hs @@ -0,0 +1,5 @@ +module Model.ImageVariant where + +data Variant = + IVStandard + | IVSlim diff --git a/gen/Model/OperatingSystem.hs b/gen/Model/OperatingSystem.hs new file mode 100644 index 0000000..6f8dcf9 --- /dev/null +++ b/gen/Model/OperatingSystem.hs @@ -0,0 +1,6 @@ +module Model.OperatingSystem where + +data OperatingSystem = + OSDebian + | OSAlpine + | OSWindows diff --git a/gen/Model/ProcessorArchitecture.hs b/gen/Model/ProcessorArchitecture.hs new file mode 100644 index 0000000..65e38d7 --- /dev/null +++ b/gen/Model/ProcessorArchitecture.hs @@ -0,0 +1,5 @@ +module Model.ProcessorArchitecture where + +data ProcessorArchitecture = + PAx86 + | PAaarch64 diff --git a/template/debian.jinja b/template/debian.jinja new file mode 100644 index 0000000..058d2a6 --- /dev/null +++ b/template/debian.jinja @@ -0,0 +1,167 @@ +## Dockerfile for a haskell environment +{% if slim %} +FROM debian:{{distribution}} +{% else %} +FROM buildpack-deps:{{distribution}} +{% endif %} + +{% if slim %} +# common haskell + stack dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + dpkg-dev \ + git \ + gcc \ + gnupg \ + g++ \ + libc6-dev \ + libffi-dev \ + libgmp-dev \ + libnuma-dev \ + libtinfo-dev \ + make \ + netbase \ + xz-utils \ + zlib1g-dev && \ + rm -rf /var/lib/apt/lists/* +{% else %} +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gnupg \ + libc6-dev \ + libffi-dev \ + libgmp-dev \ + libnuma-dev \ + libtinfo-dev \ + make \ + netbase \ + xz-utils \ + zlib1g-dev && \ + rm -rf /var/lib/apt/lists/* +{% endif %} + +## ensure locale is set during build +ENV LANG C.UTF-8 + +ARG STACK=2.7.5 +ARG STACK_RELEASE_KEY=C5705533DA4F78D8664B5DC0575159689BEFB442 + +RUN set -eux; \ + cd /tmp; \ + ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_CPU)"; \ + INSTALL_STACK="true"; \ + STACK_URL="https://github.com/commercialhaskell/stack/releases/download/v${STACK}/stack-${STACK}-linux-$ARCH.tar.gz"; \ + # sha256 from https://github.com/commercialhaskell/stack/releases/download/v${STACK}/stack-${STACK}-linux-$ARCH.tar.gz.sha256 + case "$ARCH" in \ + 'aarch64') \ + # Stack does not officially support ARM64, nor do the binaries that exist work. + # Hitting https://github.com/commercialhaskell/stack/issues/2103#issuecomment-972329065 when trying to use + # stack-2.7.1-linux-aarch64.tar.gz + INSTALL_STACK="false"; \ + ;; \ + 'x86_64') \ + STACK_SHA256='9bcd165358d4dcafd2b33320d4fe98ce72faaf62300cc9b0fb86a27eb670da50'; \ + ;; \ + *) echo >&2 "error: unsupported architecture '$ARCH'" ; exit 1 ;; \ + esac; \ + if [ "$INSTALL_STACK" = "true" ]; then \ + curl -sSL "$STACK_URL" -o stack.tar.gz; \ + echo "$STACK_SHA256 stack.tar.gz" | sha256sum --strict --check; \ + \ + curl -sSL "$STACK_URL.asc" -o stack.tar.gz.asc; \ + GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ + gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$STACK_RELEASE_KEY"; \ + gpg --batch --verify stack.tar.gz.asc stack.tar.gz; \ + gpgconf --kill all; \ + \ + tar -xf stack.tar.gz -C /usr/local/bin --strip-components=1 "stack-$STACK-linux-$ARCH/stack"; \ + stack config set system-ghc --global true; \ + stack config set install-ghc --global false; \ + \ + rm -rf /tmp/*; \ + \ + stack --version; \ + fi + +ARG CABAL_INSTALL=3.6.2.0 +ARG CABAL_INSTALL_RELEASE_KEY=A970DF3AC3B9709706D74544B3D9F94B8DCAE210 + +RUN set -eux; \ + cd /tmp; \ + ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_CPU)"; \ + CABAL_INSTALL_TAR="cabal-install-$CABAL_INSTALL-$ARCH-linux-deb10.tar.xz"; \ + CABAL_INSTALL_URL="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/$CABAL_INSTALL_TAR"; \ + CABAL_INSTALL_SHA256SUMS_URL="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/SHA256SUMS"; \ + # sha256 from https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/SHA256SUMS + case "$ARCH" in \ + 'aarch64') \ + CABAL_INSTALL_SHA256='d9acee67d4308bc5c22d27bee034d388cc4192a25deff9e7e491e2396572b030'; \ + ;; \ + 'x86_64') \ + CABAL_INSTALL_SHA256='4759b56e9257e02f29fa374a6b25d6cb2f9d80c7e3a55d4f678a8e570925641c'; \ + ;; \ + *) echo >&2 "error: unsupported architecture '$ARCH'"; exit 1 ;; \ + esac; \ + curl -fSL "$CABAL_INSTALL_URL" -o cabal-install.tar.gz; \ + echo "$CABAL_INSTALL_SHA256 cabal-install.tar.gz" | sha256sum --strict --check; \ + \ + curl -sSLO "$CABAL_INSTALL_SHA256SUMS_URL"; \ + curl -sSLO "$CABAL_INSTALL_SHA256SUMS_URL.sig"; \ + GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ + gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$CABAL_INSTALL_RELEASE_KEY"; \ + gpg --batch --verify SHA256SUMS.sig SHA256SUMS; \ + # confirm we are verying SHA256SUMS that matches the release + sha256 + grep "$CABAL_INSTALL_SHA256 $CABAL_INSTALL_TAR" SHA256SUMS; \ + gpgconf --kill all; \ + \ + tar -xf cabal-install.tar.gz -C /usr/local/bin; \ + \ + rm -rf /tmp/*; \ + \ + cabal --version + +ARG GHC={{ghcVersion}} +ARG GHC_RELEASE_KEY=FFEB7CE81E16A36B3E2DED6F2DE04D4E97DB64AD + +RUN set -eux; \ + cd /tmp; \ + ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_CPU)"; \ + GHC_URL="https://downloads.haskell.org/~ghc/$GHC/ghc-$GHC-$ARCH-deb10-linux.tar.xz"; \ + # sha256 from https://downloads.haskell.org/~ghc/$GHC/SHA256SUMS + case "$ARCH" in \ + 'aarch64') \ + GHC_SHA256='f3621ccba7ae48fcd67a9505f61bb5ccfb05c4cbfecd5a6ea65fe3f150af0e98'; \ + ;; \ + 'x86_64') \ + GHC_SHA256='fb61dea556a2023dc2d50ee61a22144bb23e4229a378e533065124c218f40cfc'; \ + ;; \ + *) echo >&2 "error: unsupported architecture '$ARCH'" ; exit 1 ;; \ + esac; \ + curl -sSL "$GHC_URL" -o ghc.tar.xz; \ + echo "$GHC_SHA256 ghc.tar.xz" | sha256sum --strict --check; \ + \ + GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ + curl -sSL "$GHC_URL.sig" -o ghc.tar.xz.sig; \ + gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$GHC_RELEASE_KEY"; \ + gpg --batch --verify ghc.tar.xz.sig ghc.tar.xz; \ + gpgconf --kill all; \ + \ + tar xf ghc.tar.xz; \ + cd "ghc-$GHC"; \ + ./configure --prefix "/opt/ghc/$GHC"; \ + make install; \ + # remove some docs +{% if slim %} + find "/opt/ghc/$GHC/" \( -name "*_p.a" -o -name "*.p_hi" \) -type f -delete; \ +{% endif %} + rm -rf "/opt/ghc/$GHC/share/"; \ + \ + rm -rf /tmp/*; \ + \ + "/opt/ghc/$GHC/bin/ghc" --version + +ENV PATH /root/.cabal/bin:/root/.local/bin:/opt/ghc/${GHC}/bin:$PATH + +CMD ["ghci"]