update: push to dockerhub
This commit is contained in:
parent
e96237b694
commit
1cbf8e8d4f
36
Dockerfile
Normal file
36
Dockerfile
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
FROM golang:1.18.2
|
||||||
|
|
||||||
|
WORKDIR /gogs_auto_deploy
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN go build
|
||||||
|
|
||||||
|
FROM python:3.7
|
||||||
|
|
||||||
|
LABEL maintainer="zhaoyingbo@live.cn"
|
||||||
|
|
||||||
|
EXPOSE 3001
|
||||||
|
|
||||||
|
WORKDIR /gogs_auto_deploy
|
||||||
|
|
||||||
|
ENV GOGS_REPOSITORY '/gogs_auto_deploy/repository/'
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=5s --timeout=3s \
|
||||||
|
CMD curl -fs http://0.0.0.0:3001/health || exit 1
|
||||||
|
|
||||||
|
RUN echo "[]" > config.json
|
||||||
|
|
||||||
|
RUN mkdir .log
|
||||||
|
|
||||||
|
RUN mkdir repository
|
||||||
|
|
||||||
|
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
|
||||||
|
&& sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
|
||||||
|
&& apt-get update && apt-get install -y --no-install-recommends procps wget vim curl \
|
||||||
|
&& apt-get install -y --no-install-recommends libsm6 libxrender1 libxext-dev libglib2.0-dev \
|
||||||
|
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||||
|
|
||||||
|
COPY --from=0 /gogs_auto_deploy/gogs_auto_deploy gogs_auto_deploy
|
||||||
|
|
||||||
|
CMD /bin/bash -c /gogs_auto_deploy/gogs_auto_deploy
|
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
version: '3.3'
|
||||||
|
services:
|
||||||
|
gogs_auto_deploy:
|
||||||
|
image: zhaoyingbo/gogs_auto_deploy:1.0.0
|
||||||
|
container_name: gogs_auto_deploy
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Shanghai # 时区
|
||||||
|
ports:
|
||||||
|
- "3001:3001"
|
||||||
|
volumes:
|
||||||
|
- ~/.ssh:/root/.ssh
|
||||||
|
- /usr/bin/docker:/usr/bin/docker
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
user: root
|
||||||
|
restart: always
|
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
|||||||
module git.lolli.tech/lollipopkit/gogs-webhook
|
module git.lacus.site/RainSun/gogs_auto_deploy
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
25
main.go
25
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
path = "/"
|
path = "/"
|
||||||
|
healthCheckPath = "/health"
|
||||||
logDir = ".log/"
|
logDir = ".log/"
|
||||||
perm = 0770
|
perm = 0770
|
||||||
)
|
)
|
||||||
@ -24,7 +26,12 @@ const (
|
|||||||
var (
|
var (
|
||||||
configs = []Config{}
|
configs = []Config{}
|
||||||
configsLock = &sync.RWMutex{}
|
configsLock = &sync.RWMutex{}
|
||||||
home = os.Getenv("HOME") + "/"
|
repositoryPath = func () string {
|
||||||
|
if os.Getenv("GOGS_REPOSITORY") != "" {
|
||||||
|
return os.Getenv("GOGS_REPOSITORY")
|
||||||
|
}
|
||||||
|
return os.Getenv("HOME") + "/repository/"
|
||||||
|
}()
|
||||||
logFile *os.File
|
logFile *os.File
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +46,12 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.SetOutput(logFile)
|
if os.Getenv("GOGS_REPOSITORY") != "" {
|
||||||
|
mw := io.MultiWriter(os.Stdout,logFile)
|
||||||
|
log.SetOutput(mw)
|
||||||
|
} else {
|
||||||
|
log.SetOutput(logFile)
|
||||||
|
}
|
||||||
time.Sleep(time.Minute)
|
time.Sleep(time.Minute)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -141,7 +153,7 @@ func checkNeedDeploy(payload GogsPayload) (Config, bool) {
|
|||||||
// 我们这个系统简单点,只要本次提交包含了部署信号,就直接部署最后一个commit
|
// 我们这个系统简单点,只要本次提交包含了部署信号,就直接部署最后一个commit
|
||||||
config := Config{
|
config := Config{
|
||||||
Repo: "",
|
Repo: "",
|
||||||
Path: home,
|
Path: repositoryPath,
|
||||||
Script: "deploy.py",
|
Script: "deploy.py",
|
||||||
Signal: "{D}",
|
Signal: "{D}",
|
||||||
Branch: "",
|
Branch: "",
|
||||||
@ -189,6 +201,11 @@ func main() {
|
|||||||
addr := flag.String("a", ":3001", "Address to listen on")
|
addr := flag.String("a", ":3001", "Address to listen on")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
http.HandleFunc(healthCheckPath, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Write([]byte("I'm alive"))
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 获取请求体
|
// 获取请求体
|
||||||
reqBody, err := ioutil.ReadAll(r.Body)
|
reqBody, err := ioutil.ReadAll(r.Body)
|
||||||
@ -230,7 +247,7 @@ func main() {
|
|||||||
if hasPrefix {
|
if hasPrefix {
|
||||||
base = deployConfig.Path
|
base = deployConfig.Path
|
||||||
} else {
|
} else {
|
||||||
base = home + deployConfig.Path
|
base = repositoryPath + deployConfig.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
repoFmt := ""
|
repoFmt := ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user