zdravko/justfile

134 lines
3.5 KiB
Makefile
Raw Normal View History

2024-02-10 17:05:11 +00:00
# Always use devbox environment to run commands.
set shell := ["devbox", "run"]
# Load dotenv
set dotenv-load
2024-02-10 17:05:11 +00:00
# Load public and private keys
export JWT_PRIVATE_KEY := `cat jwt.private.pem || echo ""`
export JWT_PUBLIC_KEY := `cat jwt.public.pem || echo ""`
2024-02-18 07:51:05 +00:00
GIT_SHA := `git rev-parse --short HEAD`
DOCKER_IMAGE := "ghcr.io/mentos1386/zdravko:sha-"+GIT_SHA
2024-02-12 08:25:11 +00:00
STATIC_DIR := "./web/static"
_default:
@just --list
2024-02-18 10:34:03 +00:00
2024-02-11 10:56:21 +00:00
# Run full development environment
run:
2024-02-24 21:07:49 +00:00
watchexec -r -e tmpl,css just _tailwindcss-build | sed -e 's/^/tailwind: /;' &
2024-02-27 11:04:05 +00:00
sleep 1
2024-02-24 21:07:49 +00:00
just run-temporal | sed -e 's/^/temporal: /;' &
2024-02-27 11:04:05 +00:00
sleep 1
2024-02-24 21:07:49 +00:00
watchexec -r -e go,tmpl,css just run-server
# Start worker
run-worker:
go build -o dist/zdravko cmd/zdravko/main.go
2024-02-18 21:41:40 +00:00
./dist/zdravko --worker
# Start server
run-server:
2024-02-18 21:41:40 +00:00
go build -o dist/zdravko cmd/zdravko/main.go
./dist/zdravko --server
# Start temporal
run-temporal:
go build -o dist/zdravko cmd/zdravko/main.go
./dist/zdravko --temporal
# Test
test:
go test -v ./...
# Generates new jwt key pair
generate-jwt-key:
2024-05-23 18:34:52 +00:00
openssl genrsa -out jwt.private.pem 2048
openssl rsa -pubout -in jwt.private.pem -out jwt.public.pem
2024-02-11 09:15:00 +00:00
# Deploy the application to fly.io
2024-02-19 09:17:32 +00:00
deploy-fly:
2024-02-18 09:54:01 +00:00
fly deploy --ha=false -c deploy/fly.toml -i {{DOCKER_IMAGE}}
2024-02-11 10:56:21 +00:00
# Read local jwt key and set it as fly secret
2024-02-19 09:17:32 +00:00
deploy-fly-set-jwt-key-secrets:
#!/bin/bash
# https://github.com/superfly/flyctl/issues/589
cat <<EOF | fly secrets import -c deploy/fly.toml
JWT_PRIVATE_KEY="""{{JWT_PRIVATE_KEY}}"""
JWT_PUBLIC_KEY="""{{JWT_PUBLIC_KEY}}"""
EOF
2024-02-19 09:17:32 +00:00
# Deploy locally with docker compose
deploy-docker:
cd deploy && docker compose up
# Build the application
build:
docker build -f build/Dockerfile -t {{DOCKER_IMAGE}} .
# Run Docker application.
run-docker:
docker run -p 8080:8080 \
-it --rm \
-e SESSION_SECRET \
-e OAUTH2_CLIENT_ID \
-e OAUTH2_CLIENT_SECRET \
-e OAUTH2_ENDPOINT_TOKEN_URL \
-e OAUTH2_ENDPOINT_AUTH_URL \
-e OAUTH2_ENDPOINT_USER_INFO_URL \
-e OAUTH2_ENDPOINT_LOGOUT_URL \
-e JWT_PRIVATE_KEY \
-e JWT_PUBLIC_KEY \
-e WORKER_TOKEN \
{{DOCKER_IMAGE}} --server --temporal --worker
2024-02-18 22:11:42 +00:00
2024-02-27 11:04:05 +00:00
# Start Sqlite web client
sqlite-web:
sqlite_web zdravko.db
2024-02-11 10:56:21 +00:00
# New migration file
migration-new name:
#!/bin/bash
FILENAME="database/sqlite/migrations/`date --iso-8601`_{{name}}.sql"
cat <<EOF > $FILENAME
-- +migrate Up
-- SQL in section 'Up' is executed when this migration is applied
-- +migrate Down
-- SQL in section 'Down' is executed when this migration is rolled back
EOF
echo "Created migration file: $FILENAME"
2024-02-11 10:56:21 +00:00
# Generate and download all external dependencies.
2024-05-23 18:34:52 +00:00
generate: _tailwindcss-build _htmx-download _monaco-download _feather-icons-download
2024-02-11 10:56:21 +00:00
go generate ./...
_tailwindcss-build:
2024-02-16 21:31:00 +00:00
tailwindcss build -c build/tailwind.config.js -i {{STATIC_DIR}}/css/main.css -o {{STATIC_DIR}}/css/tailwind.css
2024-02-11 10:56:21 +00:00
_htmx-download:
mkdir -p {{STATIC_DIR}}/js
curl -sLo {{STATIC_DIR}}/js/htmx.min.js https://unpkg.com/htmx.org/dist/htmx.min.js
_monaco-download:
rm -rf {{STATIC_DIR}}/monaco
npm install monaco-editor@0.46.0
mv node_modules/monaco-editor/min {{STATIC_DIR}}/monaco
rm -rf node_modules
# We only care about javascript language
find {{STATIC_DIR}}/monaco/vs/basic-languages/ \
-type d \
-not -name 'javascript' \
-not -name 'typescript' \
-not -name 'yaml' \
-not -name 'basic-languages' \
-prune -exec rm -rf {} \;
2024-02-11 10:56:21 +00:00
_feather-icons-download:
mkdir -p {{STATIC_DIR}}/icons
curl -sLo {{STATIC_DIR}}/icons/feather-sprite.svg https://unpkg.com/feather-icons/dist/feather-sprite.svg