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
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
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 }}
1 name: Publish API to GitHub Container Registry
2
3 on:
4 push:
5 branches:
6 - main
7
8 jobs:
9 build-and-push-api:
10 runs-on: ubuntu-latest
11 permissions:
12 contents: read
13 packages: write
14
15 steps:
16 - name: Checkout code
17 uses: actions/checkout@v3
18
19 - name: Log in to GitHub Container Registry
20 uses: docker/login-action@v2
21 with:
22 registry: ghcr.io
23 username: ${{ github.actor }}
24 password: ${{ secrets.GITHUB_TOKEN }}
25
26 - name: Set up Docker Buildx
27 uses: docker/setup-buildx-action@v2
28
29 - name: Build and push Docker image
30 uses: docker/build-push-action@v4
31 with:
32 context: ./apps/api
33 push: true
34 tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:main

View File

@ -1,43 +1,19 @@
# Stage 1: Build
FROM node:22-alpine AS builder
FROM node:18-alpine
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY prisma ./prisma/
# Install dependencies
RUN npm ci
RUN npm ci --only=production
# Copy source code
# Copy application code
COPY . .
# Generate Prisma client
RUN npx prisma generate
# Build if needed
RUN npm run build --if-present
# Build the application
RUN npm run build
EXPOSE 3000
# Stage 2: Production
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"]
CMD ["npm", "start"]