feat: add Dockerfiles for backend, frontend, and worker services with CI/CD pipeline configuration

This commit is contained in:
keven1024
2025-06-02 14:48:38 +08:00
parent 4bcab3ba5b
commit 07088b7f2e
5 changed files with 140 additions and 6553 deletions

56
.drone.yml Normal file
View File

@@ -0,0 +1,56 @@
trigger:
ref:
include:
- refs/tags/*
kind: pipeline
name: Build
steps:
- name: build-backend
image: plugins/docker
settings:
username: fudaoyuanicu
repo: fudaoyuanicu/015-backend
context: ./backend
password:
from_secret: docker_password
dockerfile: Dockerfile
tags:
- ${DRONE_TAG}
- latest
build_args:
- BUILD_TAG=${DRONE_TAG}
- name: build-frontend
image: plugins/docker
settings:
username: fudaoyuanicu
repo: fudaoyuanicu/015-frontend
context: ./front
password:
from_secret: docker_password
dockerfile: Dockerfile
tags:
- ${DRONE_TAG}
- latest
build_args:
- BUILD_TAG=${DRONE_TAG}
- name: build-worker
image: plugins/docker
settings:
username: fudaoyuanicu
repo: fudaoyuanicu/015-worker
context: ./worker
password:
from_secret: docker_password
dockerfile: Dockerfile
tags:
- ${DRONE_TAG}
- latest
build_args:
- BUILD_TAG=${DRONE_TAG}
- name: deploy
image: plugins/webhook
settings:
urls: http://192.168.100.5:8364/v1/update
content_type: application/json
headers:
- 'Authorization=Bearer helloworld'

27
backend/Dockerfile Normal file
View File

@@ -0,0 +1,27 @@
# syntax=docker/dockerfile:1
FROM golang:1.23.1 AS builder
# Set destination for COPY
WORKDIR /app
# Download Go modules
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/engine/reference/builder/#copy
COPY *.go ./
# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /backend
# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/engine/reference/builder/#expose
FROM alpine:3
COPY --from=builder /app/backend /bin/backend
ENTRYPOINT ["/bin/backend"]
EXPOSE 8080

35
front/Dockerfile Normal file
View File

@@ -0,0 +1,35 @@
FROM node:22-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json ./
RUN corepack enable pnpm && pnpm i
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN corepack enable pnpm && pnpm i && pnpm build
FROM base AS runner
ARG BUILD_TAG
WORKDIR /app
RUN apk add --no-cache curl openssl
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nuxtjs
# Only `.output` folder is needed from the build stage
COPY --from=builder --chown=nuxtjs:nodejs /app/.output/ ./
# Change the port and host
ENV PORT 80
ENV HOST 0.0.0.0
EXPOSE 80
CMD ["node", "/app/server/index.mjs"]

6553
front/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

22
worker/Dockerfile Normal file
View File

@@ -0,0 +1,22 @@
# syntax=docker/dockerfile:1
FROM golang:1.23.1 AS builder
# Set destination for COPY
WORKDIR /app
# Download Go modules
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code. Note the slash at the end, as explained in
# https://docs.docker.com/engine/reference/builder/#copy
COPY *.go ./
# Build
RUN CGO_ENABLED=0 GOOS=linux go build -o /worker
FROM alpine:3
RUN apk add --no-cache pngquant jpegoptim
COPY --from=builder /app/worker /bin/worker
ENTRYPOINT ["/bin/worker"]