Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate dockerfiles #69

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ tramp
.LSOverride

# Icon must end with two \r
Icon
Icon


# Thumbnails
._*
Expand Down Expand Up @@ -100,3 +101,5 @@ tmtags
Session.vim
.netrwhist
*~

dist-newstyle
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

with-compiler: ghc-8.10.7
42 changes: 42 additions & 0 deletions docker-haskell.cabal
Original file line number Diff line number Diff line change
@@ -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: [email protected]

-- 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,
stache >= 2.3.1 && < 2.4,
text >= 1.2.4 && < 1.3,
hs-source-dirs: gen
default-language: Haskell2010
24 changes: 24 additions & 0 deletions gen/Main.hs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions gen/Model/DebianDistribution.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Model.DebianDistribution where

data DebianDistribution =
DDBuster
6 changes: 6 additions & 0 deletions gen/Model/GHC/GhcInfo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Model.GhcInfo where

data GhcInfo = GhcInfo {
_ghcReleasers :: [GhcReleaser],
_ghcReleases :: [GhcRelease]
}
7 changes: 7 additions & 0 deletions gen/Model/GHC/GhcRelease.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Model.GHC.GhcReleaser where

data GhcRelease = GhcRelease {
_version :: Version,
_os :: OperatingSystem,
_osVersion :: OperatingSystemVersion,
}
6 changes: 6 additions & 0 deletions gen/Model/GHC/GhcReleaser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Model.GHC.GHCReleaser where

data GhcReleaser = GhcReleaser {
_name :: String,
_pgpKey :: PGPKey
}
3 changes: 3 additions & 0 deletions gen/Model/ImageVariant.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Model.ImageVariant where

newtype ImageVariant = ImageVariant String
6 changes: 6 additions & 0 deletions gen/Model/OperatingSystem.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Model.OperatingSystem where

data OperatingSystem =
OSDebian
| OSAlpine
| OSWindows
3 changes: 3 additions & 0 deletions gen/Model/PGPKey.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Model.ImageVariant where

newtype PGPKey = PGPKey String
5 changes: 5 additions & 0 deletions gen/Model/ProcessorArchitecture.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Model.ProcessorArchitecture where

data ProcessorArchitecture =
PAx86
| PAaarch64
167 changes: 167 additions & 0 deletions template/debian.jinja
Original file line number Diff line number Diff line change
@@ -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"]
77 changes: 77 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"ghc": {
"releasers": [
{
"name": "ben.gamari",
"pgpKey": "asdfasdf3423423432"
}
],
"releases": [
{
"version": "8.10.7",
"os": "debian",
"osVersion": "buster",
"sha256": "asdfasdfasdf124124",
"releasedBy": "ben.gamari"
}
]
},
"stack": {
"version": "2.7.5",
"pgpKey": "asdfsadfds234234",
"releases": [
{
"osType": "linux",
"arch": "amd64",
"sha256": "adsfasdf12123"
},
{
"osType": "windows",
"arch": "amd64",
"sha256": "adsfasdf12123"
}
]
},
"cabal": {
"version": "3.6.2.0",
"pgpKey": "asdfsadfds234234",
"releases": [
{
"os": "debian",
"osVersion": "buster",
"arch": "amd64",
"sha256": "adsfasdf12123"
}
]
},
"osVariants": [
{
"name": "debian",
"variants": [
"standard",
"slim"
],
"versions": [
"buster"
]
},
{
"name": "alpine",
"versions": [
"3.14",
"3.15"
]
},
{
"name": "windows",
"variants": [
"windowsservercore",
"nanoserver"
],
"versions": [
"1809",
"ltsc2022"
]
}
]
}