deploy docker ghcr
This commit is contained in:
51
.github/workflows/docker-publish.yml
vendored
51
.github/workflows/docker-publish.yml
vendored
@@ -1,57 +1,56 @@
|
|||||||
name: Docker Build & Publish
|
name: Publish Docker to GHCR
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "v*"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
IMAGE_NAME: ${{ github.repository }}
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
publish:
|
||||||
|
name: Build & Push to GHCR
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Free disk space
|
||||||
|
run: |
|
||||||
|
sudo rm -rf /usr/share/dotnet
|
||||||
|
sudo rm -rf /usr/local/lib/android
|
||||||
|
sudo rm -rf /opt/ghc
|
||||||
|
sudo rm -rf /opt/hostedtoolcache/CodeQL
|
||||||
|
sudo docker image prune --all --force
|
||||||
|
df -h
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Extract tag name
|
||||||
|
id: meta
|
||||||
|
run: echo "tag=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to GHCR
|
- name: Log in to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Extract metadata
|
- name: Build and push Docker image
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
||||||
tags: |
|
|
||||||
type=semver,pattern={{version}}
|
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
type=raw,value=latest
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64
|
file: ./Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
platforms: linux/amd64
|
||||||
|
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tag }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
build-args: |
|
|
||||||
BUN_PUBLIC_BASE_URL=${{ vars.BUN_PUBLIC_BASE_URL }}
|
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
87
Dockerfile
87
Dockerfile
@@ -1,48 +1,69 @@
|
|||||||
FROM debian:bookworm-slim AS base
|
# ==============================
|
||||||
|
# Stage 1: Builder (Debian)
|
||||||
|
# ==============================
|
||||||
|
FROM node:20-bookworm-slim AS builder
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
||||||
curl unzip ca-certificates libssl3 && \
|
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
|
||||||
curl -fsSL https://bun.sh/install | bash
|
|
||||||
|
|
||||||
ENV PATH="/root/.bun/bin:$PATH"
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# ---- deps ----
|
# Install dependencies yang sebelumnya pakai apk
|
||||||
FROM base AS deps
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
libc6 \
|
||||||
|
git \
|
||||||
|
openssl \
|
||||||
|
ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY package.json bun.lockb ./
|
COPY package.json bun.lockb* ./
|
||||||
RUN bun install --frozen-lockfile
|
|
||||||
|
|
||||||
# ---- builder ----
|
ENV ONNXRUNTIME_NODE_INSTALL_CUDA=0
|
||||||
FROM deps AS builder
|
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1
|
||||||
|
|
||||||
COPY prisma ./prisma
|
RUN npm install --ignore-scripts
|
||||||
RUN bunx prisma generate
|
|
||||||
|
|
||||||
COPY src ./src
|
COPY . .
|
||||||
COPY types ./types
|
|
||||||
COPY tsconfig.json ./
|
|
||||||
|
|
||||||
# BUN_PUBLIC_* vars are baked into the browser bundle at build time
|
# Skip telemetry & limit memory
|
||||||
ARG BUN_PUBLIC_BASE_URL
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
ENV BUN_PUBLIC_BASE_URL=${BUN_PUBLIC_BASE_URL}
|
ENV NODE_OPTIONS="--max-old-space-size=4096"
|
||||||
RUN bun run build
|
|
||||||
|
|
||||||
# ---- runner ----
|
# Generate prisma client
|
||||||
FROM base AS runner
|
RUN npx prisma generate
|
||||||
|
|
||||||
COPY package.json bun.lockb ./
|
# Build Next.js
|
||||||
RUN bun install --production
|
RUN npm run build
|
||||||
|
|
||||||
COPY --from=builder /app/generated ./generated
|
|
||||||
COPY --from=builder /app/.next ./.next
|
# ==============================
|
||||||
COPY src ./src
|
# Stage 2: Runner (Debian)
|
||||||
COPY prisma ./prisma
|
# ==============================
|
||||||
COPY types ./types
|
FROM node:20-bookworm-slim AS runner
|
||||||
COPY tsconfig.json ./
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
openssl \
|
||||||
|
ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Buat user non-root (cara Debian)
|
||||||
|
RUN groupadd --system --gid 1001 nodejs \
|
||||||
|
&& useradd --system --uid 1001 --gid nodejs nextjs
|
||||||
|
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
COPY --from=builder /app/.next ./.next
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder /app/package.json ./package.json
|
||||||
|
|
||||||
|
RUN chown -R nextjs:nodejs /app
|
||||||
|
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
CMD ["bun", "run", "./src/index.tsx"]
|
ENV PORT=3000
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
|
||||||
|
CMD ["npx", "next", "start"]
|
||||||
|
|||||||
Reference in New Issue
Block a user