-
Notifications
You must be signed in to change notification settings - Fork 39
/
Dockerfile
146 lines (117 loc) · 4.67 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
FROM node:lts as frontend
# Frontend
ENV LC_ALL=C.UTF-8
RUN npm install --location=global vite
RUN mkdir -p /opt/arkham/src/frontend
WORKDIR /opt/arkham/src/frontend
COPY ./frontend/package.json ./frontend/tsconfig.json ./frontend/vite.config.js ./frontend/.eslintrc.cjs ./frontend/package-lock.json /opt/arkham/src/frontend/
RUN npm ci
COPY ./frontend /opt/arkham/src/frontend
ENV VITE_ASSET_HOST ${ASSET_HOST:-""}
RUN npm run build
FROM ubuntu:22.04 as base
ARG DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
ENV TZ=UTC
# install dependencies
RUN \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apt-get update -y && \
apt-get install -y --no-install-recommends --fix-missing \
libpq-dev \
curl \
libtinfo6 \
libnuma-dev \
zlib1g-dev \
libgmp-dev \
libgmp10 \
libtinfo-dev \
git \
wget \
lsb-release \
software-properties-common \
gnupg2 \
apt-transport-https \
gcc \
autoconf \
automake \
build-essential && \
rm -rf /var/lib/apt/lists/*
ARG TARGETARCH
# install ghcup
RUN \
if [ "$TARGETARCH" = "arm64" ]; then \
curl https://downloads.haskell.org/~ghcup/aarch64-linux-ghcup > /usr/bin/ghcup; \
else \
curl https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > /usr/bin/ghcup; \
fi;
# Don't combine
RUN chmod +x /usr/bin/ghcup && \
ghcup config set gpg-setting GPGNone
ARG GHC=9.8.2
ARG CABAL=3.10.3.0
ARG STACK=3.1.1
ARG CACHE_ID="${TARGETARCH}-${GHC}-${CABAL}-${STACK}"
ENV CACHE_ID=${CACHE_ID}
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
# install GHC and cabal
RUN \
ghcup -v install ghc --isolate /usr/local --force ${GHC} && \
ghcup -v install cabal --isolate /usr/local/bin --force ${CABAL} && \
ghcup -v install stack --isolate /usr/local/bin --force ${STACK}
FROM base as dependencies
RUN mkdir -p \
/opt/arkham/bin \
/opt/arkham/src/backend/arkham-api \
/opt/arkham/src/backend/validate \
/opt/arkham/src/backend/cards-discover
WORKDIR /opt/arkham/src/backend
COPY ./backend/stack.yaml /opt/arkham/src/backend/stack.yaml
COPY ./backend/arkham-api/package.yaml /opt/arkham/src/backend/arkham-api/package.yaml
COPY ./backend/validate/package.yaml /opt/arkham/src/backend/validate/package.yaml
COPY ./backend/cards-discover/package.yaml /opt/arkham/src/backend/cards-discover/package.yaml
RUN stack build --system-ghc --dependencies-only --no-terminal --ghc-options '-j4 +RTS -A128m -n2m -RTS'
FROM dependencies as api
RUN mkdir -p \
/opt/arkham/src/backend \
/opt/arkham/bin
COPY ./backend /opt/arkham/src/backend
WORKDIR /opt/arkham/src/backend/cards-discover
RUN --mount=type=cache,id=stack-discover-${CACHE_ID},target=/opt/arkham/src/backend/cards-discover/.stack-work \
stack build --system-ghc --no-terminal --ghc-options '-j4 +RTS -A128m -n2m -RTS' cards-discover
WORKDIR /opt/arkham/src/backend/arkham-api
RUN --mount=type=cache,id=stack-root-${CACHE_ID},target=/opt/arkham/src/backend/.stack-work \
--mount=type=cache,id=stack-api-${CACHE_ID},target=/opt/arkham/src/backend/arkham-api/.stack-work \
--mount=type=cache,id=stack-api-hie-${CACHE_ID},target=/opt/arkham/src/backend/arkham-api/.hie \
--mount=type=cache,id=stack-validate-hie-${CACHE_ID},target=/opt/arkham/src/backend/arkham-validate/.hie \
--mount=type=cache,id=stack-discover-hie-${CACHE_ID},target=/opt/arkham/src/backend/cards-discover/.hie \
stack build --no-terminal --system-ghc --ghc-options '-j4 +RTS -A128m -n2m -RTS' && \
stack --no-terminal --local-bin-path /opt/arkham/bin install
FROM ubuntu:22.04 as app
# App
ENV LC_ALL=C.UTF-8
RUN apt-get update && \
apt-get upgrade -y --assume-yes && \
apt-get install -y --assume-yes libpq-dev ca-certificates nginx curl && \
rm -rf /var/lib/apt/lists/*
RUN mkdir -p \
/opt/arkham/bin \
/opt/arkham/src/backend/arkham-api \
/opt/arkham/src/frontend \
/var/log/nginx \
/var/lib/nginx \
/run
COPY --from=frontend /opt/arkham/src/frontend/dist /opt/arkham/src/frontend/dist
COPY --from=api /opt/arkham/bin/arkham-api /opt/arkham/bin/arkham-api
COPY ./backend/arkham-api/config /opt/arkham/src/backend/arkham-api/config
COPY ./prod.nginxconf /opt/arkham/src/backend/prod.nginxconf
COPY ./start.sh /opt/arkham/src/backend/arkham-api/start.sh
COPY ./backend/arkham-api/digital-ocean.crt /opt/arkham/src/backend/arkham-api/digital-ocean.crt
RUN useradd -ms /bin/bash yesod && \
chown -R yesod:yesod /opt/arkham /var/log/nginx /var/lib/nginx /run && \
chmod a+x /opt/arkham/src/backend/arkham-api/start.sh
USER yesod
ENV PATH "$PATH:/opt/stack/bin:/opt/arkham/bin"
EXPOSE 3000
WORKDIR /opt/arkham/src/backend/arkham-api
CMD ["./start.sh"]