Restructure docs and HPNP build to dramatically reduce Docker image size.

This commit is contained in:
Buster Neece 2023-12-12 10:43:14 -06:00
parent ca37639153
commit ee7feb6974
No known key found for this signature in database
13 changed files with 966 additions and 243 deletions

3
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Node Modules
# Frontend
node_modules
/frontend/hpnp*
# Junk/cache files.
*Thumbs.db

View File

@ -15,6 +15,11 @@ RUN go install github.com/aptible/supercronic@v0.2.28
#
FROM mariadb:11.2-jammy AS mariadb
#
# Built-in docs build step
#
FROM ghcr.io/azuracast/azuracast.com:builtin AS docs
#
# Final build image
#
@ -38,6 +43,9 @@ COPY ./util/docker/common /bd_build/
RUN bash /bd_build/prepare.sh \
&& bash /bd_build/add_user.sh
# Add built-in docs
COPY --from=docs --chown=azuracast:azuracast /dist /var/azuracast/docs
# Build each set of dependencies in their own step for cacheability.
COPY ./util/docker/supervisor /bd_build/supervisor/
RUN bash /bd_build/supervisor/setup.sh \
@ -64,28 +72,11 @@ RUN bash /bd_build/redis/setup.sh \
&& bash /bd_build/cleanup.sh \
&& rm -rf /bd_build/redis
COPY ./util/docker/docs /bd_build/docs/
RUN bash /bd_build/docs/setup.sh \
&& bash /bd_build/cleanup.sh \
&& rm -rf /bd_build/docs
RUN bash /bd_build/chown_dirs.sh \
&& rm -rf /bd_build
USER azuracast
# Build HPNP
RUN mkdir -p /tmp/hpnp
COPY --chown=azuracast:azuracast ./frontend /tmp/hpnp
RUN cd /tmp/hpnp \
&& npm ci --include=dev \
&& npm run build-hpnp \
&& chmod a+x /var/azuracast/scripts/hpnp.cjs \
&& cd /tmp \
&& rm -rf /tmp/hpnp
RUN touch /var/azuracast/.docker
USER root
@ -161,6 +152,18 @@ ENV TZ="UTC" \
ENTRYPOINT ["tini", "--", "/usr/local/bin/my_init"]
CMD ["--no-main-command"]
#
# High-Performance Now Playing (HPNP) Build
#
FROM node:20-alpine AS hpnp
COPY --chown=node:node ./frontend /data
WORKDIR /data
USER node
RUN npm ci --include=dev \
&& npm run build-hpnp
#
# Final build (Just environment vars and squishing the FS)
#
@ -168,6 +171,10 @@ FROM ubuntu:jammy AS final
COPY --from=pre-final / /
# Add HPNP from previous step
COPY --from=hpnp --chown=azuracast:azuracast /data/hpnp /usr/local/bin/hpnp
RUN chmod a+x /usr/local/bin/hpnp
USER azuracast
WORKDIR /var/azuracast/www

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
"serve": "vite",
"generate-locales": "vue-gettext-extract",
"generate-api": "swagger-typescript-api --path http://localhost/api/openapi.yml --output ./src/entities --name ApiInterfaces.ts --no-client",
"build-hpnp": "esbuild --bundle --target=node20 --platform=node ./src/hpnp/index.ts > /var/azuracast/scripts/hpnp.cjs"
"build-hpnp": "esbuild --bundle --target=node18 --platform=node ./src/hpnp/index.ts > ./hpnp.cjs && pkg --target=node18-linux --output ./hpnp ./hpnp.cjs"
},
"dependencies": {
"@codemirror/lang-css": "^6.0.1",
@ -41,6 +41,7 @@
"luxon": "^3",
"milliparsec": "^2.3.0",
"nprogress": "^0.2.0",
"pkg": "^5.8.1",
"qrcode": "^1.5.3",
"roboto-fontface": "^0.10.0",
"sweetalert2": "11.4.8",

View File

@ -12,6 +12,7 @@ adduser --home /var/azuracast --disabled-password --gecos "" azuracast
usermod -aG www-data azuracast
mkdir -p /var/azuracast/www /var/azuracast/stations /var/azuracast/www_tmp \
/var/azuracast/docs \
/var/azuracast/backups \
/var/azuracast/dbip \
/var/azuracast/scripts \

View File

@ -0,0 +1,10 @@
#!/bin/bash
set -e
set -x
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt-get update
apt-get install -y --no-install-recommends nodejs

View File

@ -1,18 +0,0 @@
#!/bin/bash
set -e
set -x
export DEBIAN_FRONTEND=noninteractive
mkdir -p /tmp/docs
cd /tmp/docs
# Cached commit: ff7abc40a61281e2474c724cc6f578dd382e7320
git clone https://github.com/AzuraCast/azuracast.com.git .
cd builtin
bash build.sh
mkdir -p /var/azuracast/docs
cp -TR /tmp/docs/builtin/dist/ /var/azuracast/docs/
rm -rf /tmp/docs

21
util/docker/hpnp/setup.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
set -e
set -x
export DEBIAN_FRONTEND=noninteractive
apt-get update
# Install common scripts
# cp -rT /bd_build/hpnp/scripts/ /usr/local/bin
# cp -rT /bd_build/hpnp/startup_scripts/. /etc/my_init.d/
# cp -rT /bd_build/hpnp/service.minimal/. /etc/supervisor/minimal.conf.d/
cp -rT /bd_build/hpnp/service.full/. /etc/supervisor/full.conf.d/
# Run service setup for all setup scripts
for f in /bd_build/hpnp/setup/*.sh; do
bash "$f" -H
done

View File

@ -0,0 +1,9 @@
#!/bin/bash
set -e
set -x
apt-get install -y --no-install-recommends nodejs
apt-get remove --purge -y nodejs

View File

@ -16,8 +16,7 @@ set -x
apt-get update
apt-get install -q -y --no-install-recommends \
mariadb-server mariadb-backup \
ca-certificates gpg gpgv libjemalloc2 pwgen tzdata xz-utils zstd
mariadb-server mariadb-backup mariadb-client
rm -rf /var/lib/mysql
mkdir -p /var/lib/mysql /var/run/mysqld

View File

@ -3,10 +3,6 @@ set -e
set -x
# Group up several package installations here to reduce overall build time
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
add-apt-repository -y ppa:chris-needham/ppa
add-apt-repository -y ppa:ondrej/php
apt-get update
@ -14,7 +10,5 @@ apt-get update
apt-get install -y --no-install-recommends \
audiowaveform=1.9.1-1jammy1 \
nginx nginx-common openssl \
nodejs \
tmpreaper \
zstd \
netbase
zstd

View File

@ -9,8 +9,7 @@ PHP_VERSION=8.2
apt-get install -y --no-install-recommends php${PHP_VERSION}-fpm php${PHP_VERSION}-cli php${PHP_VERSION}-gd \
php${PHP_VERSION}-curl php${PHP_VERSION}-xml php${PHP_VERSION}-zip php${PHP_VERSION}-bcmath \
php${PHP_VERSION}-gmp php${PHP_VERSION}-mysqlnd php${PHP_VERSION}-mbstring php${PHP_VERSION}-intl \
php${PHP_VERSION}-redis php${PHP_VERSION}-maxminddb php${PHP_VERSION}-xdebug \
mariadb-client
php${PHP_VERSION}-redis php${PHP_VERSION}-maxminddb php${PHP_VERSION}-xdebug
# Copy PHP configuration
echo "PHP_VERSION=$PHP_VERSION" >> /etc/php/.version