Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
46d1c2fa1a | |||
9b1db3f461 |
@ -12,8 +12,8 @@ jobs:
|
|||||||
name: Main Process
|
name: Main Process
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
GO_VERSION: 1.17
|
GO_VERSION: 1.19
|
||||||
GOLANGCI_LINT_VERSION: v1.46.2
|
GOLANGCI_LINT_VERSION: v1.49.0
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
|
|
||||||
steps:
|
steps:
|
2
.github/workflows/go-cross.yml
vendored
2
.github/workflows/go-cross.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [ 1.17, 1.x ]
|
go-version: [ 1.19, 1.x ]
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
21
.github/workflows/release.yml
vendored
21
.github/workflows/release.yml
vendored
@ -9,7 +9,7 @@ jobs:
|
|||||||
name: Release Process
|
name: Release Process
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
GO_VERSION: 1.17
|
GO_VERSION: 1.19
|
||||||
SEIHON_VERSION: v0.9.0
|
SEIHON_VERSION: v0.9.0
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
|
|
||||||
@ -27,12 +27,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
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
|
- name: Docker Login
|
||||||
env:
|
env:
|
||||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
@ -40,5 +34,14 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
|
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
|
||||||
|
|
||||||
- name: Deploy Docker Images (seihon)
|
- name: Set up Docker Buildx
|
||||||
run: make publish-images
|
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 }}
|
||||||
|
@ -1,48 +1,93 @@
|
|||||||
run:
|
run:
|
||||||
deadline: 2m
|
timeout: 2m
|
||||||
skip-files: []
|
skip-files: []
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
govet:
|
govet:
|
||||||
check-shadowing: true
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
- fieldalignment
|
||||||
gocyclo:
|
gocyclo:
|
||||||
min-complexity: 12
|
min-complexity: 16
|
||||||
goconst:
|
goconst:
|
||||||
min-len: 3
|
min-len: 3
|
||||||
min-occurrences: 3
|
min-occurrences: 3
|
||||||
misspell:
|
misspell:
|
||||||
locale: US
|
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:
|
linters:
|
||||||
enable-all: true
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
|
- deadcode # deprecated
|
||||||
|
- exhaustivestruct # deprecated
|
||||||
- golint # deprecated
|
- golint # deprecated
|
||||||
- scopelint # deprecated
|
- ifshort # deprecated
|
||||||
- interfacer # deprecated
|
- interfacer # deprecated
|
||||||
- maligned # deprecated
|
- maligned # deprecated
|
||||||
- lll
|
- nosnakecase # deprecated
|
||||||
- gosec
|
- 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
|
- dupl
|
||||||
- prealloc
|
- exhaustive
|
||||||
|
- exhaustruct
|
||||||
|
- forbidigo
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- gomnd
|
|
||||||
- wsl
|
|
||||||
- nlreturn
|
|
||||||
- testpackage
|
|
||||||
- paralleltest
|
|
||||||
- tparallel
|
|
||||||
- goerr113
|
- goerr113
|
||||||
- wrapcheck
|
- gomnd
|
||||||
- exhaustive
|
- gosec
|
||||||
- exhaustivestruct
|
- lll
|
||||||
- forbidigo
|
|
||||||
- varnamelen
|
|
||||||
- nilnil
|
- nilnil
|
||||||
- ifshort
|
- nlreturn
|
||||||
- exhaustruct
|
- paralleltest
|
||||||
|
- prealloc
|
||||||
|
- testpackage
|
||||||
|
- tparallel
|
||||||
|
- varnamelen
|
||||||
|
- wrapcheck
|
||||||
|
- wsl
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-use-default: false
|
exclude-use-default: false
|
||||||
max-per-linter: 0
|
max-per-linter: 0
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
exclude: []
|
exclude:
|
||||||
|
- 'package-comments: should have a package comment'
|
||||||
|
80
.goreleaser.yml
Normal file
80
.goreleaser.yml
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
project_name: whoami
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- binary: whoami
|
||||||
|
goos:
|
||||||
|
- windows
|
||||||
|
- darwin
|
||||||
|
- linux
|
||||||
|
- freebsd
|
||||||
|
- openbsd
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- '386'
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
goarm:
|
||||||
|
- '7'
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: '386'
|
||||||
|
- goos: openbsd
|
||||||
|
goarch: arm
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
dockers:
|
||||||
|
- use: buildx
|
||||||
|
skip_push: true
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'traefik/whoami:dev-amd64'
|
||||||
|
- 'traefik/whoami:latest-amd64'
|
||||||
|
- 'traefik/whoami:{{ .Tag }}-amd64'
|
||||||
|
- 'traefik/whoami:v{{ .Major }}.{{ .Minor }}-amd64'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
|
||||||
|
- use: buildx
|
||||||
|
skip_push: true
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
dockerfile: buildx.Dockerfile
|
||||||
|
image_templates:
|
||||||
|
- 'traefik/whoami:dev-arm64'
|
||||||
|
- 'traefik/whoami:latest-arm64'
|
||||||
|
- 'traefik/whoami:{{ .Tag }}-arm64'
|
||||||
|
- 'traefik/whoami:v{{ .Major }}.{{ .Minor }}-arm64'
|
||||||
|
build_flag_templates:
|
||||||
|
- '--pull'
|
||||||
|
- '--label=org.opencontainers.image.created={{.Date}}'
|
||||||
|
- '--label=org.opencontainers.image.title={{.ProjectName}}'
|
||||||
|
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
|
||||||
|
- '--label=org.opencontainers.image.version={{.Version}}'
|
||||||
|
|
2
Makefile
2
Makefile
@ -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)
|
TAG_NAME := $(shell git tag -l --contains HEAD)
|
||||||
|
|
||||||
|
5
app.go
5
app.go
@ -7,7 +7,6 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -85,7 +84,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupMutualTLS(ca string) *tls.Config {
|
func setupMutualTLS(ca string) *tls.Config {
|
||||||
clientCACert, err := ioutil.ReadFile(ca)
|
clientCACert, err := os.ReadFile(ca)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -312,7 +311,7 @@ func healthHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
func getEnv(key, fallback string) string {
|
func getEnv(key, fallback string) string {
|
||||||
value := os.Getenv(key)
|
value := os.Getenv(key)
|
||||||
if len(value) == 0 {
|
if value == "" {
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
@ -1,25 +1,17 @@
|
|||||||
|
# syntax=docker/dockerfile:1.2
|
||||||
FROM golang:1-alpine as builder
|
FROM golang:1-alpine as builder
|
||||||
|
|
||||||
RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
|
RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
|
||||||
&& update-ca-certificates \
|
&& update-ca-certificates \
|
||||||
&& rm -rf /var/cache/apk/*
|
&& rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
WORKDIR /go/whoami
|
# syntax=docker/dockerfile:1.2
|
||||||
|
# Create a minimal container to run a Golang static binary
|
||||||
# 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
|
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
COPY --from=builder /go/whoami/whoami .
|
COPY whoami /
|
||||||
|
|
||||||
ENTRYPOINT ["/whoami"]
|
ENTRYPOINT ["/whoami"]
|
||||||
EXPOSE 80
|
EXPOSE 80
|
Reference in New Issue
Block a user