Skip to content
Merged
32 changes: 32 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# .github/workflows/docker-publish.yml
name: Build and Publish Docker image to GHCR

on:
push:
branches: [ "master" ] # Change to your default branch

jobs:
build-and-push:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/backend:latest .
- name: Push Docker image
run: |
docker push ghcr.io/${{ github.repository_owner }}/backend:latest
39 changes: 17 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./
# Install curl (for Coolify healthchecks) and openssl (required by Prisma on Alpine)
RUN apk add --no-cache curl openssl

# 1. Copy dependency files first to maximize Docker layer caching
COPY package*.json ./
RUN npm install

# Install curl for healthchecks (required by Coolify)
RUN apk add --no-cache curl
# 2. Copy All folders for future proofing incase of custom setups later on
COPY . .

ARG DATABASE_URL
ARG DATABASE_URL_DOCKER
# 3. Define build arguments (ARGs).
# These will be available for `prisma generate` and `npm run build`,
ARG DATABASE_URL=postgresql://CHANGETHISDONOTFOLLOWTHIS:5432/placeholder_db
ARG META_NAME
ARG META_DESCRIPTION
ARG CRYPTO_SECRET
Expand All @@ -19,26 +22,18 @@ ARG CAPTCHA=false
ARG CAPTCHA_CLIENT_KEY
ARG TRAKT_CLIENT_ID
ARG TRAKT_SECRET_ID
ARG NODE_ENV=production

ENV DATABASE_URL=${DATABASE_URL}
ENV DATABASE_URL_DOCKER=${DATABASE_URL_DOCKER}
ENV META_NAME=${META_NAME}
ENV META_DESCRIPTION=${META_DESCRIPTION}
ENV CRYPTO_SECRET=${CRYPTO_SECRET}
ENV TMDB_API_KEY=${TMDB_API_KEY}
ENV CAPTCHA=${CAPTCHA}
ENV CAPTCHA_CLIENT_KEY=${CAPTCHA_CLIENT_KEY}
ENV TRAKT_CLIENT_ID=${TRAKT_CLIENT_ID}
ENV TRAKT_SECRET_ID=${TRAKT_SECRET_ID}
ENV NODE_ENV=${NODE_ENV}

COPY . .

RUN npx prisma generate
# 4. Generate Prisma client using the build-only placeholder URL
RUN DATABASE_URL=${DATABASE_URL} npx prisma generate

# 5. Build the application (it will use the ARGs above during compilation)
RUN npm run build

# 6. Set ONLY the essential, safe runtime variable.
ENV NODE_ENV=production

EXPOSE 3000

# Run migrations and start the server
# Users MUST provide the real variables via Docker Run / Compose
CMD ["sh", "-c", "npx prisma migrate deploy && node .output/server/index.mjs"]
Loading