- Manage the database schema and apply migrations in
pkg/storage/db/migrations
. - Manage the queries in
pkg/storage/db/sqlc
. - Generated query directory
pkg/storage/db/dbx
. - Manage the templates in
pkg/ui
.
install go task package to run commands defined in Taskfile.yml:
go install github.com/go-task/task/v3/cmd/task@latest
then install all dev tooling:
task setup:tooling
list all tasks:
task --list-all
For configuration see the config.toml
passed in as the --config
flag to app.
create your dev config:
task setup:config
make sure to use the correct db dsn in sqlc.yml
and that the db is fully migrated.
generate go code from sql:
task gen:sqlc
new:
task migrate:add SEQ="migration_name"
up:
task migrate:up
down:
task migrate:down
Generate template code with templ.guide
task gen:templ
use air to generate the templates and run the server:
air
list app commands:
go run . help
run the server:
go run . server --config config.dev.toml
For simplicity we are using the standalone cli.
download the cli to the tmp folder (created once air is run):
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64
chmod +x tailwindcss-macos-arm64
mv tailwindcss-macos-arm64 tmp/tailwindcss
build and watch:
task gen:tailwind
When content is in the database you will need a safelist of css classes.
To do this there is a query in pkg/storage/db/sqlc/tailwind.sql
, this returns a unique list
of css classes found in the page_html.html
field. You can expand this to fit further requirements.
running the following task will rebuild the tailwind.config.js
file with an updated list of css classes.
task gen:tailwind-config
to expand the config make sure you update the tailwind.config.js.tmpl
file to include new settings.
With the config rebuilt, re-run the main gen:tailwind
task.
This can be used to build the app as a binary and run it in a container.
build:
docker build --build-arg EXPOSE_PORT=80 -t cms:latest .
run:
docker run \
--rm \
--name cms \
--publish "80:80" \
--env "DATABASE_HOST=host.docker.internal" \
--env "SERVER_DEBUG=false" \
--env "SERVER_PORT=80" \
cms:latest \
server --config config.toml
if you need it create a postgres container for the database:
docker run \
--detach \
--name "cms-postgres" \
--mount type=tmpfs,destination=/var/lib/postgresql/data \
--publish "5432:5432" \
--env POSTGRES_USER=postgres \
--env POSTGRES_PASSWORD=password \
--env POSTGRES_DB=cms \
postgres:latest