Skip to content

Commit 9363458

Browse files
committed
WIP early sketching
1 parent 3fd71ef commit 9363458

9 files changed

+260
-1
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ tramp
5555
.LSOverride
5656

5757
# Icon must end with two \r
58-
Icon
58+
Icon
59+
5960

6061
# Thumbnails
6162
._*
@@ -100,3 +101,5 @@ tmtags
100101
Session.vim
101102
.netrwhist
102103
*~
104+
105+
dist-newstyle

cabal.project

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
packages: .
2+
3+
with-compiler: ghc-8.10.7

docker-haskell.cabal

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cabal-version: 2.4
2+
name: docker-haskell
3+
version: 0.1.0.0
4+
5+
-- A short (one-line) description of the package.
6+
-- synopsis:
7+
8+
-- A longer description of the package.
9+
-- description:
10+
11+
-- A URL where users can report bugs.
12+
-- bug-reports:
13+
14+
-- The license under which the package is released.
15+
license: MIT
16+
author: Alistair Burrowes
17+
maintainer: [email protected]
18+
19+
-- A copyright notice.
20+
-- copyright:
21+
-- category:
22+
extra-source-files:
23+
README.md
24+
25+
executable docker-haskell
26+
main-is: Main.hs
27+
28+
-- Modules included in this executable, other than Main.
29+
other-modules:
30+
Model.DebianDistribution,
31+
Model.OperatingSystem,
32+
Model.ProcessorArchitecture,
33+
Model.ImageVariant
34+
35+
-- LANGUAGE extensions used by modules in this package.
36+
default-extensions:
37+
LambdaCase
38+
build-depends: base ^>=4.14.3.0,
39+
ginger >= 0.10.4 && < 0.11,
40+
text >= 1.2.4 && < 1.3,
41+
hs-source-dirs: gen
42+
default-language: Haskell2010

gen/Main.hs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Main where
2+
3+
import System.IO
4+
import System.IO.Error
5+
import qualified Data.Text as Text
6+
import Text.Ginger
7+
8+
main :: IO ()
9+
main = do
10+
_ <- runGingerT (makeContextM scopeLookup (putStr . Text.unpack . htmlSource)) tpl
11+
pure ()
12+
13+
loadFile :: FilePath -> IO String
14+
loadFile fn = openFile fn ReadMode >>= hGetContents
15+
16+
loadFileMay :: FilePath -> IO (Maybe String)
17+
loadFileMay fn =
18+
tryIOError (loadFile fn) >>=
19+
\case
20+
Right contents ->
21+
return (Just contents)
22+
Left err -> do
23+
print err -- remove this line if you want to fail silently
24+
return Nothing

gen/Model/DebianDistribution.hs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Model.DebianDistribution where
2+
3+
data DebianDistribution =
4+
DDBuster

gen/Model/ImageVariant.hs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Model.ImageVariant where
2+
3+
data Variant =
4+
IVStandard
5+
| IVSlim

gen/Model/OperatingSystem.hs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Model.OperatingSystem where
2+
3+
data OperatingSystem =
4+
OSDebian
5+
| OSAlpine
6+
| OSWindows

gen/Model/ProcessorArchitecture.hs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Model.ProcessorArchitecture where
2+
3+
data ProcessorArchitecture =
4+
PAx86
5+
| PAaarch64

template/debian.jinja

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
## Dockerfile for a haskell environment
2+
{% if slim %}
3+
FROM debian:{{distribution}}
4+
{% else %}
5+
FROM buildpack-deps:{{distribution}}
6+
{% endif %}
7+
8+
{% if slim %}
9+
# common haskell + stack dependencies
10+
RUN apt-get update && \
11+
apt-get install -y --no-install-recommends \
12+
ca-certificates \
13+
curl \
14+
dpkg-dev \
15+
git \
16+
gcc \
17+
gnupg \
18+
g++ \
19+
libc6-dev \
20+
libffi-dev \
21+
libgmp-dev \
22+
libnuma-dev \
23+
libtinfo-dev \
24+
make \
25+
netbase \
26+
xz-utils \
27+
zlib1g-dev && \
28+
rm -rf /var/lib/apt/lists/*
29+
{% else %}
30+
RUN apt-get update && \
31+
apt-get install -y --no-install-recommends \
32+
gnupg \
33+
libc6-dev \
34+
libffi-dev \
35+
libgmp-dev \
36+
libnuma-dev \
37+
libtinfo-dev \
38+
make \
39+
netbase \
40+
xz-utils \
41+
zlib1g-dev && \
42+
rm -rf /var/lib/apt/lists/*
43+
{% endif %}
44+
45+
## ensure locale is set during build
46+
ENV LANG C.UTF-8
47+
48+
ARG STACK=2.7.5
49+
ARG STACK_RELEASE_KEY=C5705533DA4F78D8664B5DC0575159689BEFB442
50+
51+
RUN set -eux; \
52+
cd /tmp; \
53+
ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_CPU)"; \
54+
INSTALL_STACK="true"; \
55+
STACK_URL="https://github.com/commercialhaskell/stack/releases/download/v${STACK}/stack-${STACK}-linux-$ARCH.tar.gz"; \
56+
# sha256 from https://github.com/commercialhaskell/stack/releases/download/v${STACK}/stack-${STACK}-linux-$ARCH.tar.gz.sha256
57+
case "$ARCH" in \
58+
'aarch64') \
59+
# Stack does not officially support ARM64, nor do the binaries that exist work.
60+
# Hitting https://github.com/commercialhaskell/stack/issues/2103#issuecomment-972329065 when trying to use
61+
# stack-2.7.1-linux-aarch64.tar.gz
62+
INSTALL_STACK="false"; \
63+
;; \
64+
'x86_64') \
65+
STACK_SHA256='9bcd165358d4dcafd2b33320d4fe98ce72faaf62300cc9b0fb86a27eb670da50'; \
66+
;; \
67+
*) echo >&2 "error: unsupported architecture '$ARCH'" ; exit 1 ;; \
68+
esac; \
69+
if [ "$INSTALL_STACK" = "true" ]; then \
70+
curl -sSL "$STACK_URL" -o stack.tar.gz; \
71+
echo "$STACK_SHA256 stack.tar.gz" | sha256sum --strict --check; \
72+
\
73+
curl -sSL "$STACK_URL.asc" -o stack.tar.gz.asc; \
74+
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
75+
gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$STACK_RELEASE_KEY"; \
76+
gpg --batch --verify stack.tar.gz.asc stack.tar.gz; \
77+
gpgconf --kill all; \
78+
\
79+
tar -xf stack.tar.gz -C /usr/local/bin --strip-components=1 "stack-$STACK-linux-$ARCH/stack"; \
80+
stack config set system-ghc --global true; \
81+
stack config set install-ghc --global false; \
82+
\
83+
rm -rf /tmp/*; \
84+
\
85+
stack --version; \
86+
fi
87+
88+
ARG CABAL_INSTALL=3.6.2.0
89+
ARG CABAL_INSTALL_RELEASE_KEY=A970DF3AC3B9709706D74544B3D9F94B8DCAE210
90+
91+
RUN set -eux; \
92+
cd /tmp; \
93+
ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_CPU)"; \
94+
CABAL_INSTALL_TAR="cabal-install-$CABAL_INSTALL-$ARCH-linux-deb10.tar.xz"; \
95+
CABAL_INSTALL_URL="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/$CABAL_INSTALL_TAR"; \
96+
CABAL_INSTALL_SHA256SUMS_URL="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/SHA256SUMS"; \
97+
# sha256 from https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/SHA256SUMS
98+
case "$ARCH" in \
99+
'aarch64') \
100+
CABAL_INSTALL_SHA256='d9acee67d4308bc5c22d27bee034d388cc4192a25deff9e7e491e2396572b030'; \
101+
;; \
102+
'x86_64') \
103+
CABAL_INSTALL_SHA256='4759b56e9257e02f29fa374a6b25d6cb2f9d80c7e3a55d4f678a8e570925641c'; \
104+
;; \
105+
*) echo >&2 "error: unsupported architecture '$ARCH'"; exit 1 ;; \
106+
esac; \
107+
curl -fSL "$CABAL_INSTALL_URL" -o cabal-install.tar.gz; \
108+
echo "$CABAL_INSTALL_SHA256 cabal-install.tar.gz" | sha256sum --strict --check; \
109+
\
110+
curl -sSLO "$CABAL_INSTALL_SHA256SUMS_URL"; \
111+
curl -sSLO "$CABAL_INSTALL_SHA256SUMS_URL.sig"; \
112+
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
113+
gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$CABAL_INSTALL_RELEASE_KEY"; \
114+
gpg --batch --verify SHA256SUMS.sig SHA256SUMS; \
115+
# confirm we are verying SHA256SUMS that matches the release + sha256
116+
grep "$CABAL_INSTALL_SHA256 $CABAL_INSTALL_TAR" SHA256SUMS; \
117+
gpgconf --kill all; \
118+
\
119+
tar -xf cabal-install.tar.gz -C /usr/local/bin; \
120+
\
121+
rm -rf /tmp/*; \
122+
\
123+
cabal --version
124+
125+
ARG GHC={{ghcVersion}}
126+
ARG GHC_RELEASE_KEY=FFEB7CE81E16A36B3E2DED6F2DE04D4E97DB64AD
127+
128+
RUN set -eux; \
129+
cd /tmp; \
130+
ARCH="$(dpkg-architecture --query DEB_BUILD_GNU_CPU)"; \
131+
GHC_URL="https://downloads.haskell.org/~ghc/$GHC/ghc-$GHC-$ARCH-deb10-linux.tar.xz"; \
132+
# sha256 from https://downloads.haskell.org/~ghc/$GHC/SHA256SUMS
133+
case "$ARCH" in \
134+
'aarch64') \
135+
GHC_SHA256='f3621ccba7ae48fcd67a9505f61bb5ccfb05c4cbfecd5a6ea65fe3f150af0e98'; \
136+
;; \
137+
'x86_64') \
138+
GHC_SHA256='fb61dea556a2023dc2d50ee61a22144bb23e4229a378e533065124c218f40cfc'; \
139+
;; \
140+
*) echo >&2 "error: unsupported architecture '$ARCH'" ; exit 1 ;; \
141+
esac; \
142+
curl -sSL "$GHC_URL" -o ghc.tar.xz; \
143+
echo "$GHC_SHA256 ghc.tar.xz" | sha256sum --strict --check; \
144+
\
145+
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
146+
curl -sSL "$GHC_URL.sig" -o ghc.tar.xz.sig; \
147+
gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$GHC_RELEASE_KEY"; \
148+
gpg --batch --verify ghc.tar.xz.sig ghc.tar.xz; \
149+
gpgconf --kill all; \
150+
\
151+
tar xf ghc.tar.xz; \
152+
cd "ghc-$GHC"; \
153+
./configure --prefix "/opt/ghc/$GHC"; \
154+
make install; \
155+
# remove some docs
156+
{% if slim %}
157+
find "/opt/ghc/$GHC/" \( -name "*_p.a" -o -name "*.p_hi" \) -type f -delete; \
158+
{% endif %}
159+
rm -rf "/opt/ghc/$GHC/share/"; \
160+
\
161+
rm -rf /tmp/*; \
162+
\
163+
"/opt/ghc/$GHC/bin/ghc" --version
164+
165+
ENV PATH /root/.cabal/bin:/root/.local/bin:/opt/ghc/${GHC}/bin:$PATH
166+
167+
CMD ["ghci"]

0 commit comments

Comments
 (0)