Skip to content

Commit 9d52552

Browse files
authored
Merge pull request #8 from phpgeeks-club/dimns-refactor-1
Big refactoring
2 parents b3aae69 + f3a4de5 commit 9d52552

File tree

184 files changed

+47408
-173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+47408
-173
lines changed

.env.example

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GEEKSONATOR_TELEGRAM_BOT_TOKEN=bot_token_here
2+
GEEKSONATOR_TELEGRAM_TIMEOUT_SECONDS=15
3+
GEEKSONATOR_DEBUG_MODE=false
4+
GEEKSONATOR_DEBUG_TELEGRAM_BOT_TOKEN=debug_bot_token_here

.github/workflows/audit.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: audit
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
audit:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout GitHub Action
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version-file: ./go.mod
23+
cache-dependency-path: ./go.sum
24+
25+
- name: Run golangci-lint
26+
uses: golangci/golangci-lint-action@v6
27+
with:
28+
version: v1.55.2
29+
working-directory: ./
30+
31+
- name: Install dependencies
32+
run: |
33+
go mod tidy
34+
go mod vendor
35+
go install github.com/vektra/mockery/[email protected]
36+
37+
- name: Run test
38+
run: go test ./...

.github/workflows/container.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: deploy to ghcr.io
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- "*"
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
push-image:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout GitHub Action
17+
uses: actions/checkout@main
18+
19+
- name: Fetch tags
20+
run: git fetch --force --tags
21+
22+
- name: Display tag
23+
run: echo ${{github.ref_name}}
24+
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v1
27+
with:
28+
registry: ghcr.io
29+
username: ${{github.actor}}
30+
password: ${{secrets.GITHUB_TOKEN}}
31+
32+
- name: Build Image
33+
run: docker build . --tag ghcr.io/phpgeeks-club/geeksonator:${{github.ref_name}}
34+
35+
- name: Push Image
36+
run: docker push ghcr.io/phpgeeks-club/geeksonator:${{github.ref_name}}

.github/workflows/release.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- "*"
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout GitHub Action
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Fetch tags
22+
run: git fetch --force --tags
23+
24+
- name: Display tag
25+
run: echo ${{github.ref_name}}
26+
27+
- name: Setup Go
28+
uses: actions/setup-go@v4
29+
with:
30+
go-version: stable
31+
32+
- name: Display Go version
33+
run: go version
34+
35+
- name: Create release
36+
uses: goreleaser/goreleaser-action@v5
37+
with:
38+
distribution: goreleaser
39+
version: latest
40+
args: release --clean
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

-2
This file was deleted.

.gitignore.example

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin/
2+
dist/
3+
.env
4+
.gitignore

.golangci.yml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
run:
2+
concurrency: 4
3+
timeout: 5m
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- asasalint
9+
- asciicheck
10+
- bidichk
11+
- bodyclose
12+
- containedctx
13+
- contextcheck
14+
- cyclop
15+
- dogsled
16+
- dupl
17+
- durationcheck
18+
- errcheck
19+
- errchkjson
20+
- errname
21+
- errorlint
22+
- exhaustive
23+
- exportloopref
24+
- forcetypeassert
25+
- gci
26+
- gocheckcompilerdirectives
27+
- gochecknoglobals
28+
- gochecknoinits
29+
- gocognit
30+
- goconst
31+
- gocritic
32+
- gocyclo
33+
- godot
34+
- godox
35+
- gofmt
36+
- goimports
37+
- gomnd
38+
- goprintffuncname
39+
- gosec
40+
- gosimple
41+
- govet
42+
- importas
43+
- ineffassign
44+
- maintidx
45+
- makezero
46+
- misspell
47+
- musttag
48+
- nakedret
49+
- nestif
50+
- nilerr
51+
- nilnil
52+
- nlreturn
53+
- noctx
54+
- nolintlint
55+
- nosprintfhostport
56+
- paralleltest
57+
- prealloc
58+
- predeclared
59+
- reassign
60+
- revive
61+
- staticcheck
62+
- stylecheck
63+
- tagliatelle
64+
- thelper
65+
- typecheck
66+
- unconvert
67+
- unparam
68+
- unused
69+
- usestdlibvars
70+
- whitespace
71+
- wrapcheck
72+
73+
linters-settings:
74+
errorlint:
75+
errorf: false
76+
gci:
77+
sections:
78+
- standard
79+
- default
80+
- prefix(geeksonator)
81+
gocognit:
82+
min-complexity: 10
83+
gocyclo:
84+
min-complexity: 10
85+
nestif:
86+
min-complexity: 4
87+
unparam:
88+
check-exported: true

.goreleaser.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
project_name: geeksonator
2+
builds:
3+
- id: geeksonator
4+
env:
5+
- CGO_ENABLED=0
6+
goos:
7+
- linux
8+
goarch:
9+
- amd64
10+
flags:
11+
- -trimpath
12+
ldflags:
13+
- -s -w
14+
main: ./cmd/geeksonator
15+
binary: ./bin/geeksonator

.mockery.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
quiet: true
2+
with-expecter: true
3+
disable-config-search: true
4+
dir: "{{.InterfaceDir}}/mocks"
5+
mockname: "{{.InterfaceName}}Mock"
6+
filename: "{{.InterfaceName | snakecase}}_mock.go"
7+
outpkg: "mocks"
8+
packages:
9+
geeksonator/internal/observer:
10+
geeksonator/internal/provider/telegram:

.tool-versions

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
golang 1.21.4
2+
golangci-lint 1.55.2

Dockerfile

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Run
2+
# docker build -f ./Dockerfile -t geeksonator:latest .
3+
# docker run -d --env-file=/path/to/.env --name geeksonator.app geeksonator:latest .
4+
5+
##################################
6+
# STEP 1 build executable binary #
7+
##################################
8+
9+
FROM golang:1.21.4-alpine as builder
10+
11+
LABEL org.opencontainers.image.source="https://github.com/phpgeeks-club/admin-bot"
12+
13+
# Install git + SSL ca certificates.
14+
# Git is required for fetching the dependencies.
15+
# Ca-certificates is required to call HTTPS endpoints.
16+
RUN apk update && apk add --no-cache git ca-certificates tzdata make && update-ca-certificates
17+
18+
# Create appuser.
19+
ENV USER=appuser
20+
ENV UID=10001
21+
22+
# See https://stackoverflow.com/a/55757473/12429735
23+
RUN adduser \
24+
--disabled-password \
25+
--gecos "" \
26+
--home "/nonexistent" \
27+
--shell "/sbin/nologin" \
28+
--no-create-home \
29+
--uid "${UID}" \
30+
"${USER}"
31+
32+
WORKDIR /app
33+
34+
COPY . .
35+
36+
# Build the binary.
37+
RUN make build
38+
39+
##############################
40+
# STEP 2 build a small image #
41+
##############################
42+
43+
FROM scratch
44+
45+
# Import from builder.
46+
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
47+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
48+
COPY --from=builder /etc/passwd /etc/passwd
49+
COPY --from=builder /etc/group /etc/group
50+
51+
# Copy our static executable.
52+
COPY --from=builder /app/bin/geeksonator /app/geeksonator
53+
54+
# Use an unprivileged user.
55+
USER appuser:appuser
56+
57+
# Run the binary.
58+
ENTRYPOINT ["/app/geeksonator"]

Makefile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.EXPORT_ALL_VARIABLES:
2+
GOBIN = $(shell pwd)/bin
3+
4+
.PHONY: deps
5+
deps:
6+
@go mod tidy
7+
@go mod vendor
8+
9+
.PHONY: mocks
10+
mocks: tools
11+
@export PATH="$(shell pwd)/bin:$(PATH)"; mockery --config=.mockery.yaml
12+
13+
.PHONY: lint
14+
lint:
15+
@golangci-lint run
16+
17+
.PHONY: test
18+
test:
19+
@go test ./...
20+
21+
.PHONY: docker_build
22+
docker_build:
23+
@docker build -f ./Dockerfile -t geeksonator_dev .
24+
25+
.PHONY: docker_run
26+
docker_run:
27+
@GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o ./bin/geeksonator ./cmd/geeksonator
28+
29+
.PHONY: build
30+
build: deps
31+
@GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o ./bin/geeksonator ./cmd/geeksonator
32+
33+
.PHONY: tools
34+
tools: deps
35+
@go install github.com/vektra/mockery/[email protected]
36+
@go install github.com/goreleaser/[email protected]

0 commit comments

Comments
 (0)