Configure GitHub Action for GHCR and move Dockerfile

This commit is contained in:
gamvo74 2026-02-22 08:59:33 -05:00
parent 04a0358dd6
commit eb121d03aa
2 changed files with 41 additions and 86 deletions

View File

@ -1,55 +1,34 @@
name: Publish to GitHub Container Registry 1 name: Publish API to GitHub Container Registry
2
on: 3 on:
push: 4 push:
branches: 5 branches:
- main 6 - main
tags: 7
- 'v*' 8 jobs:
pull_request: 9 build-and-push-api:
branches: 10 runs-on: ubuntu-latest
- main 11 permissions:
12 contents: read
env: 13 packages: write
REGISTRY: ghcr.io 14
IMAGE_NAME: ${{ github.repository }} 15 steps:
16 - name: Checkout code
jobs: 17 uses: actions/checkout@v3
build-and-push: 18
runs-on: ubuntu-latest 19 - name: Log in to GitHub Container Registry
permissions: 20 uses: docker/login-action@v2
contents: read 21 with:
packages: write 22 registry: ghcr.io
23 username: ${{ github.actor }}
steps: 24 password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository 25
uses: actions/checkout@v4 26 - name: Set up Docker Buildx
27 uses: docker/setup-buildx-action@v2
- name: Set up Docker Buildx 28
uses: docker/setup-buildx-action@v3 29 - name: Build and push Docker image
30 uses: docker/build-push-action@v4
- name: Log in to Container Registry 31 with:
uses: docker/login-action@v3 32 context: ./apps/api
with: 33 push: true
registry: ${{ env.REGISTRY }} 34 tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:main
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@ -1,43 +1,19 @@
# Stage 1: Build FROM node:18-alpine
FROM node:22-alpine AS builder
WORKDIR /app WORKDIR /app
# Copy package files # Copy package files
COPY package*.json ./ COPY package*.json ./
COPY prisma ./prisma/
# Install dependencies # Install dependencies
RUN npm ci RUN npm ci --only=production
# Copy source code # Copy application code
COPY . . COPY . .
# Generate Prisma client # Build if needed
RUN npx prisma generate RUN npm run build --if-present
# Build the application EXPOSE 3000
RUN npm run build
# Stage 2: Production CMD ["npm", "start"]
FROM node:22-alpine
WORKDIR /app
# Install compatibility libraries for Prisma
RUN apk add --no-cache libc6-compat gcompat openssl
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
# Create a non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
EXPOSE 4000
ENV NODE_ENV=production
CMD ["node", "dist/main"]