build(deploy): replace pre-compiled arm64 binaries with multi-stage Go compilation for amd64
WHY: existing Dockerfiles copied pre-compiled arm64 binaries which cannot run on the amd64 K3s cluster (exec format error). Also fixed port conflicts when running muyu alongside iloom in docker-compose. HOW: - rewrite 3 Dockerfiles (system/inventory/gateway) to multi-stage builds using golang:1.24-alpine with CGO_ENABLED=0 GOARCH=amd64 - parameterize host ports in docker-compose to avoid conflicts (3306->13306, 6379->16379, 8080->18080) - fix inv_product unique key from product_name-only to composite (product_name, spec, color) to allow same-name products with different specs - add X-Token to Authorization header middleware in gateway for iloom frontend compatibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3ddc851340
commit
4144628cb6
@ -1,7 +1,15 @@
|
|||||||
FROM alpine:3.19
|
FROM golang:1.24-alpine AS builder
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
WORKDIR /app
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server ./gateway/gateway.go
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
RUN apk add --no-cache ca-certificates tzdata
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY deploy/bin/gateway .
|
COPY --from=builder /server ./gateway
|
||||||
COPY deploy/etc/gateway.yaml etc/gateway.yaml
|
COPY deploy/etc/gateway.yaml etc/gateway.yaml
|
||||||
EXPOSE 8888
|
EXPOSE 8888
|
||||||
CMD ["./gateway", "-f", "etc/gateway.yaml"]
|
CMD ["./gateway", "-f", "etc/gateway.yaml"]
|
||||||
|
|||||||
@ -1,7 +1,15 @@
|
|||||||
FROM alpine:3.19
|
FROM golang:1.24-alpine AS builder
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
WORKDIR /app
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server ./rpc/inventory/inventory.go
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
RUN apk add --no-cache ca-certificates tzdata
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY deploy/bin/inventory .
|
COPY --from=builder /server ./inventory
|
||||||
COPY deploy/etc/inventory.yaml etc/inventory.yaml
|
COPY deploy/etc/inventory.yaml etc/inventory.yaml
|
||||||
EXPOSE 9002
|
EXPOSE 9002
|
||||||
CMD ["./inventory", "-f", "etc/inventory.yaml"]
|
CMD ["./inventory", "-f", "etc/inventory.yaml"]
|
||||||
|
|||||||
@ -1,7 +1,15 @@
|
|||||||
FROM alpine:3.19
|
FROM golang:1.24-alpine AS builder
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
WORKDIR /app
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server ./rpc/system/system.go
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
RUN apk add --no-cache ca-certificates tzdata
|
RUN apk add --no-cache ca-certificates tzdata
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY deploy/bin/system .
|
COPY --from=builder /server ./system
|
||||||
COPY deploy/etc/system.yaml etc/system.yaml
|
COPY deploy/etc/system.yaml etc/system.yaml
|
||||||
EXPOSE 9001
|
EXPOSE 9001
|
||||||
CMD ["./system", "-f", "etc/system.yaml"]
|
CMD ["./system", "-f", "etc/system.yaml"]
|
||||||
|
|||||||
@ -8,7 +8,7 @@ services:
|
|||||||
MYSQL_DATABASE: muyu_wms
|
MYSQL_DATABASE: muyu_wms
|
||||||
TZ: Asia/Shanghai
|
TZ: Asia/Shanghai
|
||||||
ports:
|
ports:
|
||||||
- "3306:3306"
|
- "${MYSQL_PORT:-13306}:3306"
|
||||||
volumes:
|
volumes:
|
||||||
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
- ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
- ../data/mysql:/var/lib/mysql
|
- ../data/mysql:/var/lib/mysql
|
||||||
@ -24,7 +24,7 @@ services:
|
|||||||
container_name: muyu-redis
|
container_name: muyu-redis
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "${REDIS_PORT:-16379}:6379"
|
||||||
volumes:
|
volumes:
|
||||||
- ../data/redis:/data
|
- ../data/redis:/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
@ -106,7 +106,7 @@ services:
|
|||||||
container_name: muyu-nginx
|
container_name: muyu-nginx
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "8080:80"
|
- "${NGINX_PORT:-18080}:80"
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
- ../../muyu-portal/dist:/usr/share/nginx/html
|
- ../../muyu-portal/dist:/usr/share/nginx/html
|
||||||
|
|||||||
@ -146,7 +146,7 @@ CREATE TABLE `inv_product` (
|
|||||||
`deleted_at` DATETIME DEFAULT NULL,
|
`deleted_at` DATETIME DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `uk_product_id` (`product_id`),
|
UNIQUE KEY `uk_product_id` (`product_id`),
|
||||||
UNIQUE KEY `uk_product_name` (`product_name`),
|
UNIQUE KEY `uk_product_name_spec_color` (`product_name`, `spec`, `color`),
|
||||||
KEY `idx_color` (`color`),
|
KEY `idx_color` (`color`),
|
||||||
KEY `idx_location` (`location`),
|
KEY `idx_location` (`location`),
|
||||||
KEY `idx_status` (`status`),
|
KEY `idx_status` (`status`),
|
||||||
|
|||||||
@ -36,6 +36,15 @@ func main() {
|
|||||||
server := rest.MustNewServer(c.RestConf, rest.WithCors())
|
server := rest.MustNewServer(c.RestConf, rest.WithCors())
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
|
server.Use(func(next http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if token := r.Header.Get("X-Token"); token != "" {
|
||||||
|
r.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
}
|
||||||
|
next(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, interface{}) {
|
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, interface{}) {
|
||||||
s, ok := status.FromError(err)
|
s, ok := status.FromError(err)
|
||||||
if ok {
|
if ok {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user