Live Development Server
Prerequisites
Run a local development server
The helper Make targets will run a local development server, with:
- the PostgreSQL database running as a Docker container;
- the SparkleMuffin application running locally in development mode (via
go run
).
The application server will be reloaded every time a source file is changed on the disk,
thanks to watchexec
.
For more information about how services are configured and started, see:
- the Makefile;
- the docker-compose.dev.yml Docker Compose configuration.
Run a local development server:
$ make live
== Starting database
docker compose -f docker-compose.dev.yml up --remove-orphans -d
[+] Building 0.0s (0/0) docker:default
[+] Running 1/1
✔ Container sparklemuffin-postgres-1 Started 0.0s
== Watching for changes... (hit Ctrl+C when done)
2023-11-03T10:26:52+01:00 INF configuration: no file found config_paths=["/etc","/home/dev/.config","."]
2023-11-03T10:26:52+01:00 INF database: successfully created connection pool database_addr=localhost:15432 database_driver=pgx database_name=sparklemuffin
2023-11-03T10:26:52+01:00 INF global: setting up services log_level=info version=devel
2023-11-03T10:26:52+01:00 INF metrics: listening for HTTP requests metrics_addr=127.0.0.1:8081
2023-11-03T10:26:52+01:00 INF sparklemuffin: listening for HTTP requests http_addr=0.0.0.0:8080
Run a local development server, with the Go race detector enabled:
$ make live-race
== Starting database
docker compose -f docker-compose.dev.yml up --remove-orphans -d
[+] Building 0.0s (0/0) docker:default
[+] Running 1/0
✔ Container sparklemuffin-postgres-1 Running 0.0s
== Watching for changes... (hit Ctrl+C when done)
2023-11-03T10:27:38+01:00 INF configuration: no file found config_paths=["/etc","/home/dev/.config","."]
2023-11-03T10:27:38+01:00 INF database: successfully created connection pool database_addr=localhost:15432 database_driver=pgx database_name=sparklemuffin
2023-11-03T10:27:38+01:00 INF global: setting up services log_level=info version=devel
2023-11-03T10:27:38+01:00 INF metrics: listening for HTTP requests metrics_addr=127.0.0.1:8081
2023-11-03T10:27:38+01:00 INF sparklemuffin: listening for HTTP requests http_addr=0.0.0.0:8080
Run database migrations
$ make dev-migrate
go run ./cmd/sparklemuffin migrate
2023-11-03T10:31:53+01:00 INF configuration: no file found config_paths=["/etc","/home/dev/.config","."]
2023-11-03T10:31:53+01:00 INF database: successfully created connection pool database_addr=localhost:15432 database_driver=pgx database_name=sparklemuffin
2023-11-03T10:31:53+01:00 INF successfully opened database connection database_addr=localhost:15432 database_driver=pgx database_name=sparklemuffin
2023-11-03T10:31:53+01:00 INF migrate: the database schema is up to date database_addr=localhost:15432 database_driver=pgx
Create a first administrator user
Create the user account with:
$ make dev-admin
go run ./cmd/sparklemuffin createadmin \
--displayname Admin \
--email admin@dev.local \
--nickname admin
2023-11-03T10:34:50+01:00 INF configuration: no file found config_paths=["/etc","/home/dev/.config","."]
2023-11-03T10:34:50+01:00 INF database: successfully created connection pool database_addr=localhost:15432 database_driver=pgx database_name=sparklemuffin
2023-11-03T10:34:50+01:00 INF admin user successfully created email=admin@dev.local nickname=admin
Generated password: Qj3Qkeq4GpmEOrzjRv36VqVPQVymztbE4nlQ9u8KhjE=
Then open the application in your Web browser:
- access http://localhost:8080;
- login using the generated credentials:
- Email address:
admin@dev.local
- Password: use the password generated by the
make dev-admin
command
- Email address:
Stop local services
$ docker compose stop
[+] Stopping 1/1
✔ Container sparklemuffin-postgres-1 Stopped
Remove containers and application data
Stop and remove application containers (without removing data volumes):
$ docker compose down
Stop and remove application containers, and remove data volumes:
$ docker compose down -v