Skip to content

Commit 0b29025

Browse files
author
Patrick Koss
committed
fake jwt server
1 parent f0fde19 commit 0b29025

File tree

14 files changed

+879
-0
lines changed

14 files changed

+879
-0
lines changed

.github/renovate.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": [
3+
"config:base",
4+
"group:allNonMajor",
5+
":semanticCommits",
6+
":semanticCommitTypeAll(chore)",
7+
":gitSignOff"
8+
],
9+
"dependencyDashboard": false,
10+
"packageRules": [
11+
{
12+
"matchUpdateTypes": ["major", "minor", "patch", "pin", "digest"],
13+
"automerge": true
14+
}
15+
],
16+
"postUpdateOptions": ["gomodTidy", "gomodUpdateImportPaths"]
17+
}

.github/workflows/main.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
# based on https://github.com/mvdan/github-actions-golang
3+
name: CI
4+
5+
on:
6+
pull_request:
7+
branches: ["main"]
8+
paths-ignore: ["docs/**"]
9+
10+
push:
11+
branches: ["main"]
12+
paths-ignore: ["docs/**"]
13+
14+
# Allows you to run this workflow manually from the Actions tab
15+
workflow_dispatch:
16+
17+
jobs:
18+
test:
19+
strategy:
20+
matrix:
21+
go-version: [1.20.x]
22+
os: [ubuntu-latest]
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- name: Install Go
27+
uses: actions/setup-go@v4
28+
with:
29+
go-version: ${{ matrix.go-version }}
30+
31+
- name: Checkout code
32+
uses: actions/checkout@v3
33+
34+
# cache go modules
35+
- uses: actions/cache@v3
36+
with:
37+
# In order:
38+
# * Module download cache
39+
# * Build cache (Linux)
40+
# * Build cache (Mac)
41+
# * Build cache (Windows)
42+
path: |
43+
~/go/pkg/mod
44+
~/.cache/go-build
45+
~/Library/Caches/go-build
46+
%LocalAppData%\go-build
47+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
48+
restore-keys: |
49+
${{ runner.os }}-go-
50+
51+
- name: Downloads the dependencies
52+
run: make download
53+
54+
- name: Lints all code with golangci-lint
55+
run: make lint

.github/workflows/release.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
permissions: read-all
9+
10+
jobs:
11+
release:
12+
permissions:
13+
id-token: write
14+
packages: write
15+
contents: write
16+
runs-on: ubuntu-latest
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
23+
with:
24+
fetch-depth: 0
25+
- name: Git Fetch
26+
run: git fetch --force --tags
27+
- name: Setup go
28+
uses: actions/setup-go@v4
29+
with:
30+
go-version: stable
31+
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
32+
with:
33+
path: |
34+
~/.cache/go-build
35+
~/go/pkg/mod
36+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
${{ runner.os }}-go-
39+
- uses: anchore/sbom-action/download-syft@78fc58e266e87a38d4194b2137a3d4e9bcaf7ca1 # v0.14.3
40+
41+
- name: Set Up Docker Buildx
42+
uses: docker/setup-buildx-action@v2
43+
44+
- name: Login to Registry
45+
uses: docker/login-action@v2
46+
with:
47+
registry: ${{ env.REGISTRY }}
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Release with Goreleaser
52+
uses: goreleaser/goreleaser-action@v4
53+
with:
54+
distribution: goreleaser
55+
version: latest
56+
args: release --clean
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@
1919

2020
# Go workspace file
2121
go.work
22+
23+
.idea/
24+
.vscode/
25+
bin/

.golangci.yaml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
linters-settings:
2+
nestif:
3+
min-complexity: 3
4+
dupl:
5+
threshold: 100
6+
funlen:
7+
lines: 100
8+
statements: 50
9+
goconst:
10+
min-len: 3
11+
min-occurrences: 3
12+
gocritic:
13+
enabled-tags:
14+
- diagnostic
15+
- experimental
16+
- opinionated
17+
- performance
18+
- style
19+
disabled-checks:
20+
- dupImport # https://github.com/go-critic/go-critic/issues/845
21+
- ifElseChain
22+
- octalLiteral
23+
- whyNoLint
24+
- wrapperFunc
25+
- unnamedResult
26+
gocyclo:
27+
min-complexity: 10
28+
gci:
29+
local-prefixes: github.com/stackitcloud
30+
goimports:
31+
local-prefixes: github.com/stackitcloud
32+
golint:
33+
min-confidence: 0
34+
gomnd:
35+
settings:
36+
mnd:
37+
# don't include the "operation" and "assign"
38+
checks:
39+
- argument
40+
- case
41+
- condition
42+
- return
43+
govet:
44+
check-shadowing: false # too many false positives when shadowing err
45+
lll:
46+
line-length: 120
47+
misspell:
48+
locale: US
49+
nolintlint:
50+
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
51+
allow-unused: false # report any unused nolint directives
52+
require-explanation: true # require an explanation for nolint directives
53+
require-specific: false # require nolint directives to be specific about which linter is being skipped
54+
revive:
55+
rules:
56+
- name: var-naming
57+
severity: warning
58+
disabled: false
59+
arguments:
60+
- [ "JSON" ] # AllowList
61+
- [ ] # DenyList
62+
stylecheck:
63+
initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS" ]
64+
linters:
65+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
66+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
67+
disable-all: true
68+
enable:
69+
- dogsled
70+
- dupl
71+
- exportloopref
72+
- exhaustive
73+
- funlen
74+
- gochecknoinits
75+
- goconst
76+
- gocritic
77+
- gocyclo
78+
- godot
79+
- gofmt
80+
- goimports
81+
- gomnd
82+
- goprintffuncname
83+
- gosec
84+
- gosimple
85+
- govet
86+
- ineffassign
87+
- lll
88+
- megacheck
89+
- misspell
90+
- nakedret
91+
- nolintlint
92+
- revive
93+
- staticcheck
94+
- stylecheck
95+
- typecheck
96+
- unconvert
97+
- unused
98+
- whitespace
99+
- gochecknoglobals
100+
- goerr113
101+
- prealloc
102+
- asciicheck
103+
- nestif
104+
- tenv
105+
- thelper
106+
- tparallel
107+
- paralleltest
108+
109+
issues:
110+
# Excluding configuration per-path, per-linter, per-text and per-source
111+
exclude-rules:
112+
- path: _test\.go
113+
linters:
114+
- gomnd
115+
- gochecknoglobals
116+
- gosec
117+
- noctx
118+
- lll
119+
120+
- path: cmd/
121+
linters:
122+
- gomnd
123+
- gochecknoglobals
124+
- lll
125+
- gosec
126+
- gochecknoinits
127+
128+
# https://github.com/go-critic/go-critic/issues/926
129+
- linters:
130+
- gocritic
131+
text: "unnecessaryDefer:"
132+
fix: true
133+
134+
run:
135+
timeout: 10m
136+
issues-exit-code: 1
137+
tests: true

.goreleaser.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
project_name: fake-jwt-server
2+
snapshot:
3+
name_template: '{{ .Tag }}-SNAPSHOT'
4+
builds:
5+
- id: fake-jwt-server
6+
goos:
7+
- linux
8+
goarch:
9+
- amd64
10+
main: ./cmd/fakejwtserver
11+
binary: fake-jwt-server
12+
env:
13+
- CGO_ENABLED=0
14+
ldflags:
15+
- -s
16+
- -w
17+
- -X 'main.Version={{.Version}}'
18+
- -X 'main.Gitsha={{.ShortCommit}}'
19+
source:
20+
enabled: true
21+
archives:
22+
- format: tar.gz
23+
# this name template makes the OS and Arch compatible with the results of uname.
24+
name_template: >-
25+
{{ .ProjectName }}_
26+
{{- title .Os }}_
27+
{{- if eq .Arch "amd64" }}x86_64
28+
{{- else if eq .Arch "386" }}i386
29+
{{- else }}{{ .Arch }}{{ end }}
30+
{{- if .Arm }}v{{ .Arm }}{{ end }}
31+
# use zip for windows archives
32+
format_overrides:
33+
- goos: windows
34+
format: zip
35+
dockers:
36+
- id: fake-jwt-server
37+
use: buildx
38+
image_templates:
39+
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}"
40+
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest"
41+
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .ShortCommit }}"
42+
goos: linux
43+
goarch: amd64
44+
build_flag_templates:
45+
- --label=org.opencontainers.image.title={{ .ProjectName }}
46+
- --label=org.opencontainers.image.description=fake-jwt-server
47+
- --label=org.opencontainers.image.url=https://{{ .Env.GITHUB_SERVER_URL }}/{{ .Env.GITHUB_REPOSITORY}}
48+
- --label=org.opencontainers.image.source=https://{{ .Env.GITHUB_SERVER_URL }}/{{ .Env.GITHUB_REPOSITORY}}
49+
- --label=org.opencontainers.image.version={{ .Version }}
50+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
51+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
52+
- --label=org.opencontainers.image.licenses=Apache-2.0
53+
skip_push: false
54+
checksum:
55+
disable: false
56+
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"
57+
dist: dist
58+
changelog:
59+
use: github
60+
sort: asc
61+
filters:
62+
exclude:
63+
- '^docs:'
64+
- '^test:'

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine:3.19
2+
3+
RUN apk --no-cache add ca-certificates
4+
5+
COPY fake-jwt-server /fake-jwt-server
6+
7+
ENTRYPOINT ["/fake-jwt-server"]

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
SHELL=/bin/bash -e -o pipefail
2+
PWD = $(shell pwd)
3+
export PATH := $(PWD)/bin:$(PATH)
4+
export CGO_ENABLED = 0
5+
6+
# https://github.com/golangci/golangci-lint/releases
7+
GOLANGCI_VERSION = 1.56.2
8+
9+
VERSION ?= 0.0.1
10+
IMAGE_TAG_BASE ?= stackitcloud/fake-jwt-server
11+
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
12+
13+
download:
14+
go mod download
15+
16+
.PHONY: build
17+
build:
18+
CGO_ENABLED=0 go build -ldflags "-s -w" -o ./bin/fake-jwt-server -v cmd/fakejwtserver/main.go
19+
20+
.PHONY: docker-build
21+
docker-build:
22+
CGO_ENABLED=0 go build -ldflags "-s -w" -o ./bin/fake-jwt-server -v cmd/fakejwtserver/main.go
23+
docker build -t $(IMG) -f Dockerfile .
24+
rm fake-jwt-server
25+
26+
GOLANGCI_LINT = bin/golangci-lint-$(GOLANGCI_VERSION)
27+
$(GOLANGCI_LINT):
28+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b bin v$(GOLANGCI_VERSION)
29+
@mv bin/golangci-lint "$(@)"
30+
31+
lint: $(GOLANGCI_LINT) download
32+
$(GOLANGCI_LINT) run -v
33+
34+
run:
35+
go run cmd/fakejwtserver/main.go

0 commit comments

Comments
 (0)