Skip to content

Commit

Permalink
👷 build: add distroless support
Browse files Browse the repository at this point in the history
* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update main.yml

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile
  • Loading branch information
hezhijie0327 authored Dec 30, 2024
1 parent 5761303 commit 21688ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: docker/build-push-action@v5
with:
file: ./Dockerfile
platforms: linux/amd64, linux/arm64
platforms: linux/amd64
push: true
tags: |
hezhijie0327/lobechat:searxng
37 changes: 26 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
ARG NODEJS_VERSION="22"

FROM node:${NODEJS_VERSION}-alpine AS base
FROM node:${NODEJS_VERSION}-slim AS base

ARG USE_CN_MIRROR

RUN \
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
sed -i "s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g" "/etc/apk/repositories"; \
npm config set registry "https://registry.npmmirror.com/"; \
fi
sed -i "s/deb.debian.org/mirrors.ustc.edu.cn/g" "/etc/apt/sources.list.d/debian.sources"; \
fi \
&& apt update \
&& apt install -qy ca-certificates \
&& mkdir -p /distroless/bin /distroless/etc/ssl/certs /distroless/lib \
&& cp /usr/lib/$(arch)-linux-gnu/libdl.so.2 /distroless/lib/libdl.so.2 \
&& cp /usr/lib/$(arch)-linux-gnu/libstdc++.so.6 /distroless/lib/libstdc++.so.6 \
&& cp /usr/lib/$(arch)-linux-gnu/libgcc_s.so.1 /distroless/lib/libgcc_s.so.1 \
&& cp /usr/local/bin/node /distroless/bin/node \
&& cp /etc/ssl/certs/ca-certificates.crt /distroless/etc/ssl/certs/ca-certificates.crt \
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/*

FROM base AS builder

Expand All @@ -17,10 +27,16 @@ ADD . /app
WORKDIR /app

RUN \
npm i \
&& npm run build
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
npm config set registry "https://registry.npmmirror.com/"; \
fi \
&& npm i \
&& npm run build \
&& npm prune

FROM busybox:latest AS app

FROM base AS app
COPY --from=base /distroless/ /

COPY --from=builder /app/.next /app/.next
COPY --from=builder /app/public /app/public
Expand All @@ -31,13 +47,12 @@ FROM scratch

COPY --from=app / /

WORKDIR /app

ENV PORT="3000" \
PRODUCTION_URL=""

EXPOSE 3000/tcp

CMD \
sed "s|http://localhost:3000|${PRODUCTION_URL:-http://localhost:3000}|g" "/app/public/manifest-dev.json" > "/app/public/manifest.json"; \
npm run start
cd /app \
&& sed "s|http://localhost:3000|${PRODUCTION_URL:-http://localhost:3000}|g" "/app/public/manifest-dev.json" > "/app/public/manifest.json" \
&& node /app/node_modules/next/dist/bin/next start -H 0.0.0.0

0 comments on commit 21688ce

Please sign in to comment.