7 Commits

Author SHA1 Message Date
098845bccd chore: QEMU 2022-09-10 17:08:17 +02:00
0f526f05ab chore: enforce platform 2022-09-10 17:00:19 +02:00
24b1d1e4be chore: add missing manifest 2022-09-10 16:48:40 +02:00
1c1ad7d0f9 chore: keep it simple 2022-09-10 16:39:39 +02:00
05efa96950 chore: push images 2022-09-10 16:37:19 +02:00
46d1c2fa1a chore: goreleaser and buildx 2022-09-10 16:30:59 +02:00
9b1db3f461 chore: update Go, linter, CI 2022-09-10 12:29:58 +02:00
9 changed files with 178 additions and 50 deletions

View File

@ -12,8 +12,8 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.17
GOLANGCI_LINT_VERSION: v1.46.2
GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.49.0
CGO_ENABLED: 0
steps:

View File

@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
go-version: [ 1.17, 1.x ]
go-version: [ 1.19, 1.x ]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:

View File

@ -9,7 +9,7 @@ jobs:
name: Release Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.17
GO_VERSION: 1.19
SEIHON_VERSION: v0.9.0
CGO_ENABLED: 0
@ -27,12 +27,6 @@ jobs:
with:
fetch-depth: 0
# Install Docker image multi-arch builder
- name: Install seihon ${{ env.SEIHON_VERSION }}
run: |
curl -sSfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | sh -s -- -b $(go env GOPATH)/bin ${SEIHON_VERSION}
seihon --version
- name: Docker Login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
@ -40,5 +34,17 @@ jobs:
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Deploy Docker Images (seihon)
run: make publish-images
- 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.GH_TOKEN_REPO }}

View File

@ -1,48 +1,93 @@
run:
deadline: 2m
timeout: 2m
skip-files: []
linters-settings:
govet:
check-shadowing: true
enable-all: true
disable:
- fieldalignment
gocyclo:
min-complexity: 12
min-complexity: 16
goconst:
min-len: 3
min-occurrences: 3
misspell:
locale: US
funlen:
lines: -1
statements: 40
gofumpt:
extra-rules: true
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/pkg/errors
godox:
keywords:
- FIXME
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- sloppyReassign
- rangeValCopy
- octalLiteral
- paramTypeCombine # already handle by gofumpt.extra-rules
settings:
hugeParam:
sizeThreshold: 100
forbidigo:
forbid:
- '^print(ln)?$'
- '^panic$'
- '^spew\.Print(f|ln)?$'
- '^spew\.Dump$'
linters:
enable-all: true
disable:
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- scopelint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- lll
- gosec
- nosnakecase # deprecated
- scopelint # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- execinquery # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- sqlclosecheck # not relevant (SQL)
- cyclop # duplicate of gocyclo
- dupl
- prealloc
- exhaustive
- exhaustruct
- forbidigo
- gochecknoglobals
- gochecknoinits
- gomnd
- wsl
- nlreturn
- testpackage
- paralleltest
- tparallel
- goerr113
- wrapcheck
- exhaustive
- exhaustivestruct
- forbidigo
- varnamelen
- gomnd
- gosec
- lll
- nilnil
- ifshort
- exhaustruct
- nlreturn
- paralleltest
- prealloc
- testpackage
- tparallel
- varnamelen
- wrapcheck
- wsl
issues:
exclude-use-default: false
max-per-linter: 0
max-same-issues: 0
exclude: []
exclude:
- 'package-comments: should have a package comment'

86
.goreleaser.yml Normal file
View File

@ -0,0 +1,86 @@
project_name: whoami
builds:
- binary: whoami
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm
- arm64
goarm:
- '7'
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^doc:'
- '^chore:'
- '^chore(deps):'
- '^test:'
- '^tests:'
archives:
- id: whoami
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/whoami:{{ .Tag }}'
image_templates:
- 'traefik/whoami:{{ .Tag }}-amd64'
- 'traefik/whoami:{{ .Tag }}-arm64'
- name_template: 'traefik/whoami:latest'
image_templates:
- 'traefik/whoami:{{ .Tag }}-amd64'
- 'traefik/whoami:{{ .Tag }}-arm64'
- name_template: 'traefik/whoami:v{{ .Major }}.{{ .Minor }}'
image_templates:
- 'traefik/whoami:v{{ .Major }}.{{ .Minor }}-amd64'
- 'traefik/whoami:v{{ .Major }}.{{ .Minor }}-arm64'
dockers:
- use: buildx
goos: linux
goarch: amd64
dockerfile: buildx.Dockerfile
image_templates:
- 'traefik/whoami:latest-amd64'
- 'traefik/whoami:{{ .Tag }}-amd64'
- 'traefik/whoami:v{{ .Major }}.{{ .Minor }}-amd64'
build_flag_templates:
- '--pull'
- '--label=org.opencontainers.image.description=Tiny Go webserver that prints OS information and HTTP request to output'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--platform=linux/amd64'
- use: buildx
goos: linux
goarch: arm64
dockerfile: buildx.Dockerfile
image_templates:
- 'traefik/whoami:latest-arm64'
- 'traefik/whoami:{{ .Tag }}-arm64'
- 'traefik/whoami:v{{ .Major }}.{{ .Minor }}-arm64'
build_flag_templates:
- '--pull'
- '--label=org.opencontainers.image.description=Tiny Go webserver that prints OS information and HTTP request to output'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--platform=linux/arm64'

View File

@ -1,4 +1,4 @@
.PHONY: default build image check publish-images
.PHONY: default check test build image publish-images
TAG_NAME := $(shell git tag -l --contains HEAD)

5
app.go
View File

@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
@ -85,7 +84,7 @@ func main() {
}
func setupMutualTLS(ca string) *tls.Config {
clientCACert, err := ioutil.ReadFile(ca)
clientCACert, err := os.ReadFile(ca)
if err != nil {
log.Fatal(err)
}
@ -312,7 +311,7 @@ func healthHandler(w http.ResponseWriter, req *http.Request) {
func getEnv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
if value == "" {
return fallback
}
return value

View File

@ -1,25 +1,17 @@
# syntax=docker/dockerfile:1.2
FROM golang:1-alpine as builder
RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*
WORKDIR /go/whoami
# Download go modules
COPY go.mod .
COPY go.sum .
RUN GO111MODULE=on GOPROXY=https://proxy.golang.org go mod download
COPY . .
RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build
# syntax=docker/dockerfile:1.2
# Create a minimal container to run a Golang static binary
FROM scratch
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/whoami/whoami .
COPY whoami /
ENTRYPOINT ["/whoami"]
EXPOSE 80

2
go.mod
View File

@ -1,5 +1,5 @@
module github.com/traefik/whoami
go 1.17
go 1.19
require github.com/gorilla/websocket v1.4.2