forked from fmidue/codeworld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.prod
177 lines (113 loc) · 6.9 KB
/
Dockerfile.prod
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
FROM ubuntu:20.04 as base
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y python3 build-essential curl libffi-dev libffi7 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5 sudo pkg-config git wget bzip2 xz-utils psmisc zlib1g-dev make gcc g++ gnupg patch autoconf automake libtinfo-dev libssl-dev ca-certificates
RUN curl -sSf https://downloads.haskell.org/~ghcup/$(uname -m)-$(uname -s | awk '{print tolower($0)}')-ghcup > /usr/bin/ghcup && chmod +x /usr/bin/ghcup
RUN useradd -ms /bin/bash -d /opt/codeworld codeworld
RUN echo "codeworld ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers
ENV CODEWORLD_DIR /opt/codeworld
WORKDIR $CODEWORLD_DIR
RUN chown codeworld:codeworld .
USER codeworld
ENV CABAL_DIR $CODEWORLD_DIR/.cabal
WORKDIR $CODEWORLD_DIR
RUN ghcup upgrade
RUN ghcup install 8.6.5
RUN ghcup set 8.6.5
RUN ghcup install-cabal 2.4.1.0
ENV PATH $CODEWORLD_DIR/.ghcup/bin:$PATH
RUN cabal update --index-state='2023-02-09T01:33:22Z'
RUN cabal v2-install alex
RUN cabal v2-install happy-1.19.9 --overwrite-policy=always
ENV PATH $CODEWORLD_DIR/.cabal/bin:$PATH
RUN sudo mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
RUN sudo apt-get update && sudo apt-get install nodejs -y
FROM base as builder
WORKDIR $CODEWORLD_DIR
###############################################
### Install GHCJS ###
###############################################
RUN git clone --recurse-submodules --branch ghc-8.6 --single-branch https://github.com/ghcjs/ghcjs.git build/ghcjs
COPY --chown=codeworld ghc-artifacts/ ghc-artifacts/
WORKDIR $CODEWORLD_DIR/build/ghcjs
RUN git submodule update --init
RUN patch -p0 -u -d $CODEWORLD_DIR/build < $CODEWORLD_DIR/ghc-artifacts/ghcjs-8.6-default-main.patch
RUN patch -p0 -u -d $CODEWORLD_DIR/build < $CODEWORLD_DIR/ghc-artifacts/ghcjs-8.6-dedup-fix.patch
RUN ./utils/boot || true
RUN cabal v2-install . --symlink-bindir=$CODEWORLD_DIR/build/bin -j1 --disable-documentation --overwrite-policy=always
RUN ls $CODEWORLD_DIR/.cabal/store/ghc-8.6.5/ | grep ghcjs-8.6.0.1 | xargs -i sudo cp --remove-destination $CODEWORLD_DIR/.cabal/store/ghc-8.6.5/{}/libexec/ghcjs-boot $CODEWORLD_DIR/build/bin/ghcjs-boot
RUN ls $CODEWORLD_DIR/.cabal/store/ghc-8.6.5/ | grep ghcjs-8.6.0.1 | xargs -i sudo cp --remove-destination $CODEWORLD_DIR/.cabal/store/ghc-8.6.5/{}/libexec/ghcjs-run $CODEWORLD_DIR/build/bin/ghcjs-run
RUN ls $CODEWORLD_DIR/.cabal/store/ghc-8.6.5/ | grep ghcjs-8.6.0.1 | xargs -i sudo cp --remove-destination $CODEWORLD_DIR/.cabal/store/ghc-8.6.5/{}/libexec/ghcjs-dumparchive $CODEWORLD_DIR/build/bin/ghcjs-dumparchive
WORKDIR $CODEWORLD_DIR/build/ghcjs
ENV PATH $CODEWORLD_DIR/build/bin:$PATH
RUN ghcjs-boot -j1 --no-prof --no-haddock -s lib/boot/
###############################################
### Install CodeMirror ###
###############################################
WORKDIR $CODEWORLD_DIR/build
RUN git clone https://github.com/codemirror/CodeMirror.git
WORKDIR $CODEWORLD_DIR/build/CodeMirror
RUN git checkout dde0e5cb51b243c61de9c43405b60c69a86dfb24
RUN npm install
RUN npm install -s uglify-js https://github.com/angelozerr/CodeMirror-Extension
###############################################
### Install third party modules ###
###############################################
WORKDIR $CODEWORLD_DIR
COPY --chown=codeworld third_party/ third_party/
RUN git init
RUN git submodule init
RUN git submodule update
###############################################
### Build codeworld ###
###############################################
COPY --chown=codeworld mirror/ mirror/
COPY --chown=codeworld base.sh ./
RUN $CODEWORLD_DIR/mirror/get_mirrored
COPY --chown=codeworld codeworld-prediction/ codeworld-prediction/
COPY --chown=codeworld codeworld-error-sanitizer/ codeworld-error-sanitizer/
COPY --chown=codeworld codeworld-api/ codeworld-api/
COPY --chown=codeworld codeworld-base/ codeworld-base/
COPY --chown=codeworld codeworld-game-api/ codeworld-game-api/
COPY --chown=codeworld codeworld-available-pkgs/ codeworld-available-pkgs/
RUN bash -c "source base.sh && cabal_install --ghcjs ./codeworld-prediction ./codeworld-error-sanitizer ./codeworld-api ./codeworld-base ./codeworld-game-api ./codeworld-available-pkgs"
RUN ghcjs-pkg hide base-compat
RUN ghcjs-pkg hide ghcjs-dom-jsffi
RUN ghcjs-pkg hide matrices
RUN ghcjs-pkg hide simple-affine-space
RUN ghcjs-pkg hide newtype
RUN ghcjs-pkg hide non-empty
RUN ghcjs-pkg hide hgeometry-combinatorial
RUN ghcjs-pkg hide Cabal
RUN ghcjs-pkg hide cabal-doctest
RUN ghcjs-pkg hide some
RUN node $CODEWORLD_DIR/build/bin/find-dup-modules.jsexe/all.js $CODEWORLD_DIR/.ghcjs/x86_64-linux-8.6.0.1-8.6.5/ghcjs/package.conf.d/package.cache
WORKDIR $CODEWORLD_DIR/codeworld-base
RUN cabal configure --ghcjs
RUN cabal haddock --html
RUN cabal haddock --hoogle
WORKDIR $CODEWORLD_DIR/codeworld-api
RUN cabal configure --ghcjs
RUN cabal haddock --html
RUN cabal haddock --hoogle
WORKDIR $CODEWORLD_DIR
COPY --chown=codeworld codeworld-server/ codeworld-server/
COPY --chown=codeworld codeworld-compiler/ codeworld-compiler/
COPY --chown=codeworld codeworld-requirements/ codeworld-requirements/
COPY --chown=codeworld codeworld-game-server/ codeworld-game-server/
COPY --chown=codeworld codeworld-account/ codeworld-account/
COPY --chown=codeworld codeworld-auth/ codeworld-auth/
RUN bash -c "source base.sh && cabal_install ./codeworld-server ./codeworld-error-sanitizer ./codeworld-compiler ./codeworld-requirements ./codeworld-game-api ./codeworld-prediction ./codeworld-api ./codeworld-game-server ./codeworld-account ./codeworld-auth"
WORKDIR $CODEWORLD_DIR/build/CodeMirror
RUN node_modules/uglify-js/bin/uglifyjs lib/codemirror.js addon/dialog/dialog.js addon/display/placeholder.js addon/display/rulers.js addon/edit/matchbrackets.js addon/hint/show-hint.js addon/lint/lint.js addon/runmode/runmode.js addon/scroll/annotatescrollbar.js addon/search/match-highlighter.js addon/search/matchesonscrollbar.js addon/search/search.js addon/search/searchcursor.js addon/selection/active-line.js mode/haskell/haskell.js node_modules/codemirror-extension/addon/hover/text-hover.js -c -m > codemirror-compressed.js
###############################################
### Fix web directory ###
###############################################
WORKDIR $CODEWORLD_DIR
COPY --chown=codeworld web/ web/
COPY --chown=codeworld run.sh fix-web.sh ./
RUN ./fix-web.sh
RUN tar -cf codeworld.keter .cabal/store/ghc-8.6.5/ .ghcjs/ base.sh build/bin/codeworld-server build/bin/ghcjs build/lib/x86_64-linux-ghcjs-8.6.0.1-ghc8_6_5 codeworld-base/dist/doc/html/codeworld-base/codeworld-base.txt run.sh web/
CMD ./run.sh