Skip to content

Commit

Permalink
chore: replace bit with Justfile (#1109)
Browse files Browse the repository at this point in the history
This was way more work and way more irritating than I hoped it would be.
I was hoping to switch back to make, but make doesn't support spaces in
filenames. Then I tried ninja, which doesn't support "|" in filenames.
Finally, I tried just using Just, but the lack of a dependency system
meant that really slow targets like the kt-runtime and npm made it
unreasonably painful.

So in the end I wrote a [little
tool](https://github.com/alecthomas/mktg) which acts like a single
"make" target entry, executing the provided command if any input is
newer than all outputs. This gives us fairly fast incremental builds
with little complexity.
  • Loading branch information
alecthomas authored Mar 19, 2024
1 parent ac7953b commit cc18bf3
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 199 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
uses: ./.github/actions/build-cache
- name: Docker Compose
run: docker compose up -d --wait
- name: Create DB
run: just init-db
- name: Download Go Modules
run: go mod download
- name: Run ${{ matrix.test }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/rebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ jobs:
run: docker compose up -d --wait
- name: Init DB
run: ftl-initdb
- name: Clean All
run: bit -c
- name: Rebuild All
run: bit
run: just build-all
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ jobs:
- name: Build Cache
uses: ./.github/actions/build-cache
- name: Build Console
run: bit frontend/dist/index.html
run: just build-frontend
- name: Publish Go Binaries
run: |
just errtrace
bit build/release/ftl
just build ftl # Ensure all the prerequisites are built before we use goreleaser
goreleaser release --skip=validate
env:
GITHUB_TOKEN: ${{ github.token }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/writecache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ jobs:
run: docker compose up -d --wait
- name: Init DB
run: ftl-initdb
- name: Clean All
run: bit -c
- name: Rebuild All
run: bit
run: bit build-all
- name: Download Maven Dependencies
run: mvn -f kotlin-runtime/ftl-runtime dependency:resolve --batch-mode
- name: Download Go Dependencies
Expand Down
139 changes: 0 additions & 139 deletions Bitfile

This file was deleted.

6 changes: 3 additions & 3 deletions Dockerfile.controller
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ RUN go mod download -x
# Build
COPY . /src/
RUN just errtrace
RUN bit build/release/ftl-controller
RUN bit build/release/ftl-initdb
RUN bit build/release/ftl
RUN just build ftl-controller
RUN just build ftl-initdb
RUN just build ftl

# Finally create the runtime image.
FROM ubuntu:22.04
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.runner
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ RUN go mod download -x
COPY . /src/

# Build runner template
RUN bit build/template/ftl/jars/ftl-runtime.jar
RUN just build-kt-runtime

# Build runner
RUN just errtrace
RUN bit build/release/ftl-runner
RUN bit build/release/ftl
RUN just build ftl-runner
RUN just build ftl

# Finally create the runtime image.
FROM ubuntu:22.04
Expand Down
76 changes: 58 additions & 18 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
set positional-arguments

# Start a hot-reloading dev cluster
dev: install-jars
goreman -logtime=false start
RELEASE := "build/release"
VERSION := `git describe --tags --always --dirty | sed -e 's/^v//'`
KT_RUNTIME_OUT := "kotlin-runtime/ftl-runtime/target/ftl-runtime-1.0-SNAPSHOT.jar"
KT_RUNTIME_RUNNER_TEMPLATE_OUT := "build/template/ftl/jars/ftl-runtime.jar"
RUNNER_TEMPLATE_ZIP := "backend/controller/scaling/localscaling/template.zip"
TIMESTAMP := `date +%s`
SCHEMA_OUT := "backend/protos/xyz/block/ftl/v1/schema/schema.proto"
ZIP_DIRS := "go-runtime/compile/build-template go-runtime/compile/external-module-template go-runtime/scaffolding kotlin-runtime/scaffolding kotlin-runtime/external-module-template"
FRONTEND_OUT := "frontend/dist/index.html"

# Install all JARs to local Maven repository and local build directory
install-jars:
bit 'kotlin-runtime/**/*.jar'
_help:
@just -l

# Deploy the Go time module
deploy-time:
ftl deploy examples/time
# Run errtrace on Go files to add stacks
errtrace:
git ls-files -z -- '*.go' | grep -zv /_ | xargs -0 errtrace -w && go mod tidy

# Deploy the Kotlin echo module
deploy-echo-kotlin:
ftl deploy examples/echo-kotlin
# Build everything
build-all: build-frontend build-generate build-kt-runtime build-protos build-sqlc build-zips
just build ftl

regen-schema:
bit backend/protos/xyz/block/ftl/v1/schema/schema.proto
bit backend/protos/xyz/block/ftl/v1/schema/schema.pb.go
# Run "go generate" on all packages
build-generate:
go generate -x ./...

# Run errtrace on Go files to add stacks
errtrace:
git ls-files -z -- '*.go' | grep -zv /_ | xargs -0 errtrace -w && go mod tidy
# Build command-line tools
build +tools: build-protos build-sqlc build-zips build-frontend
for tool in $@; do go build -o "{{RELEASE}}/$tool" -tags release -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done

export DATABASE_URL := "postgres://postgres:secret@localhost:54320/ftl?sslmode=disable"

# Explicitly initialise the database
init-db:
dbmate drop || true
dbmate create
dbmate --migrations-dir backend/controller/sql/schema up

# Regenerate SQLC code
build-sqlc:
sqlc generate --experimental

# Build the ZIP files that are embedded in the FTL release binaries
build-zips: build-kt-runtime
for dir in {{ZIP_DIRS}}; do (cd $dir && rm -f $(basename ${dir}.zip) && zip -q --symlinks -r ../$(basename ${dir}).zip .); done

# Rebuild frontend
build-frontend: npm-install
mktg {{FRONTEND_OUT}} : frontend/src -- "cd frontend && npm run build"

# Build the Kotlin runtime (if necessary)
build-kt-runtime:
mkdir -p $(dirname {{KT_RUNTIME_RUNNER_TEMPLATE_OUT}})
mktg {{KT_RUNTIME_OUT}} : kotlin-runtime/ftl-runtime -- mvn -f kotlin-runtime/ftl-runtime -Dmaven.test.skip=true -B install
install -m 0600 {{KT_RUNTIME_OUT}} {{KT_RUNTIME_RUNNER_TEMPLATE_OUT}}
mktg {{RUNNER_TEMPLATE_ZIP}} : {{KT_RUNTIME_RUNNER_TEMPLATE_OUT}} -- "cd build/template && zip -q --symlinks -r ../../{{RUNNER_TEMPLATE_ZIP}} ."

# Install Node dependencies
npm-install:
mktg frontend/node_modules : frontend/package.json frontend/src -- "cd frontend && npm install"

# Regenerate protos
build-protos: npm-install
mktg {{SCHEMA_OUT}} : backend/schema -- "ftl-schema > {{SCHEMA_OUT}} && buf format -w && buf lint && cd backend/protos && buf generate"
12 changes: 0 additions & 12 deletions Procfile

This file was deleted.

2 changes: 1 addition & 1 deletion backend/controller/scaling/localscaling/devel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var templateDirOnce sync.Once
func templateDir(ctx context.Context) string {
templateDirOnce.Do(func() {
// TODO: Figure out how to make maven build offline
err := exec.Command(ctx, log.Debug, internal.GitRoot(""), "bit", "build/template/ftl/jars/ftl-runtime.jar").RunBuffered(ctx)
err := exec.Command(ctx, log.Debug, internal.GitRoot(""), "just", "build-kt-runtime").RunBuffered(ctx)
if err != nil {
panic(err)
}
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions bin/.mktg-0.3.0.pkg
1 change: 0 additions & 1 deletion bin/bit

This file was deleted.

1 change: 1 addition & 0 deletions bin/dbmate
1 change: 1 addition & 0 deletions bin/mktg
2 changes: 1 addition & 1 deletion frontend/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Server(ctx context.Context, timestamp time.Time, publicURL *url.URL, allowO
logger := log.FromContext(ctx)
logger.Debugf("Building console...")

err := exec.Command(ctx, log.Debug, internal.GitRoot(""), "bit", "frontend/**/*").RunBuffered(ctx)
err := exec.Command(ctx, log.Debug, internal.GitRoot(""), "just", "build-frontend").RunBuffered(ctx)
if err != nil {
return nil, err
}
Expand Down
3 changes: 0 additions & 3 deletions go-runtime/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
var archive []byte

// Files is the FTL Go runtime scaffolding files.
//
// scaffolding.zip can be generated by running `bit go-runtime/scaffolding.zip`
// or indirectly via `bit build/release/ftl`.
func Files() *zip.Reader {
zr, err := zip.NewReader(bytes.NewReader(archive), int64(len(archive)))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func runTests(t *testing.T, tmpDir string, tests []test) {
ctx := log.ContextWithLogger(context.Background(), logger)
logger.Debugf("Building ftl")
binDir := filepath.Join(rootDir, "build", "release")
err = exec.Command(ctx, log.Debug, rootDir, filepath.Join(rootDir, "bin", "bit"), "build/release/ftl", "**/*.jar").RunBuffered(ctx)
err = exec.Command(ctx, log.Debug, rootDir, "just", "build", "ftl").RunBuffered(ctx)
assert.NoError(t, err)

controller := rpc.Dial(ftlv1connect.NewControllerServiceClient, "http://localhost:8892", log.Debug)
Expand Down
6 changes: 0 additions & 6 deletions kotlin-runtime/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ var archive []byte
var externalModuleTemplate []byte

// Files is the FTL Kotlin runtime scaffolding files.
//
// scaffolding.zip can be generated by running `bit kotlin-runtime/scaffolding.zip`
// or indirectly via `bit build/release/ftl`.
func Files() *zip.Reader {
zr, err := zip.NewReader(bytes.NewReader(archive), int64(len(archive)))
if err != nil {
Expand All @@ -27,9 +24,6 @@ func Files() *zip.Reader {
}

// ExternalModuleTemplates are templates for scaffolding external modules in the FTL Kotlin runtime.
//
// external-module-template.zip can be generated by running `bit kotlin-runtime/external-module-template.zip`
// or indirectly via `bit build/release/ftl`.
func ExternalModuleTemplates() *zip.Reader {
zr, err := zip.NewReader(bytes.NewReader(externalModuleTemplate), int64(len(externalModuleTemplate)))
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions scripts/ftl-run
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ cd "${top}"


build() {
bit build/template/ftl/jars/ftl-runtime.jar \
build/release/ftl-controller \
build/release/ftl-runner
just build ftl-controller ftl-runner
}

build
Expand Down

0 comments on commit cc18bf3

Please sign in to comment.