This commit is contained in:
parent
9a4b2afb8f
commit
ac04817346
98
.gitea/workflows/deploy.yaml
Normal file
98
.gitea/workflows/deploy.yaml
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- release/*
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- release/*
|
||||||
|
|
||||||
|
env:
|
||||||
|
APP_NAME: "dnspod-watch"
|
||||||
|
NAMESPACE: app
|
||||||
|
REGISTRY: ${{ secrets.DOCKER_REGISTRY && secrets.DOCKER_REGISTRY || 'docker.io' }}
|
||||||
|
REPOSITORY: "codfrm/dnspod-watch"
|
||||||
|
GOPROXY: ${{ secrets.GOPROXY && secrets.GOPROXY || 'https://goproxy.cn,direct' }}
|
||||||
|
RUNNER_TOOL_CACHE: /toolcache
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4.2.0
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
# uses: golangci/golangci-lint-action@v3
|
||||||
|
uses: actions/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
install-mode: goinstall
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: |
|
||||||
|
go test $(go list ./...)
|
||||||
|
|
||||||
|
- name: Build binary file
|
||||||
|
run: |
|
||||||
|
CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -o ${{ env.APP_NAME }} ./cmd/app
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
# uses: docker/setup-qemu-action@v3
|
||||||
|
uses: actions/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
# uses: docker/setup-buildx-action@v3
|
||||||
|
uses: actions/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
# uses: docker/login-action@v3
|
||||||
|
uses: actions/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set outputs
|
||||||
|
id: vars
|
||||||
|
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Docker build and push
|
||||||
|
# use: docker/build-push-action@v5
|
||||||
|
uses: actions/build-push-action@v5
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
file: deploy/docker/Dockerfile
|
||||||
|
tags: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ steps.vars.outputs.sha_short }}
|
||||||
|
context: .
|
||||||
|
build-args: |
|
||||||
|
APP_NAME=${{ env.APP_NAME }}
|
||||||
|
|
||||||
|
- name: Set up kubeconfig
|
||||||
|
# uses: azure/k8s-set-context@v3
|
||||||
|
uses: actions/k8s-set-context@v3
|
||||||
|
with:
|
||||||
|
method: kubeconfig
|
||||||
|
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
context: k8s-context
|
||||||
|
|
||||||
|
- name: Set up Helm
|
||||||
|
# uses: azure/setup-helm@v3
|
||||||
|
uses: actions/setup-helm@v3.6
|
||||||
|
with:
|
||||||
|
version: 'v3.13.1' # default is latest (stable)
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
run: |
|
||||||
|
cd deploy/helm
|
||||||
|
helm upgrade --install --namespace $NAMESPACE $APP_NAME . \
|
||||||
|
--set image.tag=${{ steps.vars.outputs.sha_short }} --set image.repository=${{ env.REGISTRY }}/${{ env.REPOSITORY }} \
|
||||||
|
--set etcdConfig.password=${{ secrets.ETCD_CONFIG_PASSWORD }}
|
40
.gitea/workflows/test.yaml
Normal file
40
.gitea/workflows/test.yaml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
name: Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- !main
|
||||||
|
- !release/*
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- !main
|
||||||
|
- !release/*
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPROXY: ${{ secrets.GOPROXY && secrets.GOPROXY || 'https://goproxy.cn,direct' }}
|
||||||
|
RUNNER_TOOL_CACHE: /toolcache
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4.2.0
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
# uses: golangci/golangci-lint-action@v3
|
||||||
|
uses: actions/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
install-mode: goinstall
|
||||||
|
|
||||||
|
- name: Tests
|
||||||
|
run: |
|
||||||
|
go test $(go list ./...)
|
||||||
|
|
@ -1,80 +0,0 @@
|
|||||||
variables:
|
|
||||||
APP_NAME: "dnspod-watch"
|
|
||||||
APP_VERSION: 1.0.0
|
|
||||||
NAMESPACE: app
|
|
||||||
REGISTRY: "docker.io"
|
|
||||||
REPOSITORY: "app/dnspod-watch"
|
|
||||||
GO111MODULE: "on"
|
|
||||||
GOPROXY: "https://goproxy.cn,direct"
|
|
||||||
GOPATH: "$CI_PROJECT_DIR/.cache"
|
|
||||||
GOLANGCI_LINT_CACHE: "$CI_PROJECT_DIR/.lint-cache"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- build
|
|
||||||
- docker
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
test-job:
|
|
||||||
stage: test
|
|
||||||
image: golang:1.19
|
|
||||||
cache:
|
|
||||||
key: go-cache
|
|
||||||
paths:
|
|
||||||
- .cache
|
|
||||||
script:
|
|
||||||
- go test -v ./...
|
|
||||||
|
|
||||||
lint-job:
|
|
||||||
stage: test
|
|
||||||
image: golangci/golangci-lint:v1.52
|
|
||||||
cache:
|
|
||||||
key: lint-cache
|
|
||||||
paths:
|
|
||||||
- .lint-cache
|
|
||||||
script:
|
|
||||||
- golangci-lint run
|
|
||||||
|
|
||||||
build:
|
|
||||||
stage: build
|
|
||||||
image: golang:1.19-alpine3.16
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\/.*$/
|
|
||||||
cache:
|
|
||||||
key: go-cache
|
|
||||||
paths:
|
|
||||||
- .cache
|
|
||||||
script:
|
|
||||||
- CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -o $APP_NAME ./cmd/app
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- $APP_NAME
|
|
||||||
|
|
||||||
build-docker:
|
|
||||||
stage: docker
|
|
||||||
image: docker:rc
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\/.*$/
|
|
||||||
variables:
|
|
||||||
DOCKER_HOST: tcp://docker-dind:2375
|
|
||||||
before_script:
|
|
||||||
- docker login $REGISTRY --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
|
|
||||||
|
|
||||||
script:
|
|
||||||
- docker build . --build-arg APP_NAME=$APP_NAME -f deploy/docker/Dockerfile -t $REGISTRY/$REPOSITORY:$CI_COMMIT_SHORT_SHA
|
|
||||||
- docker push $REGISTRY/$REPOSITORY:$CI_COMMIT_SHORT_SHA
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
stage: deploy
|
|
||||||
image: alpine/helm:3.9.0
|
|
||||||
rules:
|
|
||||||
- if: $CI_COMMIT_BRANCH == "main"
|
|
||||||
script:
|
|
||||||
- cd deploy/helm
|
|
||||||
- |
|
|
||||||
helm upgrade --install --namespace $NAMESPACE $APP_NAME . \
|
|
||||||
--set image.tag=$CI_COMMIT_SHORT_SHA --set image.repository=$REGISTRY/$REPOSITORY \
|
|
||||||
--set etcdConfig.password=$ETCD_CONFIG_PASSWORD
|
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
@ -6,7 +6,7 @@ endif
|
|||||||
|
|
||||||
check-golangci-lint:
|
check-golangci-lint:
|
||||||
ifneq ($(which golangci-lint),)
|
ifneq ($(which golangci-lint),)
|
||||||
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||||
endif
|
endif
|
||||||
|
|
||||||
lint: check-golangci-lint
|
lint: check-golangci-lint
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
FROM alpine:3.16
|
FROM debian:12-slim
|
||||||
|
|
||||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
|
||||||
|
|
||||||
RUN apk update && apk add tzdata
|
|
||||||
|
|
||||||
ARG APP_NAME=cago
|
ARG APP_NAME=cago
|
||||||
|
|
||||||
ENV APP_NAME=$APP_NAME
|
ENV TZ=Asia/Shanghai \
|
||||||
|
APP_NAME=$APP_NAME
|
||||||
|
|
||||||
|
# 国内镜像
|
||||||
|
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources
|
||||||
|
|
||||||
|
# 安装证书
|
||||||
|
RUN apt update && \
|
||||||
|
apt install -y ca-certificates && \
|
||||||
|
update-ca-certificates
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ func (r *record) watch(ctx context.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
r.logger.Ctx(ctx).Error("check ip err", zap.Error(err))
|
r.logger.Ctx(ctx).Error("check ip err", zap.Error(err))
|
||||||
} else {
|
} else {
|
||||||
r.logger.Ctx(ctx).Info("check ip ok", zap.Duration("duration", duration))
|
r.logger.Ctx(ctx).Info("check ip ok",
|
||||||
|
zap.String("duration", fmt.Sprintf("%dms", duration.Milliseconds())))
|
||||||
}
|
}
|
||||||
_ = s.check(err == nil, func() error {
|
_ = s.check(err == nil, func() error {
|
||||||
// 增加负载均衡
|
// 增加负载均衡
|
||||||
|
Loading…
x
Reference in New Issue
Block a user