feat: drone ci
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Vaala Cat 2023-12-06 21:47:12 +08:00
parent 511c96c57e
commit a42fecfc63
2 changed files with 125 additions and 10 deletions

116
.drone.yml Normal file
View File

@ -0,0 +1,116 @@
kind: pipeline
name: build-and-publish
steps:
- name: download modules
image: git.vaala.cloud/vaalacat/golang:1.20.0-alpine3.17
commands:
- sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
- apk update --no-cache && apk add --no-cache tzdata git
- GOPRIVATE=git.vaala.cloud CGO_ENABLED=0 GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct go mod download
- mkdir -p etc
- cp /etc/ssl/certs/ca-certificates.crt ./etc/ca-certificates.crt
- cp /usr/share/zoneinfo/Asia/Shanghai ./etc/Shanghai
volumes:
- name: gocache
path: /go/pkg/mod
- name: build
path: /tmp/app
when:
event:
- pull_request
- promote
- rollback
- name: build - amd64
image: git.vaala.cloud/vaalacat/golang:1.20.0-alpine3.17
commands:
- GOOS=linux GOARCH=amd64 GOPRIVATE=git.vaala.cloud CGO_ENABLED=0 GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct go build -ldflags="-s -w" -o mcbot-amd64 main.go
volumes:
- name: gocache
path: /go/pkg/mod
- name: build
path: /tmp/app
depends_on:
- download modules
when:
event:
- pull_request
- promote
- rollback
- name: build - arm64
image: git.vaala.cloud/vaalacat/golang:1.20.0-alpine3.17
commands:
- GOOS=linux GOARCH=arm64 GOPRIVATE=git.vaala.cloud CGO_ENABLED=0 GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct go build -ldflags="-s -w" -o mcbot-arm64 main.go
volumes:
- name: gocache
path: /go/pkg/mod
- name: build
path: /tmp/app
depends_on:
- download modules
when:
event:
- pull_request
- promote
- rollback
- name: publish - amd64
image: git.vaala.cloud/vaalacat/drone-docker-buildx:24
privileged: true
settings:
mirror: https://dockerproxy.com
debug: true
platforms:
- linux/amd64
build_args:
- ARCH=amd64
repo: git.vaala.cloud/vaalacat/mcbot
tags:
- amd64
registry:
from_secret: docker_registry
username:
from_secret: docker_username
password:
from_secret: docker_password
depends_on:
- build - amd64
when:
event:
- promote
- rollback
target:
- production
- name: publish - arm64
image: git.vaala.cloud/vaalacat/drone-docker-buildx:24
privileged: true
settings:
mirror: https://dockerproxy.com
debug: true
platforms:
- linux/arm64
build_args:
- ARCH=arm64
repo: git.vaala.cloud/vaalacat/mcbot
tags:
- arm64
registry:
from_secret: docker_registry
username:
from_secret: docker_username
password:
from_secret: docker_password
depends_on:
- build - arm64
when:
event:
- promote
- rollback
target:
- production
volumes:
- name: build
temp: {}
- name: gocache
host:
path: /tmp/drone/mcbot/gocache

View File

@ -1,12 +1,11 @@
FROM git.vaala.cloud/vaalacat/golang:1.20 AS builder
# WORKDIR $GOPATH/src/mcbot
# COPY . .
# RUN mkdir /app && \
# CGO_ENABLED=0 GOPROXY=https://goproxy.cn,direct go build -o mcbot main.go && \
# cp mcbot /app/
FROM git.vaala.cloud/vaalacat/alpine
# COPY --from=builder /app/mcbot /app/mcbot
COPY mcbot /app/mcbot
ARG ARCH
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
apk update --no-cache && apk --no-cache add curl
WORKDIR /app
COPY mcbot-${ARCH} /app/mcbot
ENTRYPOINT [ "/app/mcbot" ]