diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b9d99c..3e91a0c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # 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 @@ -8,6 +8,7 @@ Contributing is relatively easy. - Golang v1.23.2 and above - Git - Docker +- Make (not required but it will make your life easier) ## Cloning the repository @@ -20,48 +21,42 @@ cd tinyauth ## Install requirements -Now it's time to install the requirements, firstly the Go ones: +To install the requirements simply run: ```sh -go mod download +make requirements ``` -And now the site ones: - -```sh -cd site -bun i -``` +It will download all the node packages required by the frontend as well as all the go requirements. ## 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 -cd site -bun run build -cd .. +make run ``` -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 -rm -rf internal/assets/dist -cp -r site/dist internal/assets/dist +make build ``` -Finally either run the app with: +To avoid rebuilding the frontend every time you can run: ```sh -go run main.go +make run-no-web ``` -Or build it with: +And: ```sh -go build +make build-no-web ``` +For these commands to succeed you must have built the frontend at least once. + > [!WARNING] > 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: ``` -*.dev.local -> 127.0.0.1 -dev.local -> 127.0.0.1 +*.dev.example.com -> 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: @@ -79,3 +74,6 @@ Then I can just make sure the domains are correct in the example docker compose ```sh 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. diff --git a/Makefile b/Makefile index e4475a2..96b3242 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,11 @@ web: cd site; bun run build +# Requirements +requirements: + cd site; bun install + go mod tidy + # Copy site assets assets: web rm -rf internal/assets/dist @@ -12,6 +17,10 @@ assets: web run: assets go run main.go +# Run development binary without compiling the frontend +run-skip-web: + go run main.go + # Test test: go test ./... @@ -20,6 +29,6 @@ test: build: assets go build -o tinyauth -# Build no site +# Build the binary without compiling the frontend build-skip-web: go build -o tinyauth \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index acde793..340568e 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -13,7 +13,7 @@ services: image: traefik/whoami:latest labels: 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.routers.nginx.middlewares: tinyauth @@ -24,11 +24,11 @@ services: dockerfile: Dockerfile environment: - 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 labels: 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.middlewares.tinyauth.forwardauth.address: http://tinyauth:3000/api/auth/traefik traefik.http.middlewares.tinyauth.forwardauth.authResponseHeaders: Remote-User diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 6af3925..618cb8c 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -8,12 +8,12 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock - nginx: - container_name: nginx - image: nginx:latest + whoami: + container_name: whoami + image: traefik/whoami:latest labels: 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.routers.nginx.middlewares: tinyauth diff --git a/go.mod b/go.mod index c2b81ed..0b6e313 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/gin-gonic/gin v1.10.0 github.com/go-playground/validator/v10 v10.24.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/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 @@ -15,7 +16,6 @@ require ( require ( 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/morikuni/aec v1.0.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect