Skip to content

Commit 134f1a6

Browse files
authored
Go rewrite (#37)
1 parent 4bc25fe commit 134f1a6

File tree

183 files changed

+9972
-7514
lines changed

Some content is hidden

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

183 files changed

+9972
-7514
lines changed

.github/workflows/semgrep.yml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
push:
99
branches:
1010
- main
11-
- master
1211
paths:
1312
- .github/workflows/semgrep.yml
1413
schedule:

.github/workflows/sonarcloud.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
# a pull request.
88
push:
99
branches:
10-
- master
10+
- main
1111
pull_request:
1212
types: [opened, synchronize, reopened]
1313
name: SonarCloud analysis
@@ -19,6 +19,10 @@ jobs:
1919
with:
2020
# Disabling shallow clone is recommended for improving relevancy of reporting
2121
fetch-depth: 0
22+
- uses: jdx/mise-action@0c39a522dfbced3ed83924152c45804a71ce216f # v2.0.4
23+
with:
24+
experimental: true
25+
- run: mise run dev:lint --no-fail
2226
- name: SonarCloud Scan
2327
uses: sonarsource/sonarcloud-github-action@6bbd64e0cb2194e04addb429d669a9ee873eeeef
2428
env:

.gitignore

+57
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,60 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
162+
# User-specific stuff
163+
.idea/**/workspace.xml
164+
.idea/**/tasks.xml
165+
.idea/**/usage.statistics.xml
166+
.idea/**/dictionaries
167+
.idea/**/shelf
168+
169+
# AWS User-specific
170+
.idea/**/aws.xml
171+
172+
# Generated files
173+
.idea/**/contentModel.xml
174+
175+
# Sensitive or high-churn files
176+
.idea/**/dataSources/
177+
.idea/**/dataSources.ids
178+
.idea/**/dataSources.local.xml
179+
.idea/**/sqlDataSources.xml
180+
.idea/**/dynamic.xml
181+
.idea/**/uiDesigner.xml
182+
.idea/**/dbnavigator.xml
183+
184+
# Mongo Explorer plugin
185+
.idea/**/mongoSettings.xml
186+
187+
# File-based project format
188+
*.iws
189+
190+
# IntelliJ
191+
out/
192+
193+
# mpeltonen/sbt-idea plugin
194+
.idea_modules/
195+
196+
# JIRA plugin
197+
atlassian-ide-plugin.xml
198+
199+
# Cursive Clojure plugin
200+
.idea/replstate.xml
201+
202+
# SonarLint plugin
203+
.idea/sonarlint/
204+
205+
# Crashlytics plugin (for Android Studio and IntelliJ)
206+
com_crashlytics_export_strings.xml
207+
crashlytics.properties
208+
crashlytics-build.properties
209+
fabric.properties
210+
211+
# Editor-based Rest Client
212+
.idea/httpRequests
213+
214+
# Android studio 3.1+ serialized cache file
215+
.idea/caches/build_file_checksums.ser
216+
217+
.DS_Store

.golangci.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
run:
2+
tests: true
3+
build-tags:
4+
- integration
5+
output:
6+
formats:
7+
- format: checkstyle
8+
path: build/report.xml
9+
- format: colored-line-number
10+
linters:
11+
enable:
12+
- errcheck
13+
- gosimple
14+
- govet
15+
- ineffassign
16+
- staticcheck
17+
- unused
18+
- goimports
19+
- goheader
20+
- gosec
21+
- forbidigo
22+
- goconst
23+
- godot
24+
issues:
25+
exclude-rules:
26+
- linters:
27+
- goheader
28+
path: cache.go # This file already has a header with another license
29+
linters-settings:
30+
goimports:
31+
local-prefixes: github.com/madsrc/sophrosyne
32+
gofmt:
33+
simplify: true
34+
rewrite-rules:
35+
- pattern: 'interface{}'
36+
replacement: 'any'
37+
- pattern: 'a[b:len(a)]'
38+
replacement: 'a[b:]'
39+
goheader:
40+
values:
41+
const:
42+
AUTHOR: 'Mads R. Havmand'
43+
template: |-
44+
Sophrosyne
45+
Copyright (C) {{ YEAR }} {{ AUTHOR }}
46+
47+
This program is free software: you can redistribute it and/or modify
48+
it under the terms of the GNU Affero General Public License as published by
49+
the Free Software Foundation, either version 3 of the License, or
50+
(at your option) any later version.
51+
52+
This program is distributed in the hope that it will be useful,
53+
but WITHOUT ANY WARRANTY; without even the implied warranty of
54+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55+
GNU Affero General Public License for more details.
56+
57+
You should have received a copy of the GNU Affero General Public License
58+
along with this program. If not, see <http://www.gnu.org/licenses/>.

.idea/dataSources.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/golinter.xml

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sonarlint.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sophrosyne.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sqldialects.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.mise.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tools]
2+
go = "latest"
3+
watchexec = "latest"
4+
"go:github.com/golangci/golangci-lint/cmd/golangci-lint" = "1.58.1"
5+
"go:golang.org/x/tools/cmd/goimports" = "latest"
6+
7+
[settings]
8+
experimental = true
9+
go_set_gobin = true

.mise/tasks/clean

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
rm -rf build
4+
rm -rf dist

.mise/tasks/dev/db/down

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# mise outputs=[]
3+
4+
docker compose -f docker-compose.development.yml down

.mise/tasks/dev/db/up

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# mise outputs=[]
3+
4+
docker compose -f docker-compose.development.yml up -d

.mise/tasks/dev/format

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
3+
# mise outputs=["build/report.xml"]
4+
5+
check=1
6+
7+
handle_argument() {
8+
echo "Argument '$1' not supported" >&2; exit 1
9+
}
10+
11+
while test "$#" -gt 0; do
12+
case "$1" in
13+
--check) check=0; shift 1;;
14+
15+
-*) echo "unknown option: $1" >&2; exit 1;;
16+
*) handle_argument "$1"; shift 1;;
17+
esac
18+
done
19+
20+
if test "$check" = 0; then
21+
changes=$(goimports -l -local github.com/madsrc/sophrosyne -e .)
22+
if test -n "$changes"; then
23+
echo "$changes"
24+
exit 1
25+
else
26+
exit 0
27+
fi
28+
else
29+
goimports -w -local github.com/madsrc/sophrosyne -e .
30+
fi

.mise/tasks/dev/lint

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
3+
# mise outputs=["build/report.xml"]
4+
5+
nofail=1
6+
fix=1
7+
8+
fixflag=""
9+
10+
handle_argument() {
11+
echo "Argument '$1' not supported" >&2; exit 1
12+
}
13+
14+
while test "$#" -gt 0; do
15+
case "$1" in
16+
--no-fail) nofail=0; shift 1;;
17+
--fix) fix=0; shift 1;;
18+
19+
-*) echo "unknown option: $1" >&2; exit 1;;
20+
*) handle_argument "$1"; shift 1;;
21+
esac
22+
done
23+
24+
if test "$fix" = 0; then
25+
fixflags="--fix"
26+
fi
27+
28+
golangci-lint run --issues-exit-code="$nofail" $fixflags

.mise/tasks/dev/run

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
# mise outputs=[]
3+
4+
docker compose -f docker-compose.development.yml up -d
5+
SOPH_LOGGING_LEVEL=debug \
6+
SOPH_TRACING_OUTPUT=http \
7+
SOPH_METRICS_OUTPUT=http \
8+
SOPH_METRICS_ENABLED=true \
9+
SOPH_TRACING_ENABLED=true \
10+
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" \
11+
OTEL_TRACES_EXPORTER="otlp" \
12+
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \
13+
go run cmd/sophrosyne/main.go --config configurations/dev.yaml run

.mise/tasks/sync-go-version

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# mise outputs=[]
3+
4+
set -e
5+
6+
version=$(grep -E "^go .*$" go.mod | awk '{print $2}')
7+
8+
echo "Version extracted from go.mod: $version"
9+
10+
echo "Setting go version in .mise.toml"
11+
mise use "go@$version"
12+
13+
echo "Setting go version in .idea/workspace.xml"
14+
sed -i "s/.local\/share\/mise\/installs\/go\/.*\"/.local\/share\/mise\/installs\/go\/$version\"/g" .idea/workspace.xml

.pre-commit-config.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ repos:
66
args: ['--maxkb=4000']
77
- id: end-of-file-fixer
88
exclude: "snapshots|docs/api.md"
9-
- id: check-docstring-first
109
- id: trailing-whitespace
1110
exclude: "snapshots|docs/api.md"
1211
- id: check-merge-conflict
@@ -15,10 +14,4 @@ repos:
1514
- id: check-case-conflict
1615
- id: mixed-line-ending
1716
- id: detect-private-key
18-
- id: check-ast
19-
- id: check-builtin-literals
2017
- id: check-executables-have-shebangs
21-
- id: check-shebang-scripts-are-executable
22-
- id: name-tests-test
23-
args: [ "--pytest-test-first" ]
24-
- id: requirements-txt-fixer

.python-version

-1
This file was deleted.

Dockerfile

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
FROM cgr.dev/chainguard/python:latest-dev@sha256:40b3a19b7e2a50824b1ff32d61ae5f59af1b0de67f7bb8e56f5804bace0d94b7 AS builder
2-
3-
ARG dist_file
4-
5-
WORKDIR /app
6-
7-
COPY "dist/${dist_file}" "/home/nonroot/${dist_file}"
8-
9-
RUN --mount=type=secret,id=requirements,dst=/home/nonroot/requirements.txt,uid=65532,gid=65532 \
10-
pip install --no-cache-dir -r "/home/nonroot/requirements.txt"
11-
RUN pip install --no-cache-dir "/home/nonroot/${dist_file}"
12-
13-
FROM cgr.dev/chainguard/python:latest@sha256:5f16431f56f330925a9c8f5168b31ca65f603de15b127b376f8532bab11583c0
14-
15-
WORKDIR /app
16-
17-
COPY --from=builder /home/nonroot/.local/lib/python3.12/site-packages /home/nonroot/.local/lib/python3.12/site-packages
18-
19-
ENTRYPOINT [ "python", "-m", "sophrosyne.main", "run" ]
1+
FROM cgr.dev/chainguard/glibc-dynamic:latest
2+
COPY --chown=noneroot:noneroot dist/sophrosyne /usr/bin/
3+
ENTRYPOINT ["/usr/bin/sophrosyne"]

0 commit comments

Comments
 (0)