Initial commit

This commit is contained in:
Piotr Rogowski 2022-11-05 15:13:58 +01:00
commit a34e2611e3
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
15 changed files with 3115 additions and 0 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: karniv00l

7
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

27
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,27 @@
on:
push:
tags:
- '*'
jobs:
release-linux-amd64:
name: release linux/amd64
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '>=1.19.3'
cache: true
- name: Go release
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

37
.gitignore vendored Normal file
View File

@ -0,0 +1,37 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
# mac
.DS_Store
# pb_data and backups
/backup
/pb_data
/pb_data.zip
/pb_data.tar.gz
# build
cloud-backend
cloud-backend.exe
# docker overrides
docker-compose.override.yml

28
.goreleaser.yaml Normal file
View File

@ -0,0 +1,28 @@
project_name: cloud-backend
before:
hooks:
- go mod tidy
builds:
- main: ./main.go
binary: cloud-backend
ldflags:
- -s -w -X github.com/hyper-tuner/cloud-backend.Version={{ .Version }}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- arm
goarm:
- "7"
ignore:
- goos: windows
goarch: arm
- goos: darwin
goarch: arm

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"cSpell.words": [
"pocketbase"
]
}

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Piotr Rogowski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

78
README.md Normal file
View File

@ -0,0 +1,78 @@
# HyperTuner Cloud backend
This is the backend for the HyperTuner Cloud. It is based on a great [PocketBase](https://pocketbase.io) (Open Source backend in 1 file).
This repository contains:
- The source code of the HyperTuner Cloud backend that extends PocketBase.
- database schema
- configurations
- deployment scripts / Docker and docker compose files
- migration scripts and guides
## Setting up your instance
Use provider Docker files from the `/docker` directory or just grab the binary from the [Releases](https://github.com/hyper-tuner/cloud-backend) page:
```bash
./cloud-backend serve
```
This will create `pb_data` directory where all the data will be stored (SQLite, uploaded files and metadata).
Now you can access the admin UI at: [https://your-instance.com/_/](https://your-instance.com/_/).
### Application name and URL
Located in admin UI: `Settings -> Application`.
- `Application name` - the name of your application
- `Application URL` - the URL of your **frontend** application
### Mail settings
Located in the admin UI: `Settings -> Mailer settings`.
- Verification email **ACTION URL**:
```bash
{APP_URL}/#/auth/email-verification/{TOKEN}
```
- Password reset **ACTION URL**:
```bash
{APP_URL}/#/auth/reset-password-confirmation/{TOKEN}
```
### OAuth2 settings
For every OAuth2 provider, you need to set the following redirect URLs:
```bash
https://{FRONTEND-URL}/?redirect=oauth&provider=google
https://{FRONTEND-URL}/?redirect=oauth&provider=github
https://{FRONTEND-URL}/?redirect=oauth&provider=facebook
```
### Loading schema
Copy/load `pb_schema.json` to `Settings -> Sync -> Import collections` in the admin UI.
## Building from source
```bash
go build
```
## Support this project
[GitHub Sponsors](https://github.com/sponsors/karniv00l)
## Discord server
[![HyperTuner Discord server](https://dcbadge.vercel.app/api/server/HdxznPUA)](https://discord.gg/HdxznPUA)
## License
[MIT](https://github.com/hyper-tuner/cloud-backend/blob/master/LICENSE)

1
docker/.dockerignore Normal file
View File

@ -0,0 +1 @@
pb_data

5
docker/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM alpine:latest
ARG VERSION=1.0.0
ADD https://github.com/hyper-tuner/cloud-backend/releases/download/v${VERSION}/cloud-backend_${VERSION}_linux_amd64.tar.gz /cloud-backend

13
docker/docker-compose.yml Normal file
View File

@ -0,0 +1,13 @@
version: '3.1'
# This is just an example
services:
cloud-backend:
platform: linux/x86_64
build: .
restart: unless-stopped
command: ["/cloud-backend/cloud-backend", "serve", "--http=0.0.0.0:8080"]
volumes:
- ./pb_data:/cloud-backend/pb_data
ports:
- 80:8080

85
go.mod Normal file
View File

@ -0,0 +1,85 @@
module hyper-tuner/cloud-backend
go 1.19
require github.com/pocketbase/pocketbase v0.8.0-rc2.0.20221105112208-a2abeb872aca
require (
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/aws/aws-sdk-go v1.44.130 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.9 // indirect
github.com/aws/aws-sdk-go-v2/config v1.17.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.23 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.26 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.16 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.10 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.20 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.19 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.19 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.29.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.25 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.17.1 // indirect
github.com/aws/smithy-go v1.13.4 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/domodwyer/mailyak/v3 v3.3.4 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
github.com/ganigeorgiev/fexpr v0.1.1 // indirect
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/pocketbase/dbx v1.7.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20220927061507-ef77025ab5aa // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
gocloud.dev v0.27.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/image v0.1.0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.102.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.21.4 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.19.4 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
)

2361
go.sum Normal file

File diff suppressed because it is too large Load Diff

15
main.go Normal file
View File

@ -0,0 +1,15 @@
package main
import (
"log"
"github.com/pocketbase/pocketbase"
)
func main() {
app := pocketbase.New()
if err := app.Start(); err != nil {
log.Fatal(err)
}
}

431
pb_schema.json Normal file
View File

@ -0,0 +1,431 @@
[
{
"id": "5djmpehuiigg06b",
"name": "tunes",
"type": "base",
"system": false,
"schema": [
{
"id": "io2qgnvc",
"name": "author",
"type": "relation",
"system": false,
"required": true,
"unique": false,
"options": {
"maxSelect": 1,
"collectionId": "systemprofiles0",
"cascadeDelete": false
}
},
{
"id": "pkq4wfcj",
"name": "tuneId",
"type": "text",
"system": false,
"required": true,
"unique": true,
"options": {
"min": 5,
"max": 255,
"pattern": ""
}
},
{
"id": "jcjunqhl",
"name": "signature",
"type": "text",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 3,
"max": 255,
"pattern": ""
}
},
{
"id": "g9b17t9y",
"name": "vehicleName",
"type": "text",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 2,
"max": 255,
"pattern": ""
}
},
{
"id": "w7qssd4t",
"name": "engineMake",
"type": "text",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 2,
"max": 255,
"pattern": ""
}
},
{
"id": "h47ir1bi",
"name": "engineCode",
"type": "text",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 2,
"max": 255,
"pattern": ""
}
},
{
"id": "frqzy24e",
"name": "displacement",
"type": "number",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 0,
"max": 100
}
},
{
"id": "j1asw8n1",
"name": "cylindersCount",
"type": "number",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 0,
"max": 16
}
},
{
"id": "0x8poyze",
"name": "aspiration",
"type": "select",
"system": false,
"required": true,
"unique": false,
"options": {
"maxSelect": 1,
"values": [
"na",
"turbocharged",
"supercharged"
]
}
},
{
"id": "ssd9iccu",
"name": "compression",
"type": "number",
"system": false,
"required": false,
"unique": false,
"options": {
"min": 0,
"max": 100
}
},
{
"id": "whk0u6fg",
"name": "fuel",
"type": "text",
"system": false,
"required": false,
"unique": false,
"options": {
"min": null,
"max": 255,
"pattern": ""
}
},
{
"id": "4ydhmn21",
"name": "ignition",
"type": "text",
"system": false,
"required": false,
"unique": false,
"options": {
"min": null,
"max": 255,
"pattern": ""
}
},
{
"id": "lti2l0im",
"name": "injectorsSize",
"type": "number",
"system": false,
"required": false,
"unique": false,
"options": {
"min": 0,
"max": 100000
}
},
{
"id": "pmt4jrhm",
"name": "year",
"type": "number",
"system": false,
"required": false,
"unique": false,
"options": {
"min": null,
"max": 2222
}
},
{
"id": "s9fjthhs",
"name": "hp",
"type": "number",
"system": false,
"required": false,
"unique": false,
"options": {
"min": 0,
"max": 100000
}
},
{
"id": "s4csjkpt",
"name": "stockHp",
"type": "number",
"system": false,
"required": false,
"unique": false,
"options": {
"min": 0,
"max": 100000
}
},
{
"id": "hfpkctpl",
"name": "readme",
"type": "text",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 5,
"max": 3000,
"pattern": ""
}
},
{
"id": "d5vpizsr",
"name": "textSearch",
"type": "text",
"system": false,
"required": true,
"unique": false,
"options": {
"min": 1,
"max": 2048,
"pattern": ""
}
},
{
"id": "1bjweixt",
"name": "visibility",
"type": "select",
"system": false,
"required": true,
"unique": false,
"options": {
"maxSelect": 1,
"values": [
"public",
"unlisted"
]
}
},
{
"id": "roqbws6u",
"name": "tuneFile",
"type": "file",
"system": false,
"required": true,
"unique": false,
"options": {
"maxSelect": 1,
"maxSize": 5242880,
"mimeTypes": [
"application/gzip",
"application/octet-stream"
],
"thumbs": []
}
},
{
"id": "59syvgnj",
"name": "customIniFile",
"type": "file",
"system": false,
"required": false,
"unique": false,
"options": {
"maxSelect": 1,
"maxSize": 5242880,
"mimeTypes": [
"application/gzip",
"application/octet-stream"
],
"thumbs": []
}
},
{
"id": "gzccot0l",
"name": "logFiles",
"type": "file",
"system": false,
"required": false,
"unique": false,
"options": {
"maxSelect": 5,
"maxSize": 5242880,
"mimeTypes": [
"application/gzip",
"application/octet-stream"
],
"thumbs": []
}
},
{
"id": "2z0i9ttc",
"name": "toothLogFiles",
"type": "file",
"system": false,
"required": false,
"unique": false,
"options": {
"maxSelect": 5,
"maxSize": 5242880,
"mimeTypes": [
"application/gzip",
"application/octet-stream"
],
"thumbs": []
}
}
],
"listRule": "visibility = \"public\" || (visibility = \"unlisted\" && @request.query.page = \"1\" && @request.query.perPage = \"1\") || (visibility = \"unlisted\" && @request.auth.id = author)",
"viewRule": null,
"createRule": "@request.auth.verified = true",
"updateRule": "@request.auth.id = author",
"deleteRule": null,
"options": {}
},
{
"id": "9eif9v40b0uw9l8",
"name": "iniFiles",
"type": "base",
"system": false,
"schema": [
{
"id": "h9yfwmvx",
"name": "signature",
"type": "text",
"system": false,
"required": true,
"unique": true,
"options": {
"min": 3,
"max": 255,
"pattern": ""
}
},
{
"id": "z3e1a5cl",
"name": "file",
"type": "file",
"system": false,
"required": true,
"unique": false,
"options": {
"maxSelect": 1,
"maxSize": 5242880,
"mimeTypes": [
"application/gzip",
"application/octet-stream"
],
"thumbs": []
}
},
{
"id": "t5uayom3",
"name": "ecosystem",
"type": "select",
"system": false,
"required": true,
"unique": false,
"options": {
"maxSelect": 1,
"values": [
"speeduino",
"rusefi"
]
}
}
],
"listRule": "",
"viewRule": null,
"createRule": null,
"updateRule": null,
"deleteRule": null,
"options": {}
},
{
"id": "systemprofiles0",
"name": "users",
"type": "auth",
"system": false,
"schema": [
{
"id": "pbfieldavatar",
"name": "avatar",
"type": "file",
"system": false,
"required": false,
"unique": false,
"options": {
"maxSelect": 1,
"maxSize": 5242880,
"mimeTypes": [
"image/jpg",
"image/jpeg",
"image/png",
"image/svg+xml",
"image/gif"
],
"thumbs": null
}
}
],
"listRule": null,
"viewRule": "",
"createRule": "",
"updateRule": "id = @request.auth.id",
"deleteRule": null,
"options": {
"allowEmailAuth": true,
"allowOAuth2Auth": true,
"allowUsernameAuth": false,
"exceptEmailDomains": null,
"manageRule": null,
"minPasswordLength": 8,
"onlyEmailDomains": null,
"requireEmail": true
}
}
]