refactor: Update Dockerfile to use glibc-based images for frontend and backend builds, and implement a minimal distroless runtime for improved security and efficiency. Enhance CI workflow with cleanup of old Docker images.
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 4m50s
Publish Fast Tabler Docker image / build-and-push-fast (push) Failing after 4m50s
This commit is contained in:
@@ -51,3 +51,28 @@ jobs:
|
|||||||
build-args: |
|
build-args: |
|
||||||
BUILDKIT_INLINE_CACHE=1
|
BUILDKIT_INLINE_CACHE=1
|
||||||
provenance: false
|
provenance: false
|
||||||
|
|
||||||
|
- name: Cleanup old images
|
||||||
|
run: |
|
||||||
|
# Get list of all tabler-fast images, sorted by creation date (newest first)
|
||||||
|
IMAGES=$(curl -s -H "Authorization: Bearer ${{ secrets.ACTIONS_PAT }}" \
|
||||||
|
"https://git.shts.su/api/v1/repos/${{ gitea.repository }}/tags?page=1&limit=100" | \
|
||||||
|
jq -r '.[] | select(.name | startswith("tabler-fast-")) | .name' | \
|
||||||
|
sort -r)
|
||||||
|
|
||||||
|
# Keep only the 3 most recent images
|
||||||
|
KEEP_COUNT=3
|
||||||
|
COUNT=0
|
||||||
|
|
||||||
|
echo "$IMAGES" | while read -r tag; do
|
||||||
|
if [ -n "$tag" ]; then
|
||||||
|
COUNT=$((COUNT + 1))
|
||||||
|
if [ $COUNT -gt $KEEP_COUNT ]; then
|
||||||
|
echo "Deleting old image: $tag"
|
||||||
|
curl -X DELETE -H "Authorization: Bearer ${{ secrets.ACTIONS_PAT }}" \
|
||||||
|
"https://git.shts.su/api/v1/repos/${{ gitea.repository }}/tags/$tag"
|
||||||
|
else
|
||||||
|
echo "Keeping image: $tag"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
+19
-35
@@ -1,63 +1,47 @@
|
|||||||
# syntax=docker/dockerfile:1.6
|
# syntax=docker/dockerfile:1.6
|
||||||
# Stage 1: Build React frontend
|
|
||||||
FROM node:20-alpine AS frontend-builder
|
# Stage 1: Build React frontend on glibc
|
||||||
|
FROM node:20-bookworm-slim AS frontend-builder
|
||||||
WORKDIR /app/frontend
|
WORKDIR /app/frontend
|
||||||
|
|
||||||
# Install build dependencies for native modules
|
ENV NODE_ENV=production
|
||||||
RUN apk add --no-cache python3 make g++
|
|
||||||
|
|
||||||
# Set npm config for better performance
|
|
||||||
RUN npm config set registry https://registry.npmjs.org/ \
|
RUN npm config set registry https://registry.npmjs.org/ \
|
||||||
&& npm config set fetch-timeout 300000 \
|
&& npm config set fetch-timeout 300000 \
|
||||||
&& npm config set fetch-retry-mintimeout 20000 \
|
&& npm config set fetch-retry-mintimeout 20000 \
|
||||||
&& npm config set fetch-retry-maxtimeout 120000
|
&& npm config set fetch-retry-maxtimeout 120000
|
||||||
|
|
||||||
# Copy package files first for better caching
|
|
||||||
COPY frontend/package*.json ./
|
COPY frontend/package*.json ./
|
||||||
|
|
||||||
# Install dependencies with cache (lockfile может отличаться после overrides/optional deps)
|
|
||||||
RUN --mount=type=cache,target=/root/.npm npm install --no-audit --no-fund
|
RUN --mount=type=cache,target=/root/.npm npm install --no-audit --no-fund
|
||||||
|
|
||||||
# Copy source code (only what's needed for build)
|
|
||||||
COPY frontend/src/ ./src/
|
COPY frontend/src/ ./src/
|
||||||
COPY frontend/public/ ./public/
|
COPY frontend/public/ ./public/
|
||||||
COPY frontend/index.html ./
|
COPY frontend/index.html ./
|
||||||
COPY frontend/vite.config.js ./
|
COPY frontend/vite.config.js ./
|
||||||
COPY frontend/eslint.config.js ./
|
COPY frontend/eslint.config.js ./
|
||||||
|
|
||||||
# Build the application with optimized settings
|
|
||||||
ENV ROLLUP_SKIP_NODEJS_NATIVE=1
|
ENV ROLLUP_SKIP_NODEJS_NATIVE=1
|
||||||
ENV ROLLUP_NO_NATIVE=1
|
ENV ROLLUP_NO_NATIVE=1
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Setup Node.js backend and serve everything
|
# Stage 2: Install backend deps on glibc
|
||||||
FROM node:20-alpine
|
FROM node:20-bookworm-slim AS backend-builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
# Set npm config for better performance
|
|
||||||
RUN npm config set registry https://registry.npmjs.org/ \
|
RUN npm config set registry https://registry.npmjs.org/ \
|
||||||
&& npm config set fetch-timeout 300000
|
&& npm config set fetch-timeout 300000
|
||||||
|
|
||||||
# Copy package files first for better caching
|
|
||||||
COPY backend/package*.json ./
|
COPY backend/package*.json ./
|
||||||
|
|
||||||
# Install production dependencies only with optimized flags
|
|
||||||
RUN --mount=type=cache,target=/root/.npm npm ci --only=production --no-audit --no-fund
|
RUN --mount=type=cache,target=/root/.npm npm ci --only=production --no-audit --no-fund
|
||||||
|
|
||||||
# Copy backend source code (only what's needed)
|
# Stage 3: Minimal runtime (distroless)
|
||||||
COPY backend/server.js ./
|
FROM gcr.io/distroless/nodejs20-debian12:nonroot
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy built frontend assets from the previous stage
|
# Copy runtime files
|
||||||
|
COPY --from=backend-builder /app/node_modules ./node_modules
|
||||||
|
COPY backend/server.js ./server.js
|
||||||
COPY --from=frontend-builder /app/frontend/dist ./public
|
COPY --from=frontend-builder /app/frontend/dist ./public
|
||||||
|
|
||||||
# Create non-root user for security
|
|
||||||
RUN addgroup -g 1001 -S nodejs
|
|
||||||
RUN adduser -S nodejs -u 1001
|
|
||||||
RUN chown -R nodejs:nodejs /app
|
|
||||||
USER nodejs
|
|
||||||
|
|
||||||
# The port the backend runs on
|
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
USER nonroot
|
||||||
# Start the server
|
CMD ["server.js"]
|
||||||
CMD ["node", "server.js"]
|
|
||||||
Reference in New Issue
Block a user