mirror of
https://github.com/Dvorinka/Dash.git
synced 2026-07-29 07:33:49 +00:00
ci/cd
This commit is contained in:
@@ -16,7 +16,7 @@ permissions:
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build-backend:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -44,62 +44,17 @@ jobs:
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/backend
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=semver,pattern={{version}}
|
||||
type=sha
|
||||
|
||||
- name: Build and push backend image
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: backend/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
|
||||
file: Dockerfile
|
||||
push: ${{ github.event_name == 'push' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
+57
@@ -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
@@ -15,34 +15,25 @@ services:
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
backend:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: backend/Dockerfile
|
||||
dockerfile: Dockerfile
|
||||
env_file:
|
||||
- .env.example
|
||||
environment:
|
||||
DATABASE_URL: postgres://dash:dash@postgres:5432/dash?sslmode=disable
|
||||
DATA_DIR: /data
|
||||
NEXT_PUBLIC_API_BASE_URL: http://localhost:8080
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- backend-data:/data
|
||||
depends_on:
|
||||
postgres:
|
||||
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:
|
||||
postgres-data:
|
||||
backend-data:
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user