This commit is contained in:
Tomas Dvorak
2026-05-07 10:17:07 +02:00
parent b7d86ad5f8
commit 7051459017
4 changed files with 94 additions and 62 deletions
+4 -49
View File
@@ -16,7 +16,7 @@ permissions:
packages: write packages: write
jobs: jobs:
build-backend: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -44,62 +44,17 @@ jobs:
id: meta id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}
tags: | tags: |
type=ref,event=branch type=ref,event=branch
type=semver,pattern={{version}} type=semver,pattern={{version}}
type=sha type=sha
- name: Build and push backend image - name: Build and push image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
file: backend/Dockerfile file: Dockerfile
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to registry (push only) - GitHub
if: github.event_name == 'push' && github.server_url == 'https://github.com'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to registry (push only) - Gitea
if: github.event_name == 'push' && github.server_url != 'https://github.com'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GITEA_USERNAME || github.actor }}
password: ${{ secrets.GITEA_TOKEN || secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/frontend
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=sha
- name: Build and push frontend image
uses: docker/build-push-action@v6
with:
context: ./frontend
file: frontend/Dockerfile
push: ${{ github.event_name == 'push' }} push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
+57
View File
@@ -0,0 +1,57 @@
# Build stage for frontend
FROM node:22-alpine AS frontend-builder
WORKDIR /app
COPY frontend/package.json frontend/package-lock.json* ./frontend/
WORKDIR /app/frontend
RUN npm ci
WORKDIR /app
COPY frontend ./frontend
WORKDIR /app/frontend
RUN npm run build
# Build stage for backend
FROM golang:1.26-alpine AS backend-builder
WORKDIR /src
RUN apk add --no-cache git ca-certificates
COPY backend/go.mod backend/go.sum* ./backend/
WORKDIR /src/backend
RUN go mod download
WORKDIR /src
COPY backend ./backend
COPY db ./db
WORKDIR /src/backend
RUN CGO_ENABLED=0 GOOS=linux go build -o /out/dash-backend ./cmd/server
# Final stage with supervisord
FROM alpine:3.22
# Install supervisord
RUN apk add --no-cache ca-certificates supervisor
# Create users
RUN adduser -D -H -u 10001 app && \
addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Setup directories
RUN mkdir -p /app/frontend /data /var/log/supervisor && \
chown -R app:app /data /app && \
chown -R nextjs:nodejs /app/frontend
# Copy backend
COPY --from=backend-builder /out/dash-backend /app/dash-backend
COPY --from=backend-builder /src/db /app/db
# Copy frontend
COPY --from=frontend-builder /app/frontend/public /app/frontend/public
COPY --from=frontend-builder --chown=nextjs:nodejs /app/frontend/.next/standalone /app/frontend/
COPY --from=frontend-builder --chown=nextjs:nodejs /app/frontend/.next/static /app/frontend/.next/static
# Copy supervisord config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Expose ports
EXPOSE 8080 3000
# Start supervisord
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
+4 -13
View File
@@ -15,34 +15,25 @@ services:
timeout: 5s timeout: 5s
retries: 10 retries: 10
backend: app:
build: build:
context: . context: .
dockerfile: backend/Dockerfile dockerfile: Dockerfile
env_file: env_file:
- .env.example - .env.example
environment: environment:
DATABASE_URL: postgres://dash:dash@postgres:5432/dash?sslmode=disable DATABASE_URL: postgres://dash:dash@postgres:5432/dash?sslmode=disable
DATA_DIR: /data DATA_DIR: /data
NEXT_PUBLIC_API_BASE_URL: http://localhost:8080
ports: ports:
- "8080:8080" - "8080:8080"
- "3000:3000"
volumes: volumes:
- backend-data:/data - backend-data:/data
depends_on: depends_on:
postgres: postgres:
condition: service_healthy condition: service_healthy
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
environment:
- NEXT_PUBLIC_API_BASE_URL=http://localhost:8080
ports:
- "3000:3000"
depends_on:
- backend
volumes: volumes:
postgres-data: postgres-data:
backend-data: backend-data:
+29
View File
@@ -0,0 +1,29 @@
[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
pidfile=/tmp/supervisord.pid
[program:backend]
command=/app/dash-backend
directory=/app
user=app
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
environment=HTTP_ADDR=":8080",MIGRATIONS_DIR="/app/db/migrations"
[program:frontend]
command=node server.js
directory=/app/frontend
user=nextjs
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
environment=NODE_ENV="production",PORT="3000",HOSTNAME="0.0.0.0",NEXT_PUBLIC_API_BASE_URL="http://localhost:8080"