Skip to content

Commit e1c7e6f

Browse files
author
CodingWizKid
committed
add build files
1 parent 318b7c7 commit e1c7e6f

File tree

10 files changed

+611
-98
lines changed

10 files changed

+611
-98
lines changed

.bin/external-dns-stackit-webhook

30.2 MB
Binary file not shown.

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ go.work
2525

2626
# test
2727
out/
28+
bin/
29+
reports/
30+
dist/

.goreleaser.yml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
project_name: external-dns-stackit-webhook
2+
release:
3+
github:
4+
owner: stackitcloud
5+
name: external-dns-stackit-webhook
6+
name_template: '{{.Tag}}'
7+
builds:
8+
- id: external-dns-stackit-webhook
9+
goos:
10+
- linux
11+
- darwin
12+
goarch:
13+
- amd64
14+
- arm64
15+
goarm:
16+
- "6"
17+
gomips:
18+
- hardfloat
19+
goamd64:
20+
- v1
21+
targets:
22+
- linux_amd64_v1
23+
- linux_arm64
24+
- darwin_amd64_v1
25+
- darwin_arm64
26+
dir: .
27+
main: ./cmd/webhook
28+
binary: external-dns-stackit-webhook
29+
builder: go
30+
gobinary: go
31+
command: build
32+
env:
33+
- CGO_ENABLED=0
34+
ldflags:
35+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
36+
archives:
37+
- id: default
38+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
39+
format: tar.gz
40+
files:
41+
- src: license*
42+
- src: LICENSE*
43+
- src: readme*
44+
- src: README*
45+
- src: changelog*
46+
- src: CHANGELOG*
47+
snapshot:
48+
name_template: '{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}'
49+
checksum:
50+
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
51+
algorithm: sha256
52+
dist: dist
53+
env_files:
54+
github_token: ~/.config/goreleaser/github_token
55+
gitlab_token: ~/.config/goreleaser/gitlab_token
56+
gitea_token: ~/.config/goreleaser/gitea_token
57+
source:
58+
name_template: '{{ .ProjectName }}-{{ .Version }}'
59+
format: tar.gz
60+
gomod:
61+
gobinary: go
62+
announce:
63+
twitter:
64+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
65+
mastodon:
66+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
67+
server: ""
68+
reddit:
69+
title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
70+
url_template: '{{ .ReleaseURL }}'
71+
slack:
72+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
73+
username: GoReleaser
74+
discord:
75+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
76+
author: GoReleaser
77+
color: "3888754"
78+
icon_url: https://goreleaser.com/static/avatar.png
79+
teams:
80+
title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
81+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
82+
color: '#2D313E'
83+
icon_url: https://goreleaser.com/static/avatar.png
84+
smtp:
85+
subject_template: '{{ .ProjectName }} {{ .Tag }} is out!'
86+
body_template: 'You can view details from: {{ .ReleaseURL }}'
87+
mattermost:
88+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
89+
title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
90+
username: GoReleaser
91+
linkedin:
92+
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
93+
telegram:
94+
message_template: '{{ .ProjectName }} {{ mdv2escape .Tag }} is out! Check it out at {{ mdv2escape .ReleaseURL }}'
95+
parse_mode: MarkdownV2
96+
webhook:
97+
message_template: '{ "message": "{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}"}'
98+
content_type: application/json; charset=utf-8
99+
opencollective:
100+
title_template: '{{ .Tag }}'
101+
message_template: '{{ .ProjectName }} {{ .Tag }} is out!<br/>Check it out at <a href="{{ .ReleaseURL }}">{{ .ReleaseURL }}</a>'
102+
git:
103+
tag_sort: -version:refname
104+
github_urls:
105+
download: https://github.com
106+
gitlab_urls:
107+
download: https://gitlab.com

Makefile

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
GOLANGCI_VERSION = 1.53.3
2+
LICENCES_IGNORE_LIST = $(shell cat licenses/licenses-ignore-list.txt)
3+
4+
VERSION ?= 0.0.1
5+
IMAGE_TAG_BASE ?= stackitcloud/external-dns-stackit-webhook
6+
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
7+
8+
BUILD_VERSION ?= $(shell git branch --show-current)
9+
BUILD_COMMIT ?= $(shell git rev-parse --short HEAD)
10+
BUILD_TIMESTAMP ?= $(shell date -u '+%Y-%m-%d %H:%M:%S')
11+
12+
GOLDFLAGS += -X 'stackitcloud/external-dns-stackit-webhook/internal/version.buildVersion=$(BUILD_VERSION)'
13+
GOLDFLAGS += -X 'stackitcloud/external-dns-stackit-webhook/version.buildCommit=$(BUILD_COMMIT)'
14+
GOLDFLAGS += -X 'stackitcloud/external-dns-stackit-webhook/internal/version.buildTimestamp=$(BUILD_TIMESTAMP)'
15+
16+
PWD = $(shell pwd)
17+
export PATH := $(PWD)/bin:$(PATH)
18+
19+
download:
20+
go mod download
21+
22+
.PHONY: build
23+
build:
24+
CGO_ENABLED=0 go build -ldflags "$(GOLDFLAGS)" -o ./bin/external-dns-stackit-webhook -v cmd/webhook/main.go
25+
26+
.PHONY: build-amd64
27+
build-amd64:
28+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "$(GOLDFLAGS)" -o ./bin/external-dns-stackit-webhook -v cmd/webhook/main.go
29+
30+
.PHONY: docker-build
31+
docker-build:
32+
docker build -t $(IMG) -f build/Dockerfile .
33+
34+
test:
35+
go test -race ./...
36+
37+
mocks:
38+
go generate ./...
39+
40+
GOLANGCI_LINT = bin/golangci-lint-$(GOLANGCI_VERSION)
41+
$(GOLANGCI_LINT):
42+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b bin v$(GOLANGCI_VERSION)
43+
@mv bin/golangci-lint "$(@)"
44+
45+
lint: $(GOLANGCI_LINT) download
46+
$(GOLANGCI_LINT) run -v
47+
48+
out:
49+
@mkdir -pv "$(@)"
50+
51+
reports:
52+
@mkdir -pv "$(@)/licenses"
53+
54+
coverage: out
55+
go test -race ./... -coverprofile=out/cover.out
56+
57+
html-coverage: out/report.json
58+
go tool cover -html=out/cover.out
59+
60+
.PHONY: out/report.json
61+
out/report.json:
62+
go test -race ./... -coverprofile=out/cover.out --json | tee "$(@)"
63+
64+
run:
65+
go run cmd/webhook
66+
67+
.PHONY: clean
68+
clean:
69+
rm -rf ./bin
70+
rm -rf ./out
71+
72+
GO_RELEASER = bin/goreleaser
73+
$(GO_RELEASER):
74+
GOBIN=$(PWD)/bin go install github.com/goreleaser/goreleaser@latest
75+
76+
.PHONY: release-check
77+
release-check: $(GO_RELEASER) ## Check if the release will work
78+
GITHUB_SERVER_URL=github.com GITHUB_REPOSITORY=stackitcloud/external-dns-stackit-webhook REGISTRY=$(REGISTRY) IMAGE_NAME=$(IMAGE_NAME) $(GO_RELEASER) release --snapshot --clean --skip-publish
79+
80+
GO_LICENSES = bin/go-licenses
81+
$(GO_LICENSES):
82+
GOBIN=$(PWD)/bin go install github.com/google/go-licenses
83+
84+
.PHONY: license-check
85+
license-check: $(GO_LICENSES) reports ## Check licenses against code.
86+
$(GO_LICENSES) check --include_tests --ignore $(LICENCES_IGNORE_LIST) ./...
87+
88+
.PHONY: license-report
89+
license-report: $(GO_LICENSES) reports ## Create licenses report against code.
90+
$(GO_LICENSES) report --include_tests --ignore $(LICENCES_IGNORE_LIST) ./... > ./reports/licenses/licenses-list.csv

build/Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM golang:1.20 as buildstage
2+
3+
# ca-certificates: for downloading go libraries from the internet
4+
# build-essential: for building our project (make)
5+
# curl: for downloading third party tools
6+
RUN apt-get update && \
7+
apt-get install --yes --no-install-recommends ca-certificates build-essential curl && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /build
11+
COPY . .
12+
13+
RUN make build-amd64
14+
15+
FROM gcr.io/distroless/static-debian11
16+
17+
COPY --from=buildstage /build/bin/external-dns-stackit-webhook /external-dns-stackit-webhook
18+
19+
ENTRYPOINT ["/external-dns-stackit-webhook"]

cmd/webhook/cmd/root.go

+14-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"log"
66
"net/http"
7-
"regexp"
87
"strings"
98
"time"
109

@@ -19,22 +18,23 @@ import (
1918
)
2019

2120
var (
22-
apiPort string
23-
authBearerToken string
24-
baseUrl string
25-
projectID string
26-
worker int
27-
domainFilter []string
28-
domainExclude []string
29-
domainRegex string
30-
domainRegexExclusion string
21+
apiPort string
22+
authBearerToken string
23+
baseUrl string
24+
projectID string
25+
worker int
26+
domainFilter []string
3127
)
3228

3329
var rootCmd = &cobra.Command{
3430
Use: "external-dns-stackit-webhook",
3531
Short: "provider webhook for the STACKIT DNS service",
3632
Long: "provider webhook for the STACKIT DNS service",
3733
Run: func(cmd *cobra.Command, args []string) {
34+
if len(authBearerToken) == 0 {
35+
panic("auth-token is required")
36+
}
37+
3838
logger, errLogger := zap.NewProduction()
3939
if errLogger != nil {
4040
panic(errLogger)
@@ -46,13 +46,7 @@ var rootCmd = &cobra.Command{
4646
}
4747
}(logger)
4848

49-
endpointDomainFilter := endpoint.DomainFilter{}
50-
if domainRegex != "" {
51-
endpointDomainFilter = endpoint.NewRegexDomainFilter(regexp.MustCompile(domainRegex), regexp.MustCompile(domainRegexExclusion))
52-
} else {
53-
endpointDomainFilter.Filters = domainFilter
54-
endpointDomainFilter = endpoint.NewDomainFilterWithExclusions(endpointDomainFilter.Filters, domainExclude)
55-
}
49+
endpointDomainFilter := endpoint.DomainFilter{Filters: domainFilter}
5650

5751
stackitProvider, err := stackitprovider.NewStackitDNSProvider(stackitprovider.Config{
5852
BasePath: baseUrl,
@@ -84,16 +78,13 @@ func init() {
8478
cobra.OnInitialize(initConfig)
8579

8680
rootCmd.PersistentFlags().StringVar(&apiPort, "api-port", "8888", "Port to listen on for the API")
87-
rootCmd.PersistentFlags().StringVar(&authBearerToken, "auth-bearer-token", "", "Bearer token to use for authentication")
88-
rootCmd.PersistentFlags().StringVar(&baseUrl, "base-url", "http://localhost:3000", "Base URL to use for the API")
81+
rootCmd.PersistentFlags().StringVar(&authBearerToken, "auth-token", "", "Bearer token to use for authentication")
82+
rootCmd.PersistentFlags().StringVar(&baseUrl, "base-url", "https://dns.api.stackit.cloud", "Base URL to use for the API")
8983
rootCmd.PersistentFlags().StringVar(&projectID, "project-id", "", "Project to use for the API")
9084
rootCmd.PersistentFlags().IntVar(&worker, "worker", 10, "Number of workers to use for querying the API. "+
9185
"Since we have to iterate over all zones and records we can parallelize it. But keep in mind to not set it too high "+
9286
"since you will receive 429 rate limiting from the API")
93-
rootCmd.PersistentFlags().StringArrayVar(&domainFilter, "domain-filter", []string{}, "Filter to apply to DNS records. Only this filter or the domain regex filter can be used at the same time")
94-
rootCmd.PersistentFlags().StringArrayVar(&domainExclude, "exclude-domain-filter", []string{}, "Filter to exclude DNS records")
95-
rootCmd.PersistentFlags().StringVar(&domainRegex, "domain-regex-filter", "", "Regex to apply to DNS records. Only this filter or the domain filter can be used at the same time")
96-
rootCmd.PersistentFlags().StringVar(&domainRegexExclusion, "exclude-domain-regex-filter", "", "Regex to exclude DNS records")
87+
rootCmd.PersistentFlags().StringArrayVar(&domainFilter, "domain-filter", []string{}, "Filter to filter dns zone names")
9788
}
9889

9990
func initConfig() {

0 commit comments

Comments
 (0)