Skip to content

Commit 19030a0

Browse files
committed
Let us template the Dockerfiles
1 parent aa517c2 commit 19030a0

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

8.8/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Dockerfile for a haskell environment
2-
FROM debian:stretch
2+
FROM buildpack-deps:stretch
33

44
## ensure locale is set during build
55
ENV LANG C.UTF-8

Dockerfile.template

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Dockerfile for a haskell environment
2+
FROM buildpack-deps:{{{distribution}}}
3+
4+
## ensure locale is set during build
5+
ENV LANG C.UTF-8
6+
7+
RUN apt-get update && \
8+
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git && \
9+
echo 'deb http://downloads.haskell.org/debian stretch main' > /etc/apt/sources.list.d/ghc.list && \
10+
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA3CBA3FFE22B574 && \
11+
apt-get update && \
12+
apt-get install -y --no-install-recommends ghc-{{ghcVersion}} cabal-install-3.0 \
13+
zlib1g-dev libtinfo-dev libsqlite3-dev g++ netbase xz-utils make openssh-client && \
14+
curl -fSL https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz -o stack.tar.gz && \
15+
curl -fSL https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64.tar.gz.asc -o stack.tar.gz.asc && \
16+
export GNUPGHOME="$(mktemp -d)" && \
17+
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys C5705533DA4F78D8664B5DC0575159689BEFB442 && \
18+
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 2C6A674E85EE3FB896AFC9B965101FF31C5C154D && \
19+
gpg --batch --trusted-key 0x575159689BEFB442 --verify stack.tar.gz.asc stack.tar.gz && \
20+
tar -xf stack.tar.gz -C /usr/local/bin --strip-components=1 && \
21+
/usr/local/bin/stack config set system-ghc --global true && \
22+
/usr/local/bin/stack config set install-ghc --global false && \
23+
rm -rf "$GNUPGHOME" /var/lib/apt/lists/* /stack.tar.gz.asc /stack.tar.gz
24+
25+
ENV PATH /root/.cabal/bin:/root/.local/bin:/opt/cabal/3.0/bin:/opt/ghc/8.8.1/bin:$PATH
26+
27+
## run ghci by default unless a command is specified
28+
CMD ["ghci"]

generate.hs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
2+
-- | Script to generate dockerfiles. Obviously using Haskell.
3+
--
4+
-- If you have @cabal-env@ installed, do:
5+
--
6+
-- cabal-env microstache
7+
--
8+
module Main (main) where
9+
10+
import Control.Monad (forM_)
11+
import Data.Aeson
12+
import Text.Microstache (compileMustacheFile, renderMustache)
13+
14+
import qualified Data.Text.Lazy.IO as LT
15+
16+
17+
params :: [(FilePath, Params)]
18+
params =
19+
[ mk "8.8/Dockerfile" Stretch "8.8.1"
20+
]
21+
where
22+
mk fp dist gv = (fp, Params dist gv)
23+
24+
main :: IO ()
25+
main = do
26+
template <- compileMustacheFile "Dockerfile.template"
27+
forM_ params $ \(fp, p) -> do
28+
let contents = renderMustache template (toJSON p)
29+
LT.writeFile fp contents
30+
31+
-------------------------------------------------------------------------------
32+
-- Data types
33+
-------------------------------------------------------------------------------
34+
35+
data Distribution = Stretch
36+
deriving (Show)
37+
38+
instance ToJSON Distribution where
39+
toJSON Stretch = "stretch"
40+
41+
data Params = Params
42+
{ pDistribution :: Distribution
43+
, pGhcVersion :: String
44+
}
45+
deriving (Show)
46+
47+
instance ToJSON Params where
48+
toJSON Params {..} = object
49+
[ "distribution" .= pDistribution
50+
, "ghcVersion" .= pGhcVersion
51+
]

0 commit comments

Comments
 (0)