Compare commits

...
3 Commits
3 changed files with 36 additions and 6 deletions

No files matched your search

+5 -3
View File
@@ -1,6 +1,8 @@
FROM golang:1.27.3-alpine AS builder FROM harbor.vitatech.com.cn:19443/vitavideo/base-golang:1.27.3-alpine AS builder
RUN apk add --no-cache git openssh-client RUN apk add --no-cache git openssh-client
ENV GOPRIVATE=git.vitatech.com.cn ARG GOPROXY=https://goproxy.cn,direct
ENV GOPROXY=${GOPROXY} \
GOPRIVATE=git.vitatech.com.cn
RUN git config --global url."ssh://git@git.vitatech.com.cn:12222/".insteadOf "https://git.vitatech.com.cn/" \ RUN git config --global url."ssh://git@git.vitatech.com.cn:12222/".insteadOf "https://git.vitatech.com.cn/" \
&& mkdir -p -m 0700 /root/.ssh && mkdir -p -m 0700 /root/.ssh
WORKDIR /src WORKDIR /src
@@ -11,7 +13,7 @@ RUN --mount=type=ssh,required=true \
COPY . . COPY . .
RUN CGO_ENABLED=0 go build -mod=readonly -trimpath -o /out/api ./cmd/api RUN CGO_ENABLED=0 go build -mod=readonly -trimpath -o /out/api ./cmd/api
FROM alpine:3.23 FROM harbor.vitatech.com.cn:19443/vitavideo/base-alpine:3.23
RUN apk add --no-cache ca-certificates tzdata RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app WORKDIR /app
COPY --from=builder /out/api ./api COPY --from=builder /out/api ./api
Vendored
+3 -3
View File
@@ -12,7 +12,7 @@ pipeline {
} }
environment { environment {
SERVICE = 'gin-api' SERVICE = 'gin-api'
IMAGE_REPOSITORY = 'harbor.vitatech.com.cn:19443/backend/gin_layout-api' IMAGE_REPOSITORY = 'harbor.vitatech.com.cn:19443/vitavideo/gin_layout-api'
DOCKERFILE = 'Dockerfile' DOCKERFILE = 'Dockerfile'
DEPLOY_ROOT = '/home/SHARE/devstack-scb/apps/layout-test' DEPLOY_ROOT = '/home/SHARE/devstack-scb/apps/layout-test'
} }
@@ -29,7 +29,7 @@ pipeline {
branches: [[name: '*/' + env.SOURCE_BRANCH]], branches: [[name: '*/' + env.SOURCE_BRANCH]],
userRemoteConfigs: [[ userRemoteConfigs: [[
url: 'ssh://git@git.vitatech.com.cn:12222/leo/gin_layout.git', url: 'ssh://git@git.vitatech.com.cn:12222/leo/gin_layout.git',
credentialsId: 'gitea-layout-read' credentialsId: 'gitea'
]], ]],
extensions: [[$class: 'CleanBeforeCheckout']] extensions: [[$class: 'CleanBeforeCheckout']]
]) ])
@@ -41,7 +41,7 @@ pipeline {
} }
stage('Build and push') { stage('Build and push') {
steps { steps {
sshagent(credentials: ['gitea-layout-read']) { sshagent(credentials: ['gitea']) {
withCredentials([ withCredentials([
file(credentialsId: 'gitea-known-hosts', variable: 'GIT_KNOWN_HOSTS'), file(credentialsId: 'gitea-known-hosts', variable: 'GIT_KNOWN_HOSTS'),
usernamePassword(credentialsId: 'harbor-backend', usernamePassword(credentialsId: 'harbor-backend',
+28
View File
@@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"errors" "errors"
"flag"
"fmt" "fmt"
"log/slog" "log/slog"
"net/http" "net/http"
@@ -10,6 +11,7 @@ import (
"os/signal" "os/signal"
"strconv" "strconv"
"syscall" "syscall"
"time"
"git.vitatech.com.cn/leo/proto.git/micro_layout/client" "git.vitatech.com.cn/leo/proto.git/micro_layout/client"
@@ -19,12 +21,38 @@ import (
) )
func main() { func main() {
healthcheckOnly := flag.Bool("healthcheck", false, "按服务配置检查健康状态并退出")
flag.Parse()
if *healthcheckOnly {
if err := checkHealth(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return
}
if err := run(); err != nil { if err := run(); err != nil {
slog.Error("application stopped", "error", err) slog.Error("application stopped", "error", err)
os.Exit(1) os.Exit(1)
} }
} }
func checkHealth() error {
cfg, err := config.Load()
if err != nil {
return err
}
client := &http.Client{Timeout: 3 * time.Second}
response, err := client.Get(fmt.Sprintf("http://127.0.0.1:%d/health", cfg.Server.Port))
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return fmt.Errorf("HTTP healthcheck returned status %d", response.StatusCode)
}
return nil
}
func run() error { func run() error {
cfg, err := config.Load() cfg, err := config.Load()
if err != nil { if err != nil {