forked from aeroheim/audio-file-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
217 lines (175 loc) · 7.81 KB
/
Copy pathDockerfile
File metadata and controls
217 lines (175 loc) · 7.81 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
FROM ubuntu:24.04 AS stage_build
# Use latest Emscripten LTS version
ARG EMSCRIPTEN_VERSION=3.1.57
ENV EMSDK=/emsdk
# ------------------------------------------------------------------------------
RUN echo "## Start building" \
&& echo "## Update and install packages" \
&& apt-get -qq -y update \
&& apt-get -qq install -y --no-install-recommends \
binutils \
build-essential \
ca-certificates \
file \
git \
python3 \
python3-pip \
&& echo "## Done"
# Clone and install Emscripten SDK
RUN echo "## Clone and install Emscripten" \
&& git clone https://github.com/emscripten-core/emsdk.git ${EMSDK} \
&& cd ${EMSDK} \
&& ./emsdk install ${EMSCRIPTEN_VERSION} \
&& echo "## Done"
# This generates configuration that contains all valid paths according to installed SDK
# TODO(sbc): We should be able to use just emcc -v here but it doesn't
# currently create the sanity file.
RUN cd ${EMSDK} \
&& echo "## Generate standard configuration" \
&& ./emsdk activate ${EMSCRIPTEN_VERSION} \
&& chmod 777 ${EMSDK}/upstream/emscripten \
&& chmod -R 777 ${EMSDK}/upstream/emscripten/cache \
&& echo "int main() { return 0; }" > hello.c \
&& ${EMSDK}/upstream/emscripten/emcc -c hello.c \
&& cat ${EMSDK}/upstream/emscripten/cache/sanity.txt \
&& echo "## Done"
# Cleanup Emscripten installation and strip some symbols
RUN echo "## Aggressive optimization: Remove debug symbols" \
&& cd ${EMSDK} && . ./emsdk_env.sh \
# Remove debugging symbols from embedded node (extra 7MB)
&& strip -s `which node` \
# Tests consume ~80MB disc space
&& rm -fr ${EMSDK}/upstream/emscripten/tests \
# Fastcomp is not supported
&& rm -fr ${EMSDK}/upstream/fastcomp \
# strip out symbols from clang (~extra 50MB disc space)
&& find ${EMSDK}/upstream/bin -type f -exec strip -s {} + || true \
&& echo "## Done"
# ------------------------------------------------------------------------------
# -------------------------------- STAGE DEPLOY --------------------------------
# ------------------------------------------------------------------------------
FROM ubuntu:24.04 AS stage_deploy
COPY --from=stage_build /emsdk /emsdk
# Fallback in case Emscripten isn't activated.
# This will let use tools offered by this image inside other Docker images
# (sub-stages) or with custom / no entrypoint
ENV EMSDK=/emsdk \
EMSDK_NODE=/emsdk/node/14.18.2_64bit/bin/node \
PATH="/emsdk:/emsdk/upstream/emscripten:/emsdk/upstream/bin:/emsdk/node/14.18.2_64bit/bin:${PATH}"
# ------------------------------------------------------------------------------
# Create a 'standard` 1000:1000 user
# Thanks to that this image can be executed as non-root user and created files
# will not require root access level on host machine Please note that this
# solution even if widely spread (i.e. Node.js uses it) is far from perfect as
# user 1000:1000 might not exist on host machine, and in this case running any
# docker image will cause other random problems (mostly due `$HOME` pointing to
# `/`)
RUN echo "## Create emscripten user (1000:1000)" \
&& (groupadd --gid 1000 emscripten 2>/dev/null || true) \
&& (useradd --uid 1000 --gid 1000 --shell /bin/bash --create-home emscripten 2>/dev/null || usermod -d /home/emscripten -s /bin/bash $(getent passwd 1000 | cut -d: -f1)) \
&& echo "umask 0000" >> /etc/bash.bashrc \
&& echo ". /emsdk/emsdk_env.sh" >> /etc/bash.bashrc \
&& echo "## Done"
# ------------------------------------------------------------------------------
RUN echo "## Update and install packages" \
&& apt-get -qq -y update \
# Somewhere in here apt sets up tzdata which asks for your time zone and blocks
# waiting for the answer which you can't give as docker build doesn't read from
# the terninal. The env vars set here avoid the interactive prompt and set the TZ.
&& DEBIAN_FRONTEND="noninteractive" TZ="America/San_Francisco" apt-get -qq install -y --no-install-recommends \
sudo \
libxml2 \
ca-certificates \
python3 \
python3-pip \
python-is-python3 \
wget \
curl \
zip \
unzip \
git \
git-lfs \
ssh-client \
build-essential \
make \
ant \
libidn12 \
cmake \
openjdk-11-jre-headless \
autoconf \
automake \
pkg-config \
libtool \
nodejs \
npm \
# Standard Cleanup on Debian images
&& apt-get -y clean \
&& apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/cache/debconf/*-old \
&& rm -rf /usr/share/doc/* \
&& rm -rf /usr/share/man/?? \
&& rm -rf /usr/share/man/??_* \
&& echo "## Done"
# ------------------------------------------------------------------------------
# Use commonly used /src as working directory
WORKDIR /src
# ------------------------------------------------------------------------------
# ----------------------------- STAGE NPM DEPS ---------------------------------
# ------------------------------------------------------------------------------
FROM stage_deploy AS stage_npm_deps
# Copy package files
COPY package*.json ./
# Install npm dependencies
RUN npm ci
# ------------------------------------------------------------------------------
# --------------------------- STAGE FFMPEG SYNC --------------------------------
# ------------------------------------------------------------------------------
FROM stage_npm_deps AS stage_ffmpeg_sync
# Copy Makefile and source needed for syncing
COPY makefile ./
# Sync FFmpeg and dependencies
RUN npm run sync
# ------------------------------------------------------------------------------
# -------------------------- STAGE FFMPEG BUILD --------------------------------
# ------------------------------------------------------------------------------
FROM stage_ffmpeg_sync AS stage_ffmpeg_build
# Build FFmpeg and its dependencies
RUN npm run build-deps
# ------------------------------------------------------------------------------
# ---------------------------- STAGE WASM BUILD --------------------------------
# ------------------------------------------------------------------------------
FROM stage_ffmpeg_build AS stage_wasm_build
# Copy source files needed for WASM build
COPY src/module ./src/module
COPY src/lib/worker.js ./src/lib/worker.js
# Build WASM module
RUN npm run build-wasm
# ------------------------------------------------------------------------------
# ----------------------------- STAGE JS BUILD ---------------------------------
# ------------------------------------------------------------------------------
FROM stage_wasm_build AS stage_js_build
# Copy remaining source and config files
COPY src/lib ./src/lib
COPY tsconfig.types.json .eslintrc rollup.config.js ./
# Build JavaScript library
RUN npm run build
# ------------------------------------------------------------------------------
# ---------------------------- STAGE ARTIFACTS ---------------------------------
# ------------------------------------------------------------------------------
FROM scratch AS artifacts
# Copy built artifacts from previous stage
# Everything is now in dist/ including decode-audio.wasm
COPY --from=stage_js_build /src/dist ./dist
# ------------------------------------------------------------------------------
# ---------------------------- STAGE DEVELOPMENT -------------------------------
# ------------------------------------------------------------------------------
FROM stage_deploy AS development
# Install Node.js packages globally for development
RUN npm install -g nodemon
# Set user to emscripten for development
USER emscripten
# Default command opens a bash shell
CMD ["/bin/bash"]
# ------------------------------------------------------------------------------