@@ -8,9 +8,9 @@ ARG RUNNER_IMAGE="ubuntu:${DISTRO}"
88ARG DEBIAN_FRONTEND=noninteractive
99
1010# ##
11- # ## First Stage - Fetch deps for building web assets
11+ # ## Fetch deps for building web assets
1212# ##
13- FROM ${BUILDER_IMAGE} as deps
13+ FROM ${BUILDER_IMAGE} AS deps
1414
1515ENV MIX_ENV=prod
1616
@@ -24,9 +24,9 @@ RUN mix deps.get --only $MIX_ENV
2424
2525
2626# ##
27- # ## Second Stage - Build web assets
27+ # ## Build web assets
2828# ##
29- FROM node:${NODE_VERSION} as assets
29+ FROM node:${NODE_VERSION} AS assets
3030
3131RUN mkdir -p /priv/static
3232
@@ -42,13 +42,14 @@ RUN npm ci && npm cache clean --force && npm run deploy
4242
4343
4444# ##
45- # ## Third Stage - Building the Release
45+ # ## Build the NervesHub release
4646# ##
47- FROM ${BUILDER_IMAGE} as build
47+ FROM ${BUILDER_IMAGE} AS build
4848
4949# install dependencies
50- RUN apt-get update -y && apt-get install -y build-essential git ca-certificates curl gnupg \
51- && apt-get clean && rm -f /var/lib/apt/lists/*_*
50+ RUN apt-get update -y && apt-get install -y build-essential git ca-certificates curl gnupg && \
51+ apt-get clean && \
52+ rm -f /var/lib/apt/lists/*_*
5253
5354WORKDIR /build
5455
@@ -95,25 +96,83 @@ COPY rel rel
9596RUN mix release
9697
9798
99+ # ##
100+ # ## Build a static FWUP
101+ # ##
102+
103+ FROM ${RUNNER_IMAGE} AS fwup
104+
105+ RUN apt-get update -y && \
106+ apt-get upgrade -y && \
107+ apt-get install -y git curl build-essential autoconf pkg-config libtool mtools unzip zip help2man libconfuse-dev libarchive-dev xdelta3 dosfstools
108+
109+ RUN git clone https://github.com/fwup-home/fwup /tmp/fwup
110+
111+ WORKDIR /tmp/fwup
112+
113+ RUN git checkout v1.13.2 && \
114+ ./scripts/download_deps.sh && \
115+ ./scripts/build_deps.sh && \
116+ ./autogen.sh && \
117+ PKG_CONFIG_PATH=$PWD/build/host/deps/usr/lib/pkgconfig ./configure --enable-shared=no && \
118+ make && \
119+ make check && \
120+ make install
121+
122+
123+ # ##
124+ # ## Build jemalloc - GCC 14
125+ # ##
126+
127+ FROM ${RUNNER_IMAGE} AS jemalloc
128+
129+ RUN apt-get update -y && \
130+ apt-get upgrade -y && \
131+ apt-get install -y git autoconf cmake make software-properties-common && \
132+ add-apt-repository ppa:ubuntu-toolchain-r/ppa -y && \
133+ apt-get update -y && \
134+ apt-get install -y gcc-14 g++-14 && \
135+ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 --slave /usr/bin/g++ g++ /usr/bin/g++-14
136+
137+ # Build the latest jemalloc
138+
139+ RUN git clone https://github.com/facebook/jemalloc /tmp/jemalloc
140+
141+ WORKDIR /tmp/jemalloc
142+
143+ RUN autoconf && \
144+ ./configure && \
145+ make && \
146+ make install
147+
148+
98149# ##
99150# ## Last Stage - Setup the Runtime Environment
100151# ##
101152
102153FROM ${RUNNER_IMAGE} AS app
103154
104- RUN apt-get update -y \
105- && apt-get install -y libstdc++6 openssl libncurses6 locales bash openssl curl python3 python3-pip jq xdelta3 zip unzip wget \
106- && wget https://github.com/fwup-home/fwup/releases/download/v1.13.2/fwup_1.13.2_amd64.deb \
107- && dpkg -i fwup_1.13.2_amd64.deb && rm fwup_1.13.2_amd64.deb \
108- && apt-get clean && rm -rf /var/lib/apt/lists/*
155+ RUN apt-get update -y && \
156+ apt-get install -y openssl ca-certificates locales bash xdelta3 && \
157+ apt-get autoremove -y && \
158+ apt-get clean && \
159+ rm -rf /var/lib/apt/lists/*
109160
110161# Set the locale
111162RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
112163
113- ENV LANG en_US.UTF-8
114- ENV LANGUAGE en_US:en
115- ENV LC_ALL en_US.UTF-8
164+ ENV LANG=en_US.UTF-8
165+ ENV LANGUAGE=en_US:en
166+ ENV LC_ALL=en_US.UTF-8
167+
168+ # Use jemalloc for memory allocation
169+ COPY --from=jemalloc /usr/local/lib/libjemalloc.so.2 /usr/local/lib/libjemalloc.so.2
170+ ENV LD_PRELOAD=/usr/local/lib/libjemalloc.so.2
116171
172+ # Copy over the statically built fwup
173+ COPY --from=fwup /usr/local/bin/fwup /usr/local/bin/fwup
174+
175+ # Copy over NervesHub
117176WORKDIR /app
118177
119178COPY --from=build /build/_build/prod/rel/nerves_hub ./
@@ -124,4 +183,5 @@ ENV SECRET_KEY_BASE=nokey
124183ENV PORT=4000
125184
126185ENTRYPOINT ["bin/nerves_hub" ]
186+
127187CMD ["start" ]
0 commit comments