advplyr.audiobookshelf/Dockerfile

69 lines
1.5 KiB
Text
Raw Normal View History

### STAGE 0: Build client ###
FROM node:20-alpine AS build-client
2021-08-17 17:01:11 -05:00
WORKDIR /client
COPY /client /client
RUN npm ci && npm cache clean --force
2021-08-17 17:01:11 -05:00
RUN npm run generate
### STAGE 1: Build server ###
FROM node:20-alpine AS build-server
2021-08-17 17:01:11 -05:00
ENV NODE_ENV=production
RUN apk update && \
apk add --no-cache --update \
curl \
tzdata \
ffmpeg \
make \
python3 \
g++ \
tini \
unzip
WORKDIR /server
COPY index.js package* /server
COPY /server /server/server
ARG TARGETPLATFORM
ENV NUSQLITE3_DIR="/usr/local/lib/nusqlite3"
ENV NUSQLITE3_PATH="${NUSQLITE3_DIR}/libnusqlite3.so"
RUN case "$TARGETPLATFORM" in \
"linux/amd64") \
2024-10-07 20:48:52 +03:00
curl -L -o /tmp/library.zip "https://github.com/mikiher/nunicode-sqlite/releases/download/v1.2/libnusqlite3-linux-musl-x64.zip" ;; \
"linux/arm64") \
2024-10-07 20:48:52 +03:00
curl -L -o /tmp/library.zip "https://github.com/mikiher/nunicode-sqlite/releases/download/v1.2/libnusqlite3-linux-musl-arm64.zip" ;; \
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac && \
unzip /tmp/library.zip -d $NUSQLITE3_DIR && \
rm /tmp/library.zip
RUN npm ci --only=production
### STAGE 2: Create minimal runtime image ###
FROM node:20-alpine
# Install only runtime dependencies
RUN apk add --no-cache \
tzdata \
ffmpeg \
tini
WORKDIR /app
# Copy compiled frontend and server from build stages
COPY --from=build-client /client/dist /app/client/dist
COPY --from=build-server /server /app
2021-08-17 17:01:11 -05:00
EXPOSE 80
2025-01-07 17:41:09 +02:00
ENV PORT=80
ENV CONFIG_PATH="/config"
ENV METADATA_PATH="/metadata"
ENV SOURCE="docker"
Add tini as PID 1 handler in container image This PR adds `tini` to the container image and uses it as PID 1 when starting the container. This ensures that proper PID 1 signal-handling is implemented and passed to the underlying node.js process, thereby ensuring that the ABS process has a chance to receive and handle signals other than `SIGKILL`, such as the important `SIGINT`. This is somewhat related to #2445 . Without this, the signal handled by 2445 won't be received when running in a container. Some background: In linux, PID 1 has special duties involving signal handling that are different than other processes. Node doesn't properly handle these signals, which can lead to a number of problems ranging from annoying to disruptive. PID 1 also has reaping duties that can lead to resource exhaustion if not properly handled. For example, the container ignores `SIGINT` (Ctrl+C) as well as `docker stop`, which can be annoying in development as you have to kill or wait for the timeout to be reached. In a production environment (such as Kubernetes) this can lead to signal escalation and unnecessarily adds delays to deployments and restarts as K8s has to wait for the timeout to be reached before sending `SIGKILL`. At best this is annoying and unnecessarily adds delays. At worst this can lead to file/data corruption as the process doesn't get a chance to clean anything up when it is sent `SIGKILL`. Without a proper PID 1 to forward signals, only SIGKILL can be used to terminate the running process.
2024-01-03 13:55:43 -07:00
ENTRYPOINT ["tini", "--"]
CMD ["node", "index.js"]