Skip to content

Commit

Permalink
Go rewrite (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsRC authored May 10, 2024
1 parent 4bc25fe commit 134f1a6
Show file tree
Hide file tree
Showing 183 changed files with 9,972 additions and 7,514 deletions.
1 change: 0 additions & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
push:
branches:
- main
- master
paths:
- .github/workflows/semgrep.yml
schedule:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/sonarcloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
# a pull request.
push:
branches:
- master
- main
pull_request:
types: [opened, synchronize, reopened]
name: SonarCloud analysis
Expand All @@ -19,6 +19,10 @@ jobs:
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: jdx/mise-action@0c39a522dfbced3ed83924152c45804a71ce216f # v2.0.4
with:
experimental: true
- run: mise run dev:lint --no-fail
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@6bbd64e0cb2194e04addb429d669a9ee873eeeef
env:
Expand Down
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,60 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

.DS_Store
58 changes: 58 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
run:
tests: true
build-tags:
- integration
output:
formats:
- format: checkstyle
path: build/report.xml
- format: colored-line-number
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- goimports
- goheader
- gosec
- forbidigo
- goconst
- godot
issues:
exclude-rules:
- linters:
- goheader
path: cache.go # This file already has a header with another license
linters-settings:
goimports:
local-prefixes: github.com/madsrc/sophrosyne
gofmt:
simplify: true
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
goheader:
values:
const:
AUTHOR: 'Mads R. Havmand'
template: |-
Sophrosyne
Copyright (C) {{ YEAR }} {{ AUTHOR }}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/golinter.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/sonarlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/sophrosyne.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tools]
go = "latest"
watchexec = "latest"
"go:github.com/golangci/golangci-lint/cmd/golangci-lint" = "1.58.1"
"go:golang.org/x/tools/cmd/goimports" = "latest"

[settings]
experimental = true
go_set_gobin = true
4 changes: 4 additions & 0 deletions .mise/tasks/clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

rm -rf build
rm -rf dist
4 changes: 4 additions & 0 deletions .mise/tasks/dev/db/down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
# mise outputs=[]

docker compose -f docker-compose.development.yml down
4 changes: 4 additions & 0 deletions .mise/tasks/dev/db/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
# mise outputs=[]

docker compose -f docker-compose.development.yml up -d
30 changes: 30 additions & 0 deletions .mise/tasks/dev/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["build/report.xml"]

check=1

handle_argument() {
echo "Argument '$1' not supported" >&2; exit 1
}

while test "$#" -gt 0; do
case "$1" in
--check) check=0; shift 1;;

-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done

if test "$check" = 0; then
changes=$(goimports -l -local github.com/madsrc/sophrosyne -e .)
if test -n "$changes"; then
echo "$changes"
exit 1
else
exit 0
fi
else
goimports -w -local github.com/madsrc/sophrosyne -e .
fi
28 changes: 28 additions & 0 deletions .mise/tasks/dev/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["build/report.xml"]

nofail=1
fix=1

fixflag=""

handle_argument() {
echo "Argument '$1' not supported" >&2; exit 1
}

while test "$#" -gt 0; do
case "$1" in
--no-fail) nofail=0; shift 1;;
--fix) fix=0; shift 1;;

-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done

if test "$fix" = 0; then
fixflags="--fix"
fi

golangci-lint run --issues-exit-code="$nofail" $fixflags
13 changes: 13 additions & 0 deletions .mise/tasks/dev/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# mise outputs=[]

docker compose -f docker-compose.development.yml up -d
SOPH_LOGGING_LEVEL=debug \
SOPH_TRACING_OUTPUT=http \
SOPH_METRICS_OUTPUT=http \
SOPH_METRICS_ENABLED=true \
SOPH_TRACING_ENABLED=true \
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" \
OTEL_TRACES_EXPORTER="otlp" \
OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" \
go run cmd/sophrosyne/main.go --config configurations/dev.yaml run
14 changes: 14 additions & 0 deletions .mise/tasks/sync-go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# mise outputs=[]

set -e

version=$(grep -E "^go .*$" go.mod | awk '{print $2}')

echo "Version extracted from go.mod: $version"

echo "Setting go version in .mise.toml"
mise use "go@$version"

echo "Setting go version in .idea/workspace.xml"
sed -i "s/.local\/share\/mise\/installs\/go\/.*\"/.local\/share\/mise\/installs\/go\/$version\"/g" .idea/workspace.xml
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repos:
args: ['--maxkb=4000']
- id: end-of-file-fixer
exclude: "snapshots|docs/api.md"
- id: check-docstring-first
- id: trailing-whitespace
exclude: "snapshots|docs/api.md"
- id: check-merge-conflict
Expand All @@ -15,10 +14,4 @@ repos:
- id: check-case-conflict
- id: mixed-line-ending
- id: detect-private-key
- id: check-ast
- id: check-builtin-literals
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: name-tests-test
args: [ "--pytest-test-first" ]
- id: requirements-txt-fixer
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

22 changes: 3 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
FROM cgr.dev/chainguard/python:latest-dev@sha256:40b3a19b7e2a50824b1ff32d61ae5f59af1b0de67f7bb8e56f5804bace0d94b7 AS builder

ARG dist_file

WORKDIR /app

COPY "dist/${dist_file}" "/home/nonroot/${dist_file}"

RUN --mount=type=secret,id=requirements,dst=/home/nonroot/requirements.txt,uid=65532,gid=65532 \
pip install --no-cache-dir -r "/home/nonroot/requirements.txt"
RUN pip install --no-cache-dir "/home/nonroot/${dist_file}"

FROM cgr.dev/chainguard/python:latest@sha256:5f16431f56f330925a9c8f5168b31ca65f603de15b127b376f8532bab11583c0

WORKDIR /app

COPY --from=builder /home/nonroot/.local/lib/python3.12/site-packages /home/nonroot/.local/lib/python3.12/site-packages

ENTRYPOINT [ "python", "-m", "sophrosyne.main", "run" ]
FROM cgr.dev/chainguard/glibc-dynamic:latest
COPY --chown=noneroot:noneroot dist/sophrosyne /usr/bin/
ENTRYPOINT ["/usr/bin/sophrosyne"]
Loading

0 comments on commit 134f1a6

Please sign in to comment.