Skip to content

Commit

Permalink
Big refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrii Shcherbakov committed Feb 29, 2024
1 parent b3aae69 commit d88393b
Show file tree
Hide file tree
Showing 183 changed files with 47,407 additions and 173 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GEEKSONATOR_TELEGRAM_BOT_TOKEN=bot_token_here
GEEKSONATOR_TELEGRAM_TIMEOUT_SECONDS=15
GEEKSONATOR_DEBUG_MODE=false
GEEKSONATOR_DEBUG_TELEGRAM_BOT_TOKEN=debug_bot_token_here
45 changes: 45 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: audit

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
audit:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.21"]

steps:
- name: Checkout GitHub Action
uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Display Go version
run: go version

- name: Install dependencies
run: |
go mod tidy
go mod vendor
go install github.com/vektra/mockery/[email protected]
- name: Run golangci-lint
run: golangci-lint run

- name: Run test
run: go test ./...
36 changes: 36 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: deploy to ghcr.io

on:
push:
# run only against tags
tags:
- "*"

permissions:
contents: write

jobs:
push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Action
uses: actions/checkout@main

- name: Fetch tags
run: git fetch --force --tags

- name: Display tag
run: echo ${{github.ref_name}}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Build Image
run: docker build . --tag ghcr.io/phpgeeks-club/geeksonator:${{github.ref_name}}

- name: Push Image
run: docker push ghcr.io/phpgeeks-club/geeksonator:${{github.ref_name}}
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: goreleaser

on:
push:
# run only against tags
tags:
- "*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Fetch tags
run: git fetch --force --tags

- name: Display tag
run: echo ${{github.ref_name}}

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: stable

- name: Display Go version
run: go version

- name: Create release
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vscode
geeksonator
.vscode/
bin/
dist/
.env
88 changes: 88 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
run:
concurrency: 4
timeout: 5m

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
- dogsled
- dupl
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gci
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- maintidx
- makezero
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- prealloc
- predeclared
- reassign
- revive
- staticcheck
- stylecheck
- tagliatelle
- thelper
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
- wrapcheck

linters-settings:
errorlint:
errorf: false
gci:
sections:
- standard
- default
- prefix(geeksonator)
gocognit:
min-complexity: 10
gocyclo:
min-complexity: 10
nestif:
min-complexity: 4
unparam:
check-exported: true
15 changes: 15 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project_name: geeksonator
builds:
- id: geeksonator
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
flags:
- -trimpath
ldflags:
- -s -w
main: ./cmd/geeksonator
binary: ./bin/geeksonator
10 changes: 10 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
quiet: true
with-expecter: true
disable-config-search: true
dir: "{{.InterfaceDir}}/mocks"
mockname: "{{.InterfaceName}}Mock"
filename: "{{.InterfaceName | snakecase}}_mock.go"
outpkg: "mocks"
packages:
geeksonator/internal/observer:
geeksonator/internal/provider/telegram:
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang 1.21.4
golangci-lint 1.55.2
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Run
# docker build -f ./Dockerfile -t geeksonator:latest .
# docker run -d --env-file=/path/to/.env --name geeksonator.app geeksonator:latest .

##################################
# STEP 1 build executable binary #
##################################

FROM golang:1.21.4-alpine as builder

LABEL org.opencontainers.image.source="https://github.com/phpgeeks-club/admin-bot"

# Install git + SSL ca certificates.
# Git is required for fetching the dependencies.
# Ca-certificates is required to call HTTPS endpoints.
RUN apk update && apk add --no-cache git ca-certificates tzdata make && update-ca-certificates

# Create appuser.
ENV USER=appuser
ENV UID=10001

# See https://stackoverflow.com/a/55757473/12429735
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

WORKDIR /app

COPY . .

# Build the binary.
RUN make build

##############################
# STEP 2 build a small image #
##############################

FROM scratch

# Import from builder.
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/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group

# Copy our static executable.
COPY --from=builder /app/bin/geeksonator /app/geeksonator

# Use an unprivileged user.
USER appuser:appuser

# Run the binary.
ENTRYPOINT ["/app/geeksonator"]
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.EXPORT_ALL_VARIABLES:
GOBIN = $(shell pwd)/bin

.PHONY: deps
deps:
@go mod tidy
@go mod vendor

.PHONY: mocks
mocks: tools
@export PATH="$(shell pwd)/bin:$(PATH)"; mockery --config=.mockery.yaml

.PHONY: lint
lint:
@golangci-lint run

.PHONY: test
test:
@go test ./...

.PHONY: build
build: deps
@GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o ./bin/geeksonator ./cmd/geeksonator

.PHONY: tools
tools: deps
@go install github.com/vektra/mockery/[email protected]
@go install github.com/goreleaser/[email protected]
Loading

0 comments on commit d88393b

Please sign in to comment.