Преглед изворни кода

refactor: Project directories (#541)

James Read пре 1 година
родитељ
комит
ff31abe66c
76 измењених фајлова са 100 додато и 73 уклоњено
  1. 8 2
      .github/workflows/build-buf.yml
  2. 4 4
      .github/workflows/build-snapshot.yml
  3. 1 1
      .github/workflows/build-tag.yml
  4. 1 1
      .github/workflows/codeql-analysis.yml
  5. 1 1
      .github/workflows/codestyle.yml
  6. 5 5
      .gitignore
  7. 4 4
      .goreleaser.yml
  8. 11 41
      Makefile
  9. 0 3
      generate.go
  10. 2 2
      integration-tests/runner.mjs
  11. 3 3
      proto/buf.gen.yaml
  12. 5 3
      proto/buf.lock
  13. 1 1
      proto/buf.yaml
  14. 1 1
      service/.air.toml
  15. 48 0
      service/Makefile
  16. 3 0
      service/generate.go
  17. 0 0
      service/go.mod
  18. 0 0
      service/go.sum
  19. 0 0
      service/internal/acl/acl.go
  20. 0 0
      service/internal/config/config.go
  21. 0 0
      service/internal/config/config_helpers.go
  22. 0 0
      service/internal/config/config_helpers_test.go
  23. 0 0
      service/internal/config/config_reloader.go
  24. 0 0
      service/internal/config/config_test.go
  25. 0 0
      service/internal/config/emoji.go
  26. 0 0
      service/internal/config/emoji_test.go
  27. 0 0
      service/internal/config/sanitize.go
  28. 0 0
      service/internal/config/sanitize_test.go
  29. 0 0
      service/internal/cors/cors.go
  30. 0 0
      service/internal/cors/cors_test.go
  31. 0 0
      service/internal/entityfiles/entityfiles.go
  32. 0 0
      service/internal/executor/arguments.go
  33. 0 0
      service/internal/executor/arguments_test.go
  34. 0 0
      service/internal/executor/executor.go
  35. 0 0
      service/internal/executor/executor_actions.go
  36. 0 0
      service/internal/executor/executor_test.go
  37. 0 0
      service/internal/executor/executor_unix.go
  38. 0 0
      service/internal/executor/executor_windows.go
  39. 0 0
      service/internal/filehelper/file_change_notify.go
  40. 0 0
      service/internal/filehelper/file_touch.go
  41. 0 0
      service/internal/filehelper/file_write.go
  42. 0 0
      service/internal/grpcapi/grpcApi.go
  43. 0 0
      service/internal/grpcapi/grpcApiActions.go
  44. 0 0
      service/internal/grpcapi/grpcApiDashboard.go
  45. 0 0
      service/internal/grpcapi/grpcApiDashboardEntities.go
  46. 0 0
      service/internal/grpcapi/grpcApi_test.go
  47. 0 0
      service/internal/grpcapi/local_user_login.go
  48. 0 0
      service/internal/httpservers/httpServer.go
  49. 0 0
      service/internal/httpservers/prometheus.go
  50. 0 0
      service/internal/httpservers/restapi.go
  51. 0 0
      service/internal/httpservers/restapi_auth.go
  52. 0 0
      service/internal/httpservers/restapi_auth_jwt.go
  53. 0 0
      service/internal/httpservers/restapi_auth_jwt_test.go
  54. 0 0
      service/internal/httpservers/restapi_auth_local.go
  55. 0 0
      service/internal/httpservers/restapi_auth_oauth2.go
  56. 0 0
      service/internal/httpservers/restapi_auth_oauth2_providers.go
  57. 0 0
      service/internal/httpservers/restapi_test.go
  58. 0 0
      service/internal/httpservers/singleFrontend.go
  59. 0 0
      service/internal/httpservers/webuiServer.go
  60. 1 1
      service/internal/httpservers/webuiServer_test.go
  61. 0 0
      service/internal/installationinfo/buildinfo.go
  62. 0 0
      service/internal/installationinfo/init.go
  63. 0 0
      service/internal/installationinfo/runtimeinfo.go
  64. 0 0
      service/internal/installationinfo/sosreport.go
  65. 0 0
      service/internal/oncalendarfile/calendar.go
  66. 0 0
      service/internal/oncron/cron.go
  67. 0 0
      service/internal/onfileindir/fileindir.go
  68. 0 0
      service/internal/onstartup/startup.go
  69. 0 0
      service/internal/stringvariables/entities.go
  70. 0 0
      service/internal/stringvariables/entities_test.go
  71. 0 0
      service/internal/stringvariables/map.go
  72. 0 0
      service/internal/stringvariables/map_test.go
  73. 0 0
      service/internal/updatecheck/updateCheck.go
  74. 0 0
      service/internal/websocket/websocket.go
  75. 1 0
      service/main.go
  76. 0 0
      service/tools.go

+ 8 - 2
.github/workflows/build-buf.yml

@@ -1,6 +1,9 @@
 name: Buf CI
 on:
   push:
+    paths:
+      - 'proto/**'
+
   pull_request:
     types: [opened, synchronize, reopened, labeled, unlabeled]
   delete:
@@ -16,13 +19,16 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version-file: 'go.mod'
+          go-version-file: 'service/go.mod'
           cache: true
 
       - name: grpc
         run: make -w grpc
 
-      - uses: bufbuild/buf-action@v1
+      - name: make service
+        run: make -w service
+
+      - uses: bufbuild/buf-action@v1.1.0
         with:
           token: ${{ secrets.BUF_TOKEN }}
           # Change setup_only to true if you only want to set up the Action and not execute other commands.

+ 4 - 4
.github/workflows/build-snapshot.yml

@@ -31,7 +31,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version-file: 'go.mod'
+          go-version-file: 'service/go.mod'
           cache: true
 
       - name: Print go version
@@ -40,14 +40,14 @@ jobs:
       - name: grpc
         run: make -w grpc
 
-      - name: make daemon
-        run: make -w daemon-compile-x64-lin
+      - name: make service
+        run: make -w service
 
       - name: make webui
         run: make -w webui-dist
 
       - name: unit tests
-        run: make -w daemon-unittests
+        run: make -w service-unittests
 
       - name: integration tests
         run: cd integration-tests && make -w

+ 1 - 1
.github/workflows/build-tag.yml

@@ -31,7 +31,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version-file: 'go.mod'
+          go-version-file: 'service/go.mod'
           cache: true
 
       - name: Print go version

+ 1 - 1
.github/workflows/codeql-analysis.yml

@@ -47,7 +47,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version-file: 'go.mod'
+          go-version-file: 'service/go.mod'
           cache: true
 
       - name: grpc

+ 1 - 1
.github/workflows/codestyle.yml

@@ -21,7 +21,7 @@ jobs:
       - name: Setup Go
         uses: actions/setup-go@v5
         with:
-          go-version-file: 'go.mod'
+          go-version-file: 'service/go.mod'
           cache: true
 
       - name: Print go version

+ 5 - 5
.gitignore

@@ -1,10 +1,10 @@
 **/*.swp
 **/*.swo
-gen/
-/OliveTin
-/OliveTin.armhf
-/OliveTin.exe
-reports
+service/gen/
+service/OliveTin
+service/OliveTin.armhf
+service/OliveTin.exe
+service/reports
 releases/
 dist/
 installation-id.txt

+ 4 - 4
.goreleaser.yml

@@ -2,12 +2,14 @@ project_name: OliveTin
 version: 2
 before:
   hooks:
-    - go mod download
-    - go generate ./...
+    - make service-prep
 
 builds:
   - env:
       - CGO_ENABLED=0
+    binary: OliveTin
+    main: main.go
+    dir: service
     goos:
       - linux
       - windows
@@ -25,8 +27,6 @@ builds:
       - 6
       - 7
 
-    main: cmd/OliveTin/main.go
-
     ignore:
       - goos: darwin
         goarch: arm # Mac does not work on [32bit] arm

+ 11 - 41
Makefile

@@ -2,52 +2,22 @@ define delete-files
 	python -c "import shutil;shutil.rmtree('$(1)', ignore_errors=True)"
 endef
 
-compile: daemon-compile-currentenv
+service:
+	$(MAKE) -wC service
 
-daemon-compile-currentenv:
-	go build github.com/OliveTin/OliveTin/cmd/OliveTin
-
-daemon-compile-armhf:
-	go env -w GOARCH=arm GOARM=6
-	go build -o OliveTin.armhf github.com/OliveTin/OliveTin/cmd/OliveTin
-	go env -u GOARCH GOARM
-
-daemon-compile-x64-lin:
-	go env -w GOOS=linux
-	go build -o OliveTin github.com/OliveTin/OliveTin/cmd/OliveTin
-	go env -u GOOS
-
-daemon-compile-x64-win:
-	go env -w GOOS=windows GOARCH=amd64
-	go build -o OliveTin.exe github.com/OliveTin/OliveTin/cmd/OliveTin
-	go env -u GOOS GOARCH
-
-daemon-compile: daemon-compile-armhf daemon-compile-x64-lin daemon-compile-x64-win
-
-daemon-codestyle:
-	go fmt ./...
-	go vet ./...
-	gocyclo -over 4 cmd internal
-	gocritic check ./...
-
-daemon-unittests:
-	$(call delete-files,reports)
-	mkdir reports
-	go test ./... -coverprofile reports/unittests.out
-	go tool cover -html=reports/unittests.out -o reports/unittests.html
+service-prep:
+	$(MAKE) -wC service prep
 
+service-unittests:
+	$(MAKE) -wC service unittests
 
 it:
-	cd integration-tests && make
+	$(MAKE) -wC integration-tests
 
 go-tools:
-	go install "github.com/bufbuild/buf/cmd/buf"
-	go install "github.com/fzipp/gocyclo/cmd/gocyclo"
-	go install "github.com/go-critic/go-critic/cmd/gocritic"
-	go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
-	go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
-	go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
-	go install "google.golang.org/protobuf/cmd/protoc-gen-go"
+	$(MAKE) -wC service go-tools
+
+proto: grpc
 
 grpc: go-tools
 	$(MAKE) -wC proto
@@ -98,4 +68,4 @@ clean:
 	$(call delete-files,reports)
 	$(call delete-files,gen)
 
-.PHONY: grpc
+.PHONY: grpc proto service

+ 0 - 3
generate.go

@@ -1,3 +0,0 @@
-//go:generate make grpc
-
-package main

+ 2 - 2
integration-tests/runner.mjs

@@ -35,10 +35,10 @@ class OliveTinTestRunnerStartLocalProcess extends OliveTinTestRunner {
   async start (cfg) {
     let stdout = ""
     let stderr = ""
-    
+
     console.log("      OliveTin starting local process...")
 
-    this.ot = spawn('./../OliveTin', ['-configdir', 'configs/' + cfg + '/'])
+    this.ot = spawn('./../service/OliveTin', ['-configdir', 'configs/' + cfg + '/'])
 
     let logStdout = false
 

+ 3 - 3
proto/buf.gen.yaml

@@ -1,15 +1,15 @@
 version: v1
 plugins:
   - name: go
-    out: ../gen/grpc/
+    out: ../service/gen/grpc/
     opt: paths=source_relative
 
   - name: go-grpc
-    out: ../gen/grpc/
+    out: ../service/gen/grpc/
     opt: paths=source_relative,require_unimplemented_servers=false
 
   - name: grpc-gateway
-    out: ../gen/grpc/
+    out: ../service/gen/grpc/
     opt: paths=source_relative
 
 #  - name: swagger

+ 5 - 3
proto/buf.lock

@@ -1,6 +1,8 @@
 # Generated by buf. DO NOT EDIT.
-version: v2
+version: v1
 deps:
-  - name: buf.build/googleapis/googleapis
+  - remote: buf.build
+    owner: googleapis
+    repository: googleapis
     commit: 751cbe31638d43a9bfb6162cd2352e67
-    digest: b5:51ba5c31f244fd74420f0e66d13f2b5dd6024dcfe1a29dc45bd8f6e61c1444c828b9add9e7dd25a4513ebbee8097a970e0712a2e2cd955c2d60cf8905204f51a
+    digest: shake256:87f55470d9d124e2d1dedfe0231221f4ed7efbc55bc5268917c678e2d9b9c41573a7f9a557f6d8539044524d9fc5ca8fbb7db05eb81379d168285d76b57eb8a4

+ 1 - 1
proto/buf.yaml

@@ -1,4 +1,4 @@
-version: v2
+version: v1
 deps:
   - buf.build/googleapis/googleapis
 lint:

+ 1 - 1
.air.toml → service/.air.toml

@@ -5,7 +5,7 @@ tmp_dir = "tmp"
 [build]
   args_bin = []
   bin = "./OliveTin"
-  cmd = "go build -o OliveTin github.com/OliveTin/OliveTin/cmd/OliveTin"
+  cmd = "go build -o OliveTin"
   delay = 1
   exclude_dir = ["assets", "tmp", "vendor", "testdata", "webui.dev", "webui"]
   exclude_file = []

+ 48 - 0
service/Makefile

@@ -0,0 +1,48 @@
+define delete-files
+	python -c "import shutil;shutil.rmtree('$(1)', ignore_errors=True)"
+endef
+
+compile-currentenv:
+	go build
+
+prep:
+	go mod download
+	go generate ./...
+
+compile-armhf:
+	go env -w GOARCH=arm GOARM=6
+	go build -o OliveTin.armhf
+	go env -u GOARCH GOARM
+
+compile-x64-lin:
+	go env -w GOOS=linux
+	go build -o OliveTin
+	go env -u GOOS
+
+compile-x64-win:
+	go env -w GOOS=windows GOARCH=amd64
+	go build -o OliveTin.exe
+	go env -u GOOS GOARCH
+
+compile: compile-armhf compile-x64-lin compile-x64-win
+
+codestyle:
+	go fmt ./...
+	go vet ./...
+	gocyclo -over 4 internal
+	gocritic check ./...
+
+unittests:
+	$(call delete-files,reports)
+	mkdir reports
+	go test ./... -coverprofile reports/unittests.out
+	go tool cover -html=reports/unittests.out -o reports/unittests.html
+
+go-tools:
+	go install "github.com/bufbuild/buf/cmd/buf"
+	go install "github.com/fzipp/gocyclo/cmd/gocyclo"
+	go install "github.com/go-critic/go-critic/cmd/gocritic"
+	go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
+	go install "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
+	go install "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
+	go install "google.golang.org/protobuf/cmd/protoc-gen-go"

+ 3 - 0
service/generate.go

@@ -0,0 +1,3 @@
+//go:generate make -wC ../
+
+package main

+ 0 - 0
go.mod → service/go.mod


+ 0 - 0
go.sum → service/go.sum


+ 0 - 0
internal/acl/acl.go → service/internal/acl/acl.go


+ 0 - 0
internal/config/config.go → service/internal/config/config.go


+ 0 - 0
internal/config/config_helpers.go → service/internal/config/config_helpers.go


+ 0 - 0
internal/config/config_helpers_test.go → service/internal/config/config_helpers_test.go


+ 0 - 0
internal/config/config_reloader.go → service/internal/config/config_reloader.go


+ 0 - 0
internal/config/config_test.go → service/internal/config/config_test.go


+ 0 - 0
internal/config/emoji.go → service/internal/config/emoji.go


+ 0 - 0
internal/config/emoji_test.go → service/internal/config/emoji_test.go


+ 0 - 0
internal/config/sanitize.go → service/internal/config/sanitize.go


+ 0 - 0
internal/config/sanitize_test.go → service/internal/config/sanitize_test.go


+ 0 - 0
internal/cors/cors.go → service/internal/cors/cors.go


+ 0 - 0
internal/cors/cors_test.go → service/internal/cors/cors_test.go


+ 0 - 0
internal/entityfiles/entityfiles.go → service/internal/entityfiles/entityfiles.go


+ 0 - 0
internal/executor/arguments.go → service/internal/executor/arguments.go


+ 0 - 0
internal/executor/arguments_test.go → service/internal/executor/arguments_test.go


+ 0 - 0
internal/executor/executor.go → service/internal/executor/executor.go


+ 0 - 0
internal/executor/executor_actions.go → service/internal/executor/executor_actions.go


+ 0 - 0
internal/executor/executor_test.go → service/internal/executor/executor_test.go


+ 0 - 0
internal/executor/executor_unix.go → service/internal/executor/executor_unix.go


+ 0 - 0
internal/executor/executor_windows.go → service/internal/executor/executor_windows.go


+ 0 - 0
internal/filehelper/file_change_notify.go → service/internal/filehelper/file_change_notify.go


+ 0 - 0
internal/filehelper/file_touch.go → service/internal/filehelper/file_touch.go


+ 0 - 0
internal/filehelper/file_write.go → service/internal/filehelper/file_write.go


+ 0 - 0
internal/grpcapi/grpcApi.go → service/internal/grpcapi/grpcApi.go


+ 0 - 0
internal/grpcapi/grpcApiActions.go → service/internal/grpcapi/grpcApiActions.go


+ 0 - 0
internal/grpcapi/grpcApiDashboard.go → service/internal/grpcapi/grpcApiDashboard.go


+ 0 - 0
internal/grpcapi/grpcApiDashboardEntities.go → service/internal/grpcapi/grpcApiDashboardEntities.go


+ 0 - 0
internal/grpcapi/grpcApi_test.go → service/internal/grpcapi/grpcApi_test.go


+ 0 - 0
internal/grpcapi/local_user_login.go → service/internal/grpcapi/local_user_login.go


+ 0 - 0
internal/httpservers/httpServer.go → service/internal/httpservers/httpServer.go


+ 0 - 0
internal/httpservers/prometheus.go → service/internal/httpservers/prometheus.go


+ 0 - 0
internal/httpservers/restapi.go → service/internal/httpservers/restapi.go


+ 0 - 0
internal/httpservers/restapi_auth.go → service/internal/httpservers/restapi_auth.go


+ 0 - 0
internal/httpservers/restapi_auth_jwt.go → service/internal/httpservers/restapi_auth_jwt.go


+ 0 - 0
internal/httpservers/restapi_auth_jwt_test.go → service/internal/httpservers/restapi_auth_jwt_test.go


+ 0 - 0
internal/httpservers/restapi_auth_local.go → service/internal/httpservers/restapi_auth_local.go


+ 0 - 0
internal/httpservers/restapi_auth_oauth2.go → service/internal/httpservers/restapi_auth_oauth2.go


+ 0 - 0
internal/httpservers/restapi_auth_oauth2_providers.go → service/internal/httpservers/restapi_auth_oauth2_providers.go


+ 0 - 0
internal/httpservers/restapi_test.go → service/internal/httpservers/restapi_test.go


+ 0 - 0
internal/httpservers/singleFrontend.go → service/internal/httpservers/singleFrontend.go


+ 0 - 0
internal/httpservers/webuiServer.go → service/internal/httpservers/webuiServer.go


+ 1 - 1
internal/httpservers/webuiServer_test.go → service/internal/httpservers/webuiServer_test.go

@@ -14,5 +14,5 @@ func TestGetWebuiDir(t *testing.T) {
 
 	dir := findWebuiDir()
 
-	assert.Equal(t, "./webui", dir, "Finding the webui dir")
+	assert.Equal(t, "../webui/", dir, "Finding the webui dir")
 }

+ 0 - 0
internal/installationinfo/buildinfo.go → service/internal/installationinfo/buildinfo.go


+ 0 - 0
internal/installationinfo/init.go → service/internal/installationinfo/init.go


+ 0 - 0
internal/installationinfo/runtimeinfo.go → service/internal/installationinfo/runtimeinfo.go


+ 0 - 0
internal/installationinfo/sosreport.go → service/internal/installationinfo/sosreport.go


+ 0 - 0
internal/oncalendarfile/calendar.go → service/internal/oncalendarfile/calendar.go


+ 0 - 0
internal/oncron/cron.go → service/internal/oncron/cron.go


+ 0 - 0
internal/onfileindir/fileindir.go → service/internal/onfileindir/fileindir.go


+ 0 - 0
internal/onstartup/startup.go → service/internal/onstartup/startup.go


+ 0 - 0
internal/stringvariables/entities.go → service/internal/stringvariables/entities.go


+ 0 - 0
internal/stringvariables/entities_test.go → service/internal/stringvariables/entities_test.go


+ 0 - 0
internal/stringvariables/map.go → service/internal/stringvariables/map.go


+ 0 - 0
internal/stringvariables/map_test.go → service/internal/stringvariables/map_test.go


+ 0 - 0
internal/updatecheck/updateCheck.go → service/internal/updatecheck/updateCheck.go


+ 0 - 0
internal/websocket/websocket.go → service/internal/websocket/websocket.go


+ 1 - 0
cmd/OliveTin/main.go → service/main.go

@@ -108,6 +108,7 @@ func initViperConfig(configDir string) {
 	viper.SetConfigName("config.yaml")
 	viper.SetConfigType("yaml")
 	viper.AddConfigPath(configDir)
+	viper.AddConfigPath("../")
 	viper.AddConfigPath("/config") // For containers.
 	viper.AddConfigPath("/etc/OliveTin/")
 

+ 0 - 0
tools.go → service/tools.go