Browse Source

Drone build

Ask Bjørn Hansen 4 năm trước cách đây
mục cha
commit
1068cce156

+ 106 - 0
.drone.yml

@@ -0,0 +1,106 @@
+---
+kind: pipeline
+type: kubernetes
+name: default
+
+steps:
+  - name: fetch-tags
+    image: alpine/git
+    commands:
+      - git fetch --tags
+
+  - name: test
+    image: golang:1.16.7
+    volumes:
+      - name: cache
+        path: /go
+    commands:
+      - ./scripts/download-test-geoip
+      - go get
+      - go test -v ./...
+      - go build ./...
+
+  - name: goreleaser
+    image: golang:1.16.7
+    volumes:
+      - name: cache
+        path: /go
+    commands:
+      - ./scripts/run-goreleaser
+      - echo Done
+    when:
+      ref:
+        - refs/heads/main
+        - refs/heads/drone-test
+        - refs/tags/**
+    depends_on: [test]
+
+  - name: upload
+    image: plugins/s3
+    settings:
+      access_key:
+        from_secret: s3_access_key
+      secret_key:
+        from_secret: s3_secret_key
+      bucket: geodns
+      target: /builds/${DRONE_BUILD_NUMBER}
+      source: dist/*
+      strip_prefix: dist/
+      endpoint: https://minio-ewr1.develooper.com/
+      path_style: true
+    depends_on: [goreleaser]
+
+  - name: fury-publish
+    image: golang:1.16.7
+    environment:
+      FURY_TOKEN:
+        from_secret: fury_test_token
+    commands:
+      - ./scripts/fury-publish ntppool-test
+    when:
+      ref:
+        - refs/heads/main
+        - refs/heads/drone-test
+        - refs/tags/**
+    depends_on: [goreleaser]
+
+volumes:
+  - name: cache
+    temp: {}
+
+trigger:
+  event:
+    - push
+    - tag
+    - pull_request
+
+---
+kind: pipeline
+type: kubernetes
+name: publish-production
+
+steps:
+  - name: download
+    image: golang:1.16.7
+    commands:
+      - ./scripts/download-release ${DRONE_BUILD_PARENT} dist/
+
+  - name: fury-publish
+    image: golang:1.16.7
+    environment:
+      FURY_TOKEN:
+        from_secret: fury_token
+    commands:
+      - ./scripts/fury-publish ntppool
+    depends_on: ["download"]
+
+trigger:
+  event:
+    - promote
+  target:
+    - publish
+---
+kind: signature
+hmac: 687f4bc1dfa9b493fed2838a5033619ea1d5a8cc7b1133dc16db6489552ea896
+
+...

+ 84 - 0
.goreleaser.yml

@@ -0,0 +1,84 @@
+before:
+  hooks:
+    - go mod tidy
+    - go generate ./...
+builds:
+  - id: geodns
+    env:
+      - CGO_ENABLED=0
+    ldflags:
+      - -s -w
+      - -X main.VERSION={{.Version}}{{ if index .Env "DRONE_BUILD_NUMBER" }}-{{ .Env.DRONE_BUILD_NUMBER }}{{ end }}
+      - -X main.gitVersion={{.Commit}}
+      - -X main.buildTime={{.Date}}
+
+    goos:
+      - linux
+      - freebsd
+      - darwin
+    ignore:
+      - goos: darwin
+        goarch: 386
+      - goos: freebsd
+        goarch: 386
+      - goos: freebsd
+        goarch: arm64
+archives:
+  - replacements:
+      #darwin: Darwin
+      #linux: Linux
+      #windows: Windows
+      #386: i386
+      #amd64: x86_64
+checksum:
+  name_template: "checksums.txt"
+snapshot:
+  name_template: '{{ .Tag }}{{ if index .Env "DRONE_BUILD_NUMBER" }}-{{ .Env.DRONE_BUILD_NUMBER }}{{ end }}'
+changelog:
+  sort: asc
+  filters:
+    exclude:
+      - "^docs:"
+      - "^test:"
+
+nfpms:
+  - id: geodns
+
+    # Name of the package.
+    # Defaults to `ProjectName`.
+    package_name: geodns
+
+    # release: {{ if index .Env "DRONE_BUILD_NUMBER" }}{{ .Env.DRONE_BUILD_NUMBER }}{{ else }}1{{ end }}
+
+    # You can change the file name of the package.
+    # Default: `{{ .PackageName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
+    file_name_template: '{{ .ProjectName }}_{{ .Version }}{{ if index .Env "DRONE_BUILD_NUMBER" }}-{{ .Env.DRONE_BUILD_NUMBER }}{{ end }}._{{ .Os }}_{{ .Arch }}'
+
+    vendor: NTP Pool Project
+    homepage: https://www.ntppool.org/
+    maintainer: Ask Bjørn Hansen <[email protected]>
+    description: GeoDNS server
+    license: Apache 2.0
+    formats:
+      - deb
+      - rpm
+      - apk
+    replacements:
+      386: i686
+      amd64: x86_64
+    bindir: /usr/bin
+    contents:
+      - src: "scripts/geodns.service"
+        dst: "/etc/systemd/system/geodns.service"
+
+      - src: "scripts/defaults"
+        dst: "/etc/default/geodns.sample"
+        type: config
+
+    scripts:
+      postinstall: scripts/postinstall.sh
+
+    overrides:
+      rpm:
+        #file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Arch }}"
+        # {{ if index .Env "DRONE_BUILD_NUMBER" }}-{{ .Env.DRONE_BUILD_NUMBER }}{{ end }}

+ 9 - 0
scripts/defaults

@@ -0,0 +1,9 @@
+beta4_key=
+beta6_key=
+beta4_url=https://www.beta.grundclock.com/monitor
+beta6_url=https://www.beta.grundclock.com/monitor
+
+prod4_key=
+prod6_key=
+prod4_url=https://api.ntppool.org/monitor
+prod6_url=https://api.ntppool.org/monitor

+ 23 - 0
scripts/download-release

@@ -0,0 +1,23 @@
+#!/bin/bash
+
+BUILD=$1
+DIR=$2
+
+set -euo pipefail
+
+if [ -z "$DIR" ]; then
+  echo run with $0 BUILD_NUMBER DIR
+  exit 2
+fi
+
+mkdir -p $DIR
+
+BASE=https://geodns.bitnames.com/builds/$BUILD
+
+files=`curl -sf $BASE/checksums.txt | awk '{print $2}'`
+
+for f in $files; do
+  url=$BASE/$f
+  echo downloading $f
+  curl -fRo $DIR/$f $url
+done

+ 15 - 0
scripts/download-test-geoip

@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -euo pipefail
+
+DIR=/usr/local/share/GeoIP
+
+mkdir -p $DIR
+
+for f in GeoLite2-ASN.mmdb GeoLite2-City.mmdb GeoLite2-Country.mmdb; do
+    Z=""
+    if [ -e $DIR/$f ]; then
+        Z="-z $DIR/$f"
+    fi
+    curl $Z -sfo $DIR/$f https://geodns.bitnames.com/geoip/$f
+done

+ 15 - 0
scripts/fury-publish

@@ -0,0 +1,15 @@
+#!/bin/bash
+
+account=$1
+
+set -euo pipefail
+
+if [ -z "$account" ]; then
+  echo specify account as the first parameter
+  exit 2
+fi
+
+for f in dist/*.rpm dist/*.deb; do
+  echo Uploading $f
+  curl -sf -F package=@$f https://${FURY_TOKEN}@push.fury.io/${account}/
+done

+ 13 - 0
scripts/geodns.service

@@ -0,0 +1,13 @@
+[Unit]
+Description=GeoDNS server
+
+[Service]
+Type=simple
+EnvironmentFile=-/etc/default/geodns
+ExecStart=/usr/bin/geodns
+Restart=always
+TimeoutStartSec=10
+RestartSec=10
+
+[Install]
+WantedBy=multi-user.target

+ 2 - 0
scripts/postinstall.sh

@@ -0,0 +1,2 @@
+#!/bin/sh
+systemctl daemon-reload

+ 13 - 0
scripts/run-goreleaser

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -euo pipefail
+
+DRONE_TAG=${DRONE_TAG-""}
+
+is_snapshot=""
+
+if [ -z "$DRONE_TAG" ]; then
+  is_snapshot="--snapshot"
+fi
+
+curl -fsL https://git.io/goreleaser | bash -s -- release --snapshot