diff --git a/.github/workflows/main.yml b/.github/workflows/ci.yml similarity index 66% rename from .github/workflows/main.yml rename to .github/workflows/ci.yml index 8475e50..cd1e916 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/ci.yml @@ -4,8 +4,6 @@ on: push: branches: - master - tags: - - v* pull_request: jobs: @@ -14,8 +12,8 @@ jobs: name: Main Process runs-on: ubuntu-latest env: - GO_VERSION: 1.16 - GOLANGCI_LINT_VERSION: v1.41.1 + GO_VERSION: 1.19 + GOLANGCI_LINT_VERSION: v1.50.0 CGO_ENABLED: 0 steps: @@ -46,21 +44,15 @@ jobs: go mod tidy git diff --exit-code go.mod git diff --exit-code go.sum - go mod download # https://golangci-lint.run/usage/install#other-ci - name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }} - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + golangci-lint --version - name: Make run: make - # https://goreleaser.com/ci/actions/ - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - if: startsWith(github.ref, 'refs/tags/v') - with: - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Make Image + run: make image diff --git a/.github/workflows/go-cross.yml b/.github/workflows/go-cross.yml index a0f4a76..4416873 100644 --- a/.github/workflows/go-cross.yml +++ b/.github/workflows/go-cross.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - go-version: [ 1.16, 1.x ] + go-version: [ 1.19, 1.x ] os: [ubuntu-latest, macos-latest, windows-latest] steps: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..14dd505 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: "Release a tag" +on: + push: + tags: + - v* + +jobs: + release: + name: Release Process + runs-on: ubuntu-latest + env: + GO_VERSION: 1.19 + CGO_ENABLED: 0 + + steps: + + # https://github.com/marketplace/actions/setup-go-environment + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + # https://github.com/marketplace/actions/checkout + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Docker Login + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + run: | + echo "${DOCKER_TOKEN}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # https://goreleaser.com/ci/actions/ + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.golangci.toml b/.golangci.toml deleted file mode 100644 index c1e4523..0000000 --- a/.golangci.toml +++ /dev/null @@ -1,71 +0,0 @@ -[run] - deadline = "2m" - skip-files = [ - "^unsecured/", - ] - -[linters-settings] - - [linters-settings.govet] - check-shadowing = true - - [linters-settings.gocyclo] - min-complexity = 16.0 - - [linters-settings.maligned] - suggest-new = true - - [linters-settings.goconst] - min-len = 3.0 - min-occurrences = 3.0 - - [linters-settings.misspell] - locale = "US" - -[linters] - enable-all = true - disable = [ - "maligned", - "interfacer", - "scopelint", - "golint", - "cyclop", - "lll", - "gas", - "dupl", - "prealloc", - "scopelint", - "gomnd", - "wsl", - "nlreturn", - "gocognit", - "nestif", - "testpackage", - "paralleltest", - "tparallel", - "goerr113", - "wrapcheck", - "exhaustive", - "exhaustivestruct", - "noctx", - "ifshort", - "makezero", - "forbidigo", - ] - -[issues] - exclude-use-default = false - max-per-linter = 0 - max-same-issues = 0 - exclude = [ - "ST1000: at least one file in a package should have a package comment", - ] - [[issues.exclude-rules]] - path = "version.go" - text = "(version|date|commit) is a global variable" - [[issues.exclude-rules]] - path = "version.go" - text = "use of `fmt.Printf` forbidden by pattern" - [[issues.exclude-rules]] - path = "internal/search/parameter.go" - text = "Multiplication of durations: `\\-time\\.Duration\\(days\\) \\* 24 \\* time\\.Hour`" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..6f3e10e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,70 @@ +run: + timeout: 2m + skip-files: + - ^unsecured/ + +linters-settings: + govet: + check-shadowing: true + gocyclo: + min-complexity: 16 + goconst: + min-len: 3 + min-occurrences: 3 + misspell: + locale: US + +linters: + enable-all: true + disable: + - maligned # deprecated + - interfacer # deprecated + - scopelint # deprecated + - golint # deprecated + - ifshort # deprecated + - varcheck # deprecated + - deadcode # deprecated + - nosnakecase # deprecated + - structcheck # deprecated + - exhaustivestruct # deprecated + - execinquery # not relevant (SQL) + - sqlclosecheck # not relevant (SQL) + - rowserrcheck # not relevant (SQL) + - cyclop # duplicate of gocyclo + - contextcheck + - lll + - gas + - dupl + - prealloc + - scopelint + - gomnd + - wsl + - nlreturn + - gocognit + - nestif + - testpackage + - paralleltest + - tparallel + - goerr113 + - wrapcheck + - exhaustive + - exhaustruct + - noctx + - varnamelen + - nilnil + +issues: + exclude-use-default: false + max-per-linter: 0 + max-same-issues: 0 + exclude: + - 'ST1000: at least one file in a package should have a package comment' + - 'package-comments: should have a package comment' + exclude-rules: + - path: (.+)_test.go + linters: + - funlen + - path: version.go + text: (version|date|commit) is a global variable + - path: version.go + text: use of `fmt.Printf` forbidden by pattern diff --git a/.goreleaser.yml b/.goreleaser.yml index 4ae4ec3..bf9b04a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,21 +2,22 @@ project_name: bibikoffi builds: - binary: bibikoffi + main: ./ + + env: + - CGO_ENABLED=0 + flags: + - -trimpath + ldflags: + - -s -w -X main.version={{.Version}} + goos: - windows - darwin - linux goarch: - amd64 - - 386 - - arm - arm64 - goarm: - - 7 - - ignore: - - goos: darwin - goarch: 386 changelog: sort: asc @@ -28,11 +29,69 @@ changelog: - '^test:' - '^tests:' -archive: - name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' - format: tar.gz - format_overrides: - - goos: windows - format: zip - files: - - LICENSE +archives: + - id: bibikoffi + name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + format: tar.gz + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + +docker_manifests: + - name_template: 'traefik/bibikoffi:{{ .Tag }}' + image_templates: + - 'traefik/bibikoffi:{{ .Tag }}-amd64' + - 'traefik/bibikoffi:{{ .Tag }}-arm64' + - name_template: 'traefik/bibikoffi:latest' + image_templates: + - 'traefik/bibikoffi:{{ .Tag }}-amd64' + - 'traefik/bibikoffi:{{ .Tag }}-arm64' + - name_template: 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}' + image_templates: + - 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-amd64' + - 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-arm64' + +dockers: + - use: buildx + goos: linux + goarch: amd64 + dockerfile: buildx.Dockerfile + image_templates: + - 'traefik/bibikoffi:latest-amd64' + - 'traefik/bibikoffi:{{ .Tag }}-amd64' + - 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-amd64' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Myrmica Bibikoffi - Closes stale issues' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation={{.GitURL}}' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/amd64' + + - use: buildx + goos: linux + goarch: arm64 + dockerfile: buildx.Dockerfile + image_templates: + - 'traefik/bibikoffi:latest-arm64' + - 'traefik/bibikoffi:{{ .Tag }}-arm64' + - 'traefik/bibikoffi:v{{ .Major }}.{{ .Minor }}-arm64' + build_flag_templates: + - '--pull' + # https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys + - '--label=org.opencontainers.image.title={{.ProjectName}}' + - '--label=org.opencontainers.image.description=Myrmica Bibikoffi - Closes stale issues' + - '--label=org.opencontainers.image.source={{.GitURL}}' + - '--label=org.opencontainers.image.url={{.GitURL}}' + - '--label=org.opencontainers.image.documentation={{.GitURL}}' + - '--label=org.opencontainers.image.created={{.Date}}' + - '--label=org.opencontainers.image.revision={{.FullCommit}}' + - '--label=org.opencontainers.image.version={{.Version}}' + - '--platform=linux/arm64' diff --git a/Makefile b/Makefile index 604b22d..5ecd5e1 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,10 @@ SHA := $(shell git rev-parse --short HEAD) VERSION := $(if $(TAG_NAME),$(TAG_NAME),$(SHA)) BUILD_DATE := $(shell date -u '+%Y-%m-%d_%I:%M:%S%p') +BIN_OUTPUT := $(if $(filter $(shell go env GOOS), windows), bibikoffi.exe, bibikoffi) + +IMAGE_NAME := traefik/bibikoffi + default: clean check test build test: clean @@ -17,7 +21,10 @@ clean: build: clean @echo Version: $(VERSION) $(BUILD_DATE) - go build -v -ldflags '-X "main.version=${VERSION}" -X "main.commit=${SHA}" -X "main.date=${BUILD_DATE}"' + CGO_ENABLED=0 go build -trimpath -ldflags '-s -w -X "main.version=${VERSION}" -X "main.commit=${SHA}" -X "main.date=${BUILD_DATE}"' -o ${BIN_OUTPUT} . check: golangci-lint run + +image: + docker build -t $(IMAGE_NAME) . diff --git a/buildx.Dockerfile b/buildx.Dockerfile new file mode 100644 index 0000000..34680cb --- /dev/null +++ b/buildx.Dockerfile @@ -0,0 +1,10 @@ +# syntax=docker/dockerfile:1.4 +FROM alpine:3.16 + +RUN apk --no-cache --no-progress add ca-certificates git \ + && rm -rf /var/cache/apk/* + +COPY bibikoffi / + +ENTRYPOINT ["/bibikoffi"] +EXPOSE 80 diff --git a/go.mod b/go.mod index 3b4a7f8..cad3dbc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/traefik/bibikoffi -go 1.16 +go 1.19 require ( github.com/BurntSushi/toml v0.3.1 @@ -10,3 +10,11 @@ require ( github.com/rs/zerolog v1.21.0 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 ) + +require ( + github.com/golang/protobuf v1.2.0 // indirect + github.com/google/go-querystring v1.0.0 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect + golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect + google.golang.org/appengine v1.4.0 // indirect +)