-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
158 lines (125 loc) · 3.9 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# BUILD IMAGE
FROM ubuntu:18.04 AS builder
LABEL author="Oleg Grenrus <oleg.grenrus@iki.fi>"
WORKDIR /build
# Update APT
RUN apt-get -yq update && apt-get -yq upgrade
# hvr-ppa, provides GHC and cabal-install
RUN apt-get -yq --no-install-suggests --no-install-recommends install \
software-properties-common \
apt-utils \
&& apt-add-repository -y "ppa:hvr/ghc"
# Locales
# - UTF-8 is good
RUN apt-get -yq --no-install-suggests --no-install-recommends install \
locales
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
# Some what stable dependencies
# - separately, mostly to spot ghc and cabal-install
RUN apt-get -yq --no-install-suggests --no-install-recommends install \
cabal-install-2.4 \
ghc-8.4.4 \
ghc-8.6.5 \
git
# More dependencies, all the -dev libraries
# - some basic collection of often needed libs
# - also some dev tools
RUN apt-get -yq --no-install-suggests --no-install-recommends install \
build-essential \
ca-certificates \
curl \
git \
libgmp-dev \
liblapack-dev \
liblzma-dev \
libpq-dev \
libssl-dev \
libyaml-dev \
netbase \
openssh-client \
pkg-config \
zlib1g-dev
# Set up PATH
ENV PATH=/cabal/bin:/opt/ghc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# cabal-install configuration
# - we'll be in better control of the build environment, than with default config.
COPY docker.cabal.config /build/cabal.config
ENV CABAL_CONFIG /build/cabal.config
# Update cabal-install database
RUN cabal v2-update
# Install cabal-plan
# - we'll need it to find build artifacts
# - note: actual build tools ought to be specified in build-tool-depends field
RUN cabal v2-install cabal-plan --constraint='cabal-plan ^>=0.5' --constraint='cabal-plan +exe'
# Add a .cabal file to build environment
# - it's enough to build dependencies
COPY *.cabal cabal.project /build/
# Build package dependencies first
# - beware of https://github.com/haskell/cabal/issues/6106
RUN cabal v2-build -v1 --dependencies-only all
# Add rest of the files into build environment
# - remember to keep .dockerignore up to date
COPY . /build
# An executable to build
ARG EXECUTABLE
# Check that ARG is set up
RUN if [ -z "$EXECUTABLE" ]; then echo "ERROR: Empty $EXECUTABLE"; false; fi
# BUILD
RUN cabal v2-build -v1 exe:$EXECUTABLE
# Copy build artifact to known directory
# - todo arg
RUN mkdir -p /build/artifacts && cp $(cabal-plan list-bin $EXECUTABLE) /build/artifacts/
# Make a final binary a bit smaller
RUN strip /build/artifacts/$EXECUTABLE; done
# Small debug output
RUN ls -lh /build/artifacts
# DEPLOYMENT IMAGE
FROM ubuntu:18.04
LABEL author="Oleg Grenrus <oleg.grenrus@iki.fi>"
# Dependencies
# - no -dev stuff
# - cleanup apt stuff after installation
RUN apt-get -yq update && apt-get -yq --no-install-suggests --no-install-recommends install \
ca-certificates \
curl \
locales \
libgmp10 \
liblapack3 \
liblzma5 \
libpq5 \
libssl1.1 \
libyaml-0-2 \
msmtp \
netbase \
openssh-client \
zlib1g \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
# Config msmtp to use G Suite relay for email sending
RUN echo 'domain satakuntatalo.fi\n\
host smtp-relay.gmail.com\n\
port 587\n\
tls on\n\
tls_trust_file /etc/ssl/certs/ca-certificates.crt\n\
from noreply@satakuntatalo.fi' > /etc/msmtprc
# Create a symbolic link from msmtp to sendmail so there is no need for code changes
RUN ln -s /usr/bin/msmtp /usr/sbin/sendmail
WORKDIR /app
EXPOSE 8080
# Inherit the executable argument
ARG EXECUTABLE
# Copy build artifact from a builder stage
COPY --from=builder /build/artifacts/$EXECUTABLE /app/$EXECUTABLE
# ARG env isn't preserved, so we make another ENV
ENV EXECUTABLE_ $EXECUTABLE
RUN env
RUN ls /app
# Set up a default command to run
ENTRYPOINT /app/${EXECUTABLE_}