mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-06 11:36:44 +03:00
chore: switch docker build to bun
This commit is contained in:
78
Dockerfile
78
Dockerfile
@@ -1,82 +1,46 @@
|
|||||||
# syntax=docker/dockerfile:1.4
|
# syntax=docker/dockerfile:1.4
|
||||||
|
|
||||||
FROM node:lts-alpine AS base
|
FROM oven/bun:1.2.9-alpine AS base
|
||||||
ENV PNPM_HOME=/usr/local/bin
|
WORKDIR /app
|
||||||
ENV PATH=$PNPM_HOME:$PATH
|
RUN apk add --no-cache libc6-compat python3 make g++ gcc wget sqlite
|
||||||
RUN apk add --no-cache libc6-compat
|
|
||||||
|
|
||||||
# -----------------------------------
|
# ----------------------------
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
WORKDIR /app
|
COPY package.json bun.lockb* ./
|
||||||
RUN apk add --no-cache python3 make g++ gcc
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/root/.npm \
|
# ----------------------------
|
||||||
corepack enable && corepack prepare pnpm@latest --activate
|
FROM deps AS builder
|
||||||
|
|
||||||
COPY package.json pnpm-lock.yaml* ./
|
|
||||||
|
|
||||||
# Full dev install
|
|
||||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
|
||||||
pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
# -----------------------------------
|
|
||||||
FROM base AS builder
|
|
||||||
WORKDIR /app
|
|
||||||
RUN apk add --no-cache python3 make g++ gcc
|
|
||||||
|
|
||||||
RUN --mount=type=cache,target=/root/.npm \
|
|
||||||
corepack enable && corepack prepare pnpm@latest --activate
|
|
||||||
|
|
||||||
COPY --from=deps /app/node_modules ./node_modules
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN bun run build
|
||||||
RUN pnpm build
|
|
||||||
# Compile TypeScript scripts to JavaScript
|
|
||||||
RUN mkdir -p dist/scripts && \
|
RUN mkdir -p dist/scripts && \
|
||||||
for script in scripts/*.ts; do \
|
for script in scripts/*.ts; do \
|
||||||
node_modules/.bin/tsc --outDir dist/scripts --module commonjs --target es2020 --esModuleInterop $script || true; \
|
bun build "$script" --target=bun --outfile=dist/scripts/$(basename "${script%.ts}.js"); \
|
||||||
done
|
done
|
||||||
|
|
||||||
# -----------------------------------
|
# ----------------------------
|
||||||
FROM deps AS pruner
|
FROM deps AS pruner
|
||||||
WORKDIR /app
|
RUN bun install --production --frozen-lockfile
|
||||||
|
|
||||||
# Prune dev dependencies and just keep the production bits
|
# ----------------------------
|
||||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
|
||||||
pnpm prune --prod
|
|
||||||
|
|
||||||
# -----------------------------------
|
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Only copy production node_modules and built output
|
|
||||||
COPY --from=pruner /app/node_modules ./node_modules
|
COPY --from=pruner /app/node_modules ./node_modules
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/package.json ./package.json
|
COPY --from=builder /app/package.json ./package.json
|
||||||
COPY --from=builder /app/docker-entrypoint.sh ./docker-entrypoint.sh
|
COPY --from=builder /app/docker-entrypoint.sh ./docker-entrypoint.sh
|
||||||
COPY --from=builder /app/scripts ./scripts
|
COPY --from=builder /app/scripts ./scripts
|
||||||
COPY --from=builder /app/data ./data
|
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
ENV PORT=4321
|
ENV PORT=4321
|
||||||
ENV DATABASE_URL=file:data/gitea-mirror.db
|
ENV DATABASE_URL=file:data/gitea-mirror.db
|
||||||
|
|
||||||
# Make entrypoint executable
|
RUN chmod +x ./docker-entrypoint.sh && \
|
||||||
RUN chmod +x /app/docker-entrypoint.sh
|
mkdir -p /app/data && \
|
||||||
|
addgroup --system --gid 1001 nodejs && \
|
||||||
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
adduser --system --uid 1001 gitea-mirror && \
|
||||||
|
chown -R gitea-mirror:nodejs /app/data
|
||||||
RUN apk add --no-cache wget sqlite && \
|
|
||||||
mkdir -p /app/data && \
|
|
||||||
addgroup --system --gid 1001 nodejs && \
|
|
||||||
adduser --system --uid 1001 gitea-mirror && \
|
|
||||||
chown -R gitea-mirror:nodejs /app/data
|
|
||||||
|
|
||||||
COPY --from=builder --chown=gitea-mirror:nodejs /app/dist ./dist
|
|
||||||
COPY --from=pruner --chown=gitea-mirror:nodejs /app/node_modules ./node_modules
|
|
||||||
COPY --from=builder --chown=gitea-mirror:nodejs /app/package.json ./package.json
|
|
||||||
COPY --from=builder --chown=gitea-mirror:nodejs /app/scripts ./scripts
|
|
||||||
|
|
||||||
USER gitea-mirror
|
USER gitea-mirror
|
||||||
|
|
||||||
@@ -86,8 +50,4 @@ EXPOSE 4321
|
|||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:4321/ || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:4321/ || exit 1
|
||||||
|
|
||||||
# Create a startup script that initializes the database before starting the application
|
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||||
COPY --from=builder --chown=gitea-mirror:nodejs /app/docker-entrypoint.sh ./docker-entrypoint.sh
|
|
||||||
RUN chmod +x ./docker-entrypoint.sh
|
|
||||||
|
|
||||||
CMD ["./docker-entrypoint.sh"]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user