mirror of
https://github.com/p-stream/backend.git
synced 2026-03-11 17:55:35 +00:00
Improve Docker image publish workflow and DockerFile (#37)
Some checks failed
Build and Publish Docker image to GHCR / build-and-push (push) Has been cancelled
Some checks failed
Build and Publish Docker image to GHCR / build-and-push (push) Has been cancelled
This commit is contained in:
parent
68df7fa8ad
commit
a0ffb32fd5
3 changed files with 138 additions and 22 deletions
84
.dockerignore
Normal file
84
.dockerignore
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
# VCS
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.gitattributes
|
||||||
|
.github/
|
||||||
|
|
||||||
|
# Dependencies installed on host
|
||||||
|
node_modules/
|
||||||
|
.npm/
|
||||||
|
.pnpm-store/
|
||||||
|
.yarn/
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
# Build output / caches
|
||||||
|
.output/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
coverage/
|
||||||
|
.nyc_output/
|
||||||
|
.cache/
|
||||||
|
.parcel-cache/
|
||||||
|
.eslintcache
|
||||||
|
.stylelintcache
|
||||||
|
*.tsbuildinfo
|
||||||
|
tmp/
|
||||||
|
temp/
|
||||||
|
|
||||||
|
# Tests / local-only files
|
||||||
|
test/
|
||||||
|
tests/
|
||||||
|
__tests__/
|
||||||
|
__mocks__/
|
||||||
|
|
||||||
|
# Local env / secrets
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
*.pem
|
||||||
|
*.key
|
||||||
|
*.crt
|
||||||
|
*.p12
|
||||||
|
*.jks
|
||||||
|
|
||||||
|
# Local DB / runtime artifacts
|
||||||
|
*.sqlite
|
||||||
|
*.sqlite3
|
||||||
|
*.db
|
||||||
|
|
||||||
|
# Logs / pid files
|
||||||
|
logs/
|
||||||
|
*.log
|
||||||
|
pids/
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Editor / OS
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Docker / deployment config
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
docker-compose.yml
|
||||||
|
nixpacks.toml
|
||||||
|
railpack.json
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
|
||||||
|
# Dev-only source folders
|
||||||
|
examples/
|
||||||
|
|
||||||
|
# Dev tooling config
|
||||||
|
.eslintrc.json
|
||||||
|
.prettierrc
|
||||||
37
.github/workflows/docker-publish.yml
vendored
Normal file
37
.github/workflows/docker-publish.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# .github/workflows/docker-publish.yml
|
||||||
|
name: Build and Publish Docker image to GHCR
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ] # Change to your default branch
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
|
||||||
|
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 -t ghcr.io/${{ github.repository_owner }}/backend:${{ github.sha }} .
|
||||||
|
- name: Push Docker image
|
||||||
|
run: |
|
||||||
|
docker push ghcr.io/${{ github.repository_owner }}/backend:latest
|
||||||
|
docker push ghcr.io/${{ github.repository_owner }}/backend:${{ github.sha }}
|
||||||
39
Dockerfile
39
Dockerfile
|
|
@ -1,16 +1,19 @@
|
||||||
FROM node:22-alpine
|
FROM node:22-alpine
|
||||||
|
|
||||||
WORKDIR /app
|
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
|
RUN npm install
|
||||||
|
|
||||||
# Install curl for healthchecks (required by Coolify)
|
# 2. Copy All folders for future proofing incase of custom setups later on
|
||||||
RUN apk add --no-cache curl
|
COPY . .
|
||||||
|
|
||||||
ARG DATABASE_URL
|
# 3. Define build arguments (ARGs).
|
||||||
ARG DATABASE_URL_DOCKER
|
# These will be available for `prisma generate` and `npm run build`,
|
||||||
|
ARG DATABASE_URL=postgresql://CHANGETHISDONOTFOLLOWTHIS:5432/placeholder_db
|
||||||
ARG META_NAME
|
ARG META_NAME
|
||||||
ARG META_DESCRIPTION
|
ARG META_DESCRIPTION
|
||||||
ARG CRYPTO_SECRET
|
ARG CRYPTO_SECRET
|
||||||
|
|
@ -19,26 +22,18 @@ ARG CAPTCHA=false
|
||||||
ARG CAPTCHA_CLIENT_KEY
|
ARG CAPTCHA_CLIENT_KEY
|
||||||
ARG TRAKT_CLIENT_ID
|
ARG TRAKT_CLIENT_ID
|
||||||
ARG TRAKT_SECRET_ID
|
ARG TRAKT_SECRET_ID
|
||||||
ARG NODE_ENV=production
|
|
||||||
|
|
||||||
ENV DATABASE_URL=${DATABASE_URL}
|
# 4. Generate Prisma client using the build-only placeholder URL
|
||||||
ENV DATABASE_URL_DOCKER=${DATABASE_URL_DOCKER}
|
RUN DATABASE_URL=${DATABASE_URL} npx prisma generate
|
||||||
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
|
|
||||||
|
|
||||||
|
# 5. Build the application (it will use the ARGs above during compilation)
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# 6. Set ONLY the essential, safe runtime variable.
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
EXPOSE 3000
|
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"]
|
CMD ["sh", "-c", "npx prisma migrate deploy && node .output/server/index.mjs"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue