Compare commits

..

3 Commits
dev ... main

Author SHA1 Message Date
141f1f543e Merge pull request 'dev' (#3) from dev into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #3
2024-02-28 17:25:20 +08:00
5e26ffcd91 Merge pull request 'dev' (#2) from dev into main
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
Reviewed-on: #2
2024-02-28 16:52:46 +08:00
d28c9cf024 Merge pull request 'dev' (#1) from dev into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #1
2024-02-28 16:03:08 +08:00
4 changed files with 63 additions and 58 deletions

View File

@ -1,37 +1,10 @@
kind: pipeline
name: default
#设置挂载
volumes:
#Go编译缓存
- name: pkgdeps
host:
path: /mnt/drone/cache/go
clone:
disable: false # 启用代码拉取
steps:
#构建镜像
- name: build
image: golang:latest
pull: if-not-exists
volumes:
- name: pkgdeps
path: /go/pkg
environment:
GOPROXY: "https://goproxy.cn,direct" # 懂的都懂
commands:
- echo "start build app"
- CGO_ENABLED=0 go build -o cli -ldflags="-w -s"
when:
branch:
- master
- dev
event:
- push
# 开发版
- name: docker-${DRONE_BRANCH}
image: plugins/docker
@ -45,7 +18,7 @@ steps:
debug: true
dockerfile: Dockerfile
tags:
- latest
- canary
when:
branch:
- master
@ -53,6 +26,25 @@ steps:
event:
- push
# 稳定版
- name: docker-release
image: plugins/docker
settings:
username: liupeng
password:
from_secret: DOCKER_PASSWORD
registry: git.daymele.com
repo: git.daymele.com/liupeng/drone
insecure: true
dockerfile: Dockerfile
tags:
- ${DRONE_TAG}
- latest
when:
event:
- tag
- name: deploy-${DRONE_BRANCH}
image: appleboy/drone-ssh
settings:
@ -68,7 +60,7 @@ steps:
script:
- echo "deploy docker ssh!"
- name=drone-test
- image=git.daymele.com/liupeng/drone:latest
- image=git.daymele.com/liupeng/drone:canary
- echo ${DRONE_BRANCH}
- docker pull $image
- docker rm -f drone-test || true
@ -82,4 +74,26 @@ steps:
- push
- name: deploy-release
image: appleboy/drone-ssh
settings:
host:
- pub.daymele.com
username: liup
# password:
# from_secret: HOST_PASSWORD
key:
from_secret: HOST_KEY
port: 22
command_timeout: 2m
script:
- echo "deploy podman ssh!"
- name=drone-release
- image=git.daymele.com/liupeng/drone:latest
- podman pull $image
- podman rm -f drone-release || true
- podman image prune -f
- podman run --name=$name -d -p 8002:9000 -v /etc/conf:/conf $image
when:
event:
- tag

View File

@ -1,32 +1,23 @@
# syntax=docker/dockerfile:1.2
# FROM golang as builder
# ENV GO111MODULE on
# ENV GOPROXY=https://goproxy.io
# WORKDIR /src
# RUN groupadd -r appuser && useradd --no-log-init -r -g appuser appuser
# golang环境编译 docker build -t dev.daymele.com:5000/res .
FROM golang:latest as build
ENV GO111MODULE on
ENV GOPROXY=https://goproxy.io
WORKDIR /
# 通过提前运行go mod download可以使用cache编译避免每次编译都下载加快编译速度
# RUN --mount=type=cache,target=/go/pkg/mod/ \
# --mount=type=bind,source=/go.sum,target=/go.sum \
# --mount=type=bind,source=/go.mod,target=/go.mod \
# go mod download -x
# COPY . .
# RUN --mount=type=cache,target=/go/pkg/mod/ \
# GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o /bin/cli -ldflags="-w -s"
COPY go.mod go.sum ./
RUN go mod download
ADD . /
RUN GOOS=linux CGO_ENABLED=0 go build -o adapt -ldflags="-w -s"
# 生成alpine部署容器
FROM scratch as client
FROM alpine:latest
LABEL MAINTAINER='LIU Peng<liupeng@daymele.com>'
WORKDIR /
# COPY --from=builder /bin/cli /cli
# COPY --from=builder /etc/passwd /etc/passwd
# COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# COPY --from=builder /bin/appmain /bin/appmain
# USER appuser
COPY ./cli /cli
# 健康检测 scratch 镜像没有其它shell指令所以无法进行健康检测
# ADD ./hc.sh /root/healthcheck.sh
# HEALTHCHECK --start-period=60s --interval=15s --timeout=5s --retries=3 CMD /bin/ash /root/healthcheck.sh
COPY --from=build /adapt /adapt
# 健康检测
ADD ./hc.sh /root/healthcheck.sh
HEALTHCHECK --start-period=60s --interval=15s --timeout=5s --retries=3 CMD /bin/ash /root/healthcheck.sh
# 时区处理(方法一:需要提前准备下两条scratch和alpine都可以使用)
# tar cfz zoneinfo.tar.gz /usr/share/zoneinfo
@ -39,7 +30,7 @@ ADD zoneinfo.tar.gz /
# && echo "Asia/Shanghai" > /etc/timezone \
# && apk del tzdata \
# && rm -rf /var/cache/apk/*
ENTRYPOINT ["/cli","-port","9000","-conf","/conf/daymele.conf"]
ENTRYPOINT ["/adapt","-port","9000","-conf","/conf/daymele.conf"]
EXPOSE 9000
# docker image prune 删除悬虚镜像

View File

@ -53,7 +53,7 @@ func Mkdir(basePath string) string {
}
func main() {
version := "1.0.2"
version := "1.0.0"
fmt.Printf("\n\n\n")
fmt.Printf(" **************************************************\n")
fmt.Printf(" * \033[1;34;42m豆曲咖资源|美团服务\033[0m *\n")
@ -124,7 +124,7 @@ func main() {
}
}()
// 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间)
quit := make(chan os.Signal, 1)
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
logger.Info("Shutdown Server ...")

2
go.mod
View File

@ -1,6 +1,6 @@
module res
go 1.22.0
go 1.21.0
require (
github.com/gin-gonic/gin v1.9.1