Skip to content

Commit

Permalink
Add local development https with caddy use
Browse files Browse the repository at this point in the history
Update dev docs
  • Loading branch information
StevenWeathers committed Oct 13, 2024
1 parent 9eb94db commit 1908e07
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 58 deletions.
114 changes: 114 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
version: '3'

vars:
BINARY_NAME: thunderdome-planning-poker
BINARY_UNIX: $(BINARY_NAME)_unix
BINARY_WINDOWS: $(BINARY_NAME).exe
SWAGGER_DOCS_DIR: docs/swagger

tasks:
install:
cmds:
- go mod download
- go install github.com/swaggo/swag/cmd/[email protected]
- go install github.com/pressly/goose/v3/cmd/goose@latest
- npm ci --prefix ui

update-ui-deps:
cmds:
- npm update --prefix ui

update-go-deps:
cmds:
- go get -u ./...

clean:
cmds:
- rm -f {{.BINARY_NAME}}
- rm -f {{.BINARY_UNIX}}
- rm -f {{.BINARY_WINDOWS}}
- rm -rf ui/dist
- rm -rf release
- rm -rf {{ .SWAGGER_DOCS_DIR }}

gen-swag:
cmds:
- swag fmt
- swag init -g internal/http/http.go -o {{ .SWAGGER_DOCS_DIR }}

gen-i8n:
cmds:
- npm run locales --prefix ui

fmt-ui:
deps: [ gen-i8n ]
cmds:
- npm run format --prefix ui

fmt-e2e:
cmds:
- npm run format --prefix e2e

fmt-go:
deps: [ gen-swag ]
cmds:
- goimports -w .

format:
deps: [ fmt-go, fmt-ui, fmt-e2e ]

test-go:
cmds:
- go test -v ./... | grep -v {{ .SWAGGER_DOCS_DIR }}

build-ui:
deps: [ fmt-ui ]
cmds:
- npm run build --prefix ui

build-go:
deps: [ fmt-go ]
cmds:
- go build -o thunderdome-planning-poker -v

build-linux:
deps: [ gen-swag, build-ui ]
cmds:
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o {{.BINARY_UNIX}} -v

build-windows:
deps: [ gen-swag, build-ui ]
cmds:
- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o {{.BINARY_WINDOWS}} -v

build:
deps: [ fmt-go, build-ui ]
cmds:
- go build -o thunderdome-planning-poker -v

dev:
deps: [ build-ui ]
cmds:
- task: build
- HTTP_SECURE_PROTOCOL="false" SMTP_ENABLED="false" DB_HOST="localhost" APP_DOMAIN="localhost" COOKIE_SECURE="false" ./{{.BINARY_NAME}} live

dev-go:
cmds:
- task: build-go
- HTTP_SECURE_PROTOCOL="false" SMTP_ENABLED="false" DB_HOST="localhost" APP_DOMAIN="localhost" COOKIE_SECURE="false" ./{{.BINARY_NAME}} live

dev-secure:
cmds:
- task: build
- caddy start
- SMTP_ENABLED="false" DB_HOST="localhost" APP_DOMAIN="thunderdome.localhost" COOKIE_SECURE="false" ./{{.BINARY_NAME}} live

dev-secure-go:
cmds:
- task: build-go
- caddy start --config build/dev.caddyfile
- SMTP_ENABLED="false" DB_HOST="localhost" APP_DOMAIN="thunderdome.localhost" COOKIE_SECURE="false" ./{{.BINARY_NAME}} live

run:
cmds:
- HTTP_SECURE_PROTOCOL="false" SMTP_ENABLED="false" DB_HOST="localhost" APP_DOMAIN="localhost" COOKIE_SECURE="false" ./$(BINARY_NAME)
3 changes: 3 additions & 0 deletions build/dev.caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
thunderdome.localhost

reverse_proxy 127.0.0.1:8080
100 changes: 42 additions & 58 deletions docs/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,108 +11,92 @@
- [Code Review Comments guide](https://go.dev/wiki/CodeReviewComments) from the Go project should be
followed

### Format code before commit

Run `make format` to format all go and frontend code before commit
## Developing locally

- not doing so can result in a failed build on GitHub
There are a few ways to run the application locally, the easiest way is to
use [Docker Compose](https://docs.docker.com/compose/), but you can also run
the application directly on your machine provided you have the dependencies installed.

## Building and running with Docker (preferred solution)
- [Building and running with Docker Compose](#building-and-running-with-docker-compose)
- [Build and Run without Docker Compose](#build-and-run-without-docker-compose)
- [Creating SQL Migrations](#creating-sql-migrations)
- [Adding new Localizations](#adding-new-localizations)
- [Format code before commit](#format-code-before-commit)

### Using Docker Compose
## Building and running with Docker Compose

```
docker-compose up --build
```

### Using Docker without Compose
## Build and Run without Docker Compose

This solution will require you to pass environment variables or set up the config file, as well as setup and manage the
DB yourself.
### Prerequisites

```
docker build ./ -f ./build/Dockerfile -t thunderdome:latest
docker run --publish 8080:8080 --name thunderdome thunderdome:latest
```
- [Postgres](https://www.postgresql.org/download/)
- [Go](https://golang.org/dl/)
- [Node.js](https://nodejs.org/en/download/)
- [Task](https://taskfile.dev/#/) (recommended) is used to manage development tasks in the project.
- [Goose](https://github.com/pressly/goose) (recommended) is used to manage SQL migrations
- [Caddy Server](https://caddyserver.com/) (optional) is used to run locally with HTTPS

## Building
### Install dependencies

To run without docker you will need to first build, then setup the postgres DB, and pass the user, pass, name, host, and
port to the application as environment variables or in a config file.
With [Task](https://taskfile.dev/#/) running the `task install` command will install dependencies

```
DB_HOST=
DB_PORT=
DB_USER=
DB_PASS=
DB_NAME=
```

### Install dependencies
OR manually run the following commands

```
go mod download
go install github.com/swaggo/swag/cmd/[email protected]
cd ui && npm install
```

## Build with Make
#### Build and run

```
make build
```
Postgres must be running with the same configuration as in the `docker-compose.yml` file.

### OR manual steps
With [Task](https://taskfile.dev/#/) run the `task dev` command to build and run the application then visit
[http://localhost:8080](http://localhost:8080) in your browser.

### Build static assets
Or `task dev-secure` to run with HTTPS (using Caddy) then
visit [https://thunderdome.localhost](https://thunderdome.localhost) in your browser.

```
npm run build --prefix ui
```
### Format code before commit

### Build for current OS
- Using the above dev Task(s) will automatically handle this for you.

```
swag init -g internal/http/http.go -o docs/swagger
go build
```
If you've setup Task simply `task format` to format all go and frontend code before commit, otherwise `make format` is
still available for those with make installed.

## Running with Watch (uses webapp dist files on OS instead of embedded)
- not doing so can result in a failed build on GitHub

```
npm run autobuild --prefix ui
make dev-go
```
### Restful API Changes

## Let the Pointing Games begin!
- Using the above dev Task(s) will automatically handle this for you.

Run the server and visit [http://localhost:8080](http://localhost:8080)
The restful API is documented using swagger comments in the Go code, any changes to that documentation require
regenerating the docs with the following commands and committing the updated docs with the changes.

## Restful API Changes
With [Task](https://taskfile.dev/#/) `task gen-swag` will regenerate the swagger docs

The restful API is documented using swagger, any changes to that documentation require regenerating the docs with the
following commands and committing the updated docs with the changes.
OR manually run the following commands

```bash
swag fmt
swag init -g internal/http/http.go -o docs/swagger
```

## Creating SQL Migrations

First install [goose](https://github.com/pressly/goose) tool

```
go install github.com/pressly/goose/v3/cmd/goose@latest
```
### Creating SQL Migrations

Generate new migration file
Generate new migration file using the following command, replacing `SHORT_DESCRIPTIVE_FILNAME` with a short descriptive
name for the migration example `create_poker_table`.

```
goose -dir internal/db/migrations create SHORT_DESCRIPTIVE_FILNAME sql
```

## Adding new Localizations
### Adding new Localizations

**Thunderdome** supports Locale selection on the UI (Default en-US)

Expand Down

0 comments on commit 1908e07

Please sign in to comment.