docs: update contributing

This commit is contained in:
Stavros
2025-03-10 18:47:54 +02:00
parent ec67ea3807
commit 9dd9829058
5 changed files with 38 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
# Contributing # Contributing
Contributing is relatively easy. Contributing is relatively easy, you just need to follow the steps carefully and you will be up and running with a development server in less than 5 minutes.
## Requirements ## Requirements
@@ -8,6 +8,7 @@ Contributing is relatively easy.
- Golang v1.23.2 and above - Golang v1.23.2 and above
- Git - Git
- Docker - Docker
- Make (not required but it will make your life easier)
## Cloning the repository ## Cloning the repository
@@ -20,48 +21,42 @@ cd tinyauth
## Install requirements ## Install requirements
Now it's time to install the requirements, firstly the Go ones: To install the requirements simply run:
```sh ```sh
go mod download make requirements
``` ```
And now the site ones: It will download all the node packages required by the frontend as well as all the go requirements.
```sh
cd site
bun i
```
## Developing locally ## Developing locally
In order to develop the app locally you need to build the frontend and copy it to the assets folder in order for Go to embed it and host it. In order to build the frontend run: In order to develop the app you need to firstly compile the frontend and then the go app. To avoid running the same commands over and over again you can just run:
```sh ```sh
cd site make run
bun run build
cd ..
``` ```
Copy it to the assets folder: This is the equivalent of `go run main.go`, if you would like to build a binary run:
```sh ```sh
rm -rf internal/assets/dist make build
cp -r site/dist internal/assets/dist
``` ```
Finally either run the app with: To avoid rebuilding the frontend every time you can run:
```sh ```sh
go run main.go make run-no-web
``` ```
Or build it with: And:
```sh ```sh
go build make build-no-web
``` ```
For these commands to succeed you must have built the frontend at least once.
> [!WARNING] > [!WARNING]
> Make sure you have set the environment variables when running outside of docker else the app will fail. > Make sure you have set the environment variables when running outside of docker else the app will fail.
@@ -70,8 +65,8 @@ go build
My recommended development method is docker so I can test that both my image works and that the app responds correctly to traefik. In my setup I have set these two DNS records in my DNS server: My recommended development method is docker so I can test that both my image works and that the app responds correctly to traefik. In my setup I have set these two DNS records in my DNS server:
``` ```
*.dev.local -> 127.0.0.1 *.dev.example.com -> 127.0.0.1
dev.local -> 127.0.0.1 dev.example.com -> 127.0.0.1
``` ```
Then I can just make sure the domains are correct in the example docker compose file and do: Then I can just make sure the domains are correct in the example docker compose file and do:
@@ -79,3 +74,6 @@ Then I can just make sure the domains are correct in the example docker compose
```sh ```sh
docker compose -f docker-compose.dev.yml up --build docker compose -f docker-compose.dev.yml up --build
``` ```
> [!WARNING]
> I would recommend copying the example `docker-compose.dev.yml` into a `docker-compose.test.yml` file, so as you don't accidentally commit any sensitive information.

View File

@@ -2,6 +2,11 @@
web: web:
cd site; bun run build cd site; bun run build
# Requirements
requirements:
cd site; bun install
go mod tidy
# Copy site assets # Copy site assets
assets: web assets: web
rm -rf internal/assets/dist rm -rf internal/assets/dist
@@ -12,6 +17,10 @@ assets: web
run: assets run: assets
go run main.go go run main.go
# Run development binary without compiling the frontend
run-skip-web:
go run main.go
# Test # Test
test: test:
go test ./... go test ./...
@@ -20,6 +29,6 @@ test:
build: assets build: assets
go build -o tinyauth go build -o tinyauth
# Build no site # Build the binary without compiling the frontend
build-skip-web: build-skip-web:
go build -o tinyauth go build -o tinyauth

View File

@@ -13,7 +13,7 @@ services:
image: traefik/whoami:latest image: traefik/whoami:latest
labels: labels:
traefik.enable: true traefik.enable: true
traefik.http.routers.nginx.rule: Host(`whoami.dev.local`) traefik.http.routers.nginx.rule: Host(`whoami.dev.example.com`)
traefik.http.services.nginx.loadbalancer.server.port: 80 traefik.http.services.nginx.loadbalancer.server.port: 80
traefik.http.routers.nginx.middlewares: tinyauth traefik.http.routers.nginx.middlewares: tinyauth
@@ -24,11 +24,11 @@ services:
dockerfile: Dockerfile dockerfile: Dockerfile
environment: environment:
- SECRET=some-random-32-chars-string - SECRET=some-random-32-chars-string
- APP_URL=http://tinyauth.dev.local - APP_URL=http://tinyauth.dev.example.com
- USERS=user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u # user:password - USERS=user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u # user:password
labels: labels:
traefik.enable: true traefik.enable: true
traefik.http.routers.tinyauth.rule: Host(`tinyauth.dev.local`) traefik.http.routers.tinyauth.rule: Host(`tinyauth.dev.example.com`)
traefik.http.services.tinyauth.loadbalancer.server.port: 3000 traefik.http.services.tinyauth.loadbalancer.server.port: 3000
traefik.http.middlewares.tinyauth.forwardauth.address: http://tinyauth:3000/api/auth/traefik traefik.http.middlewares.tinyauth.forwardauth.address: http://tinyauth:3000/api/auth/traefik
traefik.http.middlewares.tinyauth.forwardauth.authResponseHeaders: Remote-User traefik.http.middlewares.tinyauth.forwardauth.authResponseHeaders: Remote-User

View File

@@ -8,12 +8,12 @@ services:
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
nginx: whoami:
container_name: nginx container_name: whoami
image: nginx:latest image: traefik/whoami:latest
labels: labels:
traefik.enable: true traefik.enable: true
traefik.http.routers.nginx.rule: Host(`nginx.example.com`) traefik.http.routers.nginx.rule: Host(`whoami.example.com`)
traefik.http.services.nginx.loadbalancer.server.port: 80 traefik.http.services.nginx.loadbalancer.server.port: 80
traefik.http.routers.nginx.middlewares: tinyauth traefik.http.routers.nginx.middlewares: tinyauth

2
go.mod
View File

@@ -7,6 +7,7 @@ require (
github.com/gin-gonic/gin v1.10.0 github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.24.0 github.com/go-playground/validator/v10 v10.24.0
github.com/google/go-querystring v1.1.0 github.com/google/go-querystring v1.1.0
github.com/mdp/qrterminal/v3 v3.2.0
github.com/rs/zerolog v1.33.0 github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1 github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0 github.com/spf13/viper v1.19.0
@@ -15,7 +16,6 @@ require (
require ( require (
github.com/containerd/log v0.1.0 // indirect github.com/containerd/log v0.1.0 // indirect
github.com/mdp/qrterminal/v3 v3.2.0 // indirect
github.com/moby/term v0.5.2 // indirect github.com/moby/term v0.5.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect