-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTaskfile.yml
More file actions
95 lines (80 loc) · 3.37 KB
/
Taskfile.yml
File metadata and controls
95 lines (80 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
version: '3'
# Load env/development.env by default, but allow it to be overridden by setting ENV like `ENV=production task <task>`
env:
ENV: "{{.ENV | default \"development\"}}"
dotenv: ['env/{{.ENV}}.env']
tasks:
# Developer setup, development, and testing
#
setup:
desc: Install dependencies
cmds:
- npm install
# Do an initial build of the frontend assets to ensure that when we build the Go app, embed succeeds
- npx vite build
- go install
- if [[ ! $(command -v air) ]]; then go install github.com/air-verse/air@v1.52.2; fi
- "if [[ ! $(command -v air) ]]; then echo \"WARNING: Attempted to go install the air command, but it still could not be found; to fix this, try adding ~/bin/go to your PATH like so: go env GOPATH >> .zshrc\"; fi"
- if [[ ! $(command -v atlas) ]]; then curl -sSf https://atlasgo.sh | sh -s -- -y; fi
- task: "db:up"
- task: "db:apply"
- task: "db:seed"
- echo "Setup complete. Run 'task dev' to start the dev server."
dev:
desc: Run a local dev server, watching for changes
deps: ["dev:frontend", "dev:backend"]
dev:backend:
cmds:
# Sometimes the previous process doesn't get killed properly, ensure it's gone
- pkill kbexample || true
- air {{.CLI_ARGS}}
dev:frontend:
cmds:
- npx vite --clearScreen false
dev:dlv:
desc: Run the backend with dlv for debugging
cmds:
- npx vite build
- dlv debug .
test:
desc: "Run tests (hint: use -w to test continuously)"
sources:
- "**/*.go"
cmds:
# NOTE(dk): -p 1 ensures we don't run the package tests concurrently. They can interfere with each other because
# they share a test database. To be fixed by https://github.com/katabole/kbsql/issues/2
- go test -p 1 ./...
# Database tasks
# Note that most of the configuration of these comes from environment variables, loaded with dotenv above
#
db:up:
desc: Ensure a local postgres dev db is running
cmds:
- docker compose up -d postgres
- sleep 1 # Give it a second to bind to ports so the next commands don't fail
# Ensure these dev-related databases exist and create them if they don't yet.
# The former is the app's dev database, while the latter is essentially a "scratch" database used by atlas
# (see https://atlasgo.io/concepts/dev-database#introduction)
- psql -tc "SELECT 1 FROM pg_database WHERE datname = 'kbexample_dev'" | grep -q 1 || psql -c "CREATE DATABASE kbexample_dev"
- psql -tc "SELECT 1 FROM pg_database WHERE datname = 'atlas_dev'" | grep -q 1 || psql -c "CREATE DATABASE atlas_dev"
db:down:
desc: Take down the local postgres db
cmds:
- docker compose down postgres
db:apply:
desc: Ensure any changes in the schema.sql file are applied to the dev database
cmds:
- atlas schema apply --to file://schema.sql --url "postgresql:///kbexample_dev" --dev-url "postgresql:///atlas_dev"
db:gen-migration:
desc: Create a migration file based on the changes made to schema.sql
cmds:
- atlas migrate diff {{.CLI_ARGS}} --dir "file://migrations" --to file://schema.sql --dev-url "postgresql:///atlas_dev"
db:shell:
desc: Open a psql shell to the database
cmds:
- psql
db:seed:
desc: Insert seed data into the database
cmds:
- go run ./cmd/dbseed
# vim: set expandtab tabstop=2