Deploy Single Container architecture with Supervisord
This commit is contained in:
parent
4c5bccbd61
commit
ddb64e2ce3
4 changed files with 97 additions and 25 deletions
63
Dockerfile
Normal file
63
Dockerfile
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
# ---- Backend Builder ----
|
||||||
|
FROM golang:1.24-alpine AS backend-builder
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apk add --no-cache git gcc musl-dev
|
||||||
|
COPY backend/go.mod backend/go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY backend/ ./
|
||||||
|
RUN CGO_ENABLED=1 GOOS=linux go build -o kv-tube .
|
||||||
|
|
||||||
|
# ---- Frontend Builder ----
|
||||||
|
FROM node:20-alpine AS frontend-deps
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
|
WORKDIR /app
|
||||||
|
COPY frontend/package.json frontend/package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
FROM node:20-alpine AS frontend-builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=frontend-deps /app/node_modules ./node_modules
|
||||||
|
COPY frontend/ ./
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# ---- Final Unified Image ----
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# Install dependencies for Go backend, Node.js frontend, and Supervisord
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
nodejs \
|
||||||
|
ca-certificates \
|
||||||
|
ffmpeg \
|
||||||
|
curl \
|
||||||
|
python3 \
|
||||||
|
py3-pip \
|
||||||
|
supervisor \
|
||||||
|
&& curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp \
|
||||||
|
&& chmod a+rx /usr/local/bin/yt-dlp
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy Backend Binary
|
||||||
|
COPY --from=backend-builder /app/kv-tube /app/kv-tube
|
||||||
|
|
||||||
|
# Copy Frontend Standalone App
|
||||||
|
COPY --from=frontend-builder /app/public /app/frontend/public
|
||||||
|
COPY --from=frontend-builder /app/.next/standalone /app/frontend/
|
||||||
|
COPY --from=frontend-builder /app/.next/static /app/frontend/.next/static
|
||||||
|
|
||||||
|
# Copy Supervisord Config
|
||||||
|
COPY supervisord.conf /etc/supervisord.conf
|
||||||
|
|
||||||
|
# Setup Environment
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
ENV KVTUBE_DATA_DIR=/app/data
|
||||||
|
ENV GIN_MODE=release
|
||||||
|
ENV NEXT_PUBLIC_API_URL=http://127.0.0.1:8080
|
||||||
|
|
||||||
|
EXPOSE 3000 8080
|
||||||
|
|
||||||
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||||
|
|
@ -4,35 +4,18 @@
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
kv-tube-backend:
|
kv-tube-app:
|
||||||
image: git.khoavo.myds.me/vndangkhoa/kv-tube-backend:v4.0.1
|
image: git.khoavo.myds.me/vndangkhoa/kv-tube-app:v4.0.1
|
||||||
container_name: kv-tube-backend
|
container_name: kv-tube-app
|
||||||
platform: linux/amd64
|
platform: linux/amd64
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "5011:3000"
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
environment:
|
environment:
|
||||||
- KVTUBE_DATA_DIR=/app/data
|
- KVTUBE_DATA_DIR=/app/data
|
||||||
- GIN_MODE=release
|
- GIN_MODE=release
|
||||||
healthcheck:
|
- NODE_ENV=production
|
||||||
test: [ "CMD", "curl", "-f", "http://localhost:8080/api/health" ]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
start_period: 10s
|
|
||||||
labels:
|
|
||||||
- "com.centurylinklabs.watchtower.enable=true"
|
|
||||||
|
|
||||||
kv-tube-frontend:
|
|
||||||
image: git.khoavo.myds.me/vndangkhoa/kv-tube-frontend:v4.0.1
|
|
||||||
container_name: kv-tube-frontend
|
|
||||||
platform: linux/amd64
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- "5011:3000"
|
|
||||||
environment:
|
|
||||||
- NEXT_PUBLIC_API_URL=http://kv-tube-backend:8080
|
|
||||||
depends_on:
|
|
||||||
- kv-tube-backend
|
|
||||||
labels:
|
labels:
|
||||||
- "com.centurylinklabs.watchtower.enable=true"
|
- "com.centurylinklabs.watchtower.enable=true"
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ const nextConfig = {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
source: '/api/:path*',
|
source: '/api/:path*',
|
||||||
destination: 'http://kv-tube-backend:8080/api/:path*',
|
destination: 'http://127.0.0.1:8080/api/:path*',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: '/video_proxy',
|
source: '/video_proxy',
|
||||||
destination: 'http://kv-tube-backend:8080/video_proxy',
|
destination: 'http://127.0.0.1:8080/video_proxy',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
|
||||||
26
supervisord.conf
Normal file
26
supervisord.conf
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
||||||
|
logfile=/dev/null
|
||||||
|
logfile_maxbytes=0
|
||||||
|
|
||||||
|
[program:backend]
|
||||||
|
command=/app/kv-tube
|
||||||
|
directory=/app
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
stdout_logfile=/dev/stdout
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/stderr
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
environment=KVTUBE_DATA_DIR="/app/data",GIN_MODE="release"
|
||||||
|
|
||||||
|
[program:frontend]
|
||||||
|
command=node server.js
|
||||||
|
directory=/app/frontend
|
||||||
|
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"
|
||||||
Loading…
Reference in a new issue