diff --git a/Dockerfile b/Dockerfile index 71aea7c..30aa201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,82 +1,46 @@ # syntax=docker/dockerfile:1.4 -FROM node:lts-alpine AS base -ENV PNPM_HOME=/usr/local/bin -ENV PATH=$PNPM_HOME:$PATH -RUN apk add --no-cache libc6-compat +FROM oven/bun:1.2.9-alpine AS base +WORKDIR /app +RUN apk add --no-cache libc6-compat python3 make g++ gcc wget sqlite -# ----------------------------------- +# ---------------------------- FROM base AS deps -WORKDIR /app -RUN apk add --no-cache python3 make g++ gcc +COPY package.json bun.lockb* ./ +RUN bun install --frozen-lockfile -RUN --mount=type=cache,target=/root/.npm \ - corepack enable && corepack prepare pnpm@latest --activate - -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 +# ---------------------------- +FROM deps AS builder COPY . . - -RUN pnpm build -# Compile TypeScript scripts to JavaScript +RUN bun run build RUN mkdir -p dist/scripts && \ 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 -# ----------------------------------- +# ---------------------------- 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 WORKDIR /app - -# Only copy production node_modules and built output COPY --from=pruner /app/node_modules ./node_modules COPY --from=builder /app/dist ./dist COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/docker-entrypoint.sh ./docker-entrypoint.sh COPY --from=builder /app/scripts ./scripts -COPY --from=builder /app/data ./data ENV NODE_ENV=production ENV HOST=0.0.0.0 ENV PORT=4321 ENV DATABASE_URL=file:data/gitea-mirror.db -# Make entrypoint executable -RUN chmod +x /app/docker-entrypoint.sh - -ENTRYPOINT ["/app/docker-entrypoint.sh"] - -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 +RUN chmod +x ./docker-entrypoint.sh && \ + mkdir -p /app/data && \ + addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 gitea-mirror && \ + chown -R gitea-mirror:nodejs /app/data USER gitea-mirror @@ -86,8 +50,4 @@ EXPOSE 4321 HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:4321/ || exit 1 -# Create a startup script that initializes the database before starting the application -COPY --from=builder --chown=gitea-mirror:nodejs /app/docker-entrypoint.sh ./docker-entrypoint.sh -RUN chmod +x ./docker-entrypoint.sh - -CMD ["./docker-entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["./docker-entrypoint.sh"]