init
parent
d4824078b2
commit
c3b7d531e9
|
@ -0,0 +1,51 @@
|
|||
kind: pipeline
|
||||
type: docker
|
||||
name: 部署drone_plugin
|
||||
|
||||
clone:
|
||||
disable: true
|
||||
|
||||
steps:
|
||||
- name: clone
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git clone ${DRONE_REMOTE_URL} .
|
||||
- git checkout $DRONE_COMMIT
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
|
||||
- name: build
|
||||
image: plugins/docker
|
||||
volumes:
|
||||
- name: docker
|
||||
path: /var/run/docker.sock
|
||||
settings:
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
from_secret: reg_password
|
||||
repo: reg.icechen.cn/pkg/drone_plugin
|
||||
registry: reg.icechen.cn
|
||||
tags: ${DRONE_COMMIT:0:8}
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
|
||||
- name: run
|
||||
image: docker/compose
|
||||
volumes:
|
||||
- name: docker
|
||||
path: /var/run/docker.sock
|
||||
commands:
|
||||
- export TAG=${DRONE_COMMIT:0:8}
|
||||
- docker-compose -p drone_plugin down
|
||||
- docker-compose -p drone_plugin up -d
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
|
||||
volumes:
|
||||
- name: docker
|
||||
host:
|
||||
path: /var/run/docker.sock
|
|
@ -0,0 +1,24 @@
|
|||
FROM golang:1.17 as builder
|
||||
ENV GO111MODULE on
|
||||
ENV GOPROXY https://goproxy.io,direct
|
||||
WORKDIR /go/cache
|
||||
ADD go.mod .
|
||||
ADD go.sum .
|
||||
RUN go mod download
|
||||
WORKDIR /go/src
|
||||
ADD . .
|
||||
RUN go mod tidy
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o main
|
||||
|
||||
FROM alpine as drone_plugin
|
||||
WORKDIR /go/src
|
||||
#LABEL maintainer "The Prometheus Authors <prometheus-developers@googlegroups.com>"
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
# copy main and config from builder
|
||||
COPY --from=builder /go/src/main ./
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV DRONE_DEBUG=true
|
||||
ENV DRONE_SECRET=6dc7224d3e415d2d45b55eb04a7d2e9e
|
||||
RUN chmod +x ./main
|
||||
EXPOSE 8080
|
||||
CMD ["./main"]
|
|
@ -0,0 +1,16 @@
|
|||
version: '3'
|
||||
|
||||
networks:
|
||||
nginx-net:
|
||||
external:
|
||||
name: nginx-net
|
||||
services:
|
||||
zeus-api:
|
||||
image: reg.icechen.cn/pkg/drone_plugin:${TAG}
|
||||
container_name: drone_plugin
|
||||
labels:
|
||||
io.portainer.accesscontrol.teams: admin
|
||||
ports:
|
||||
- "3000:3000"
|
||||
networks:
|
||||
- nginx-net
|
|
@ -0,0 +1,23 @@
|
|||
package go_coverter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/drone-go/plugin/converter"
|
||||
)
|
||||
|
||||
// New returns a new conversion plugin.
|
||||
func New() converter.Plugin {
|
||||
return &plugin{}
|
||||
}
|
||||
|
||||
type plugin struct{}
|
||||
|
||||
func (p *plugin) Convert(ctx context.Context, req *converter.Request) (*drone.Config, error) {
|
||||
fmt.Printf("%+v", *req)
|
||||
return &drone.Config{
|
||||
Data: req.Config.Data,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"git.icechen.cn/pkg/drone_plugin/go_coverter"
|
||||
"github.com/drone/drone-go/plugin/converter"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
// spec provides the plugin settings.
|
||||
type spec struct {
|
||||
Bind string `envconfig:"DRONE_BIND"`
|
||||
Debug bool `envconfig:"DRONE_DEBUG"`
|
||||
Secret string `envconfig:"DRONE_SECRET"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
spec := new(spec)
|
||||
err := envconfig.Process("", spec)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if spec.Debug {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
if spec.Secret == "" {
|
||||
logrus.Fatalln("missing secret key")
|
||||
}
|
||||
if spec.Bind == "" {
|
||||
spec.Bind = ":3000"
|
||||
}
|
||||
|
||||
handler := converter.Handler(
|
||||
go_coverter.New(),
|
||||
spec.Secret,
|
||||
logrus.StandardLogger(),
|
||||
)
|
||||
|
||||
logrus.Infof("server listening on address %s", spec.Bind)
|
||||
|
||||
http.Handle("/", handler)
|
||||
logrus.Fatal(http.ListenAndServe(spec.Bind, nil))
|
||||
}
|
Loading…
Reference in New Issue