diff options
| author | mo khan <mo@mokhan.ca> | 2025-08-14 18:19:12 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-08-14 18:19:12 -0600 |
| commit | 21952b2c5b9f4973c966057f6041c488b5e09129 (patch) | |
| tree | dc8f733b1d66d369455096d3a61d508367a9371f | |
| parent | 0b7103e850232eaab4e87a0322817055e55dbe51 (diff) | |
| parent | 034d58bf07c55fa5ae7a347defda8cbacf811027 (diff) | |
Merge branch 'pg-db' into 'main'
Start a pg container in the integration tests
See merge request gitlab-org/software-supply-chain-security/authorization/sparkled!23
| -rw-r--r-- | .dockerignore | 3 | ||||
| -rw-r--r-- | Dockerfile | 8 | ||||
| -rw-r--r-- | Makefile | 37 | ||||
| -rwxr-xr-x | bin/mise | 13 | ||||
| -rwxr-xr-x | bin/zed | 2 | ||||
| -rw-r--r-- | test/integration/container_test.go | 3 |
6 files changed, 40 insertions, 26 deletions
diff --git a/.dockerignore b/.dockerignore index 830b1ea..2926439 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,8 +4,9 @@ /.env* /.git* /.runway/ -/.tool-versions +/mise.toml /log/ /tags* /test/ /tmp/ +Dockerfile @@ -4,9 +4,7 @@ FROM envoyproxy/envoy:v1.34-latest AS envoy-binary # Build stage for getting dumb-init FROM debian:bookworm-slim AS dumb-init-builder -RUN apt-get update && apt-get install -y wget && \ - wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 && \ - chmod +x /usr/bin/dumb-init +RUN apt-get update && apt-get install -y wget && wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 && chmod +x /usr/bin/dumb-init # Build stage for getting SpiceDB binary FROM authzed/spicedb:latest AS spicedb-binary @@ -16,8 +14,8 @@ FROM golang:1.24-alpine AS build ENV CGO_ENABLED=0 WORKDIR /app COPY . ./ -RUN go build -o /bin/sparkled ./cmd/sparkled/main.go -RUN go build -o /bin/authzd ./cmd/authzd/main.go +RUN go build -mod=vendor -o /bin/sparkled ./cmd/sparkled/main.go +RUN go build -mod=vendor -o /bin/authzd ./cmd/authzd/main.go WORKDIR /app/vendor/github.com/xlgmokha/minit RUN go build -o /bin/minit main.go @@ -2,6 +2,9 @@ PROJECT_NAME := $(shell basename $(shell pwd)) GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') IMAGE_TAG := $(PROJECT_NAME):$(GIT_BRANCH) AUTHZD_BIN := bin/authzd +DOCKER := docker +GO := mise exec go -- go +MISE := bin/mise SPARKLED_BIN := bin/sparkled SPICEDB := bin/spicedb TOOL := bin/tool @@ -10,24 +13,24 @@ ZED := bin/zed .PHONY: clean setup build test run db-setup db-create db-stop db-reset $(AUTHZD_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum - @go build -o $(AUTHZD_BIN) ./cmd/authzd/main.go + @$(GO) build -mod=vendor -o $(AUTHZD_BIN) ./cmd/authzd/main.go $(SPARKLED_BIN): $(shell find . -name "*.go" 2>/dev/null) go.sum - @go build -o $(SPARKLED_BIN) ./cmd/sparkled/main.go + @$(GO) build -mod=vendor -o $(SPARKLED_BIN) ./cmd/sparkled/main.go db-clean: @rm -rf tmp/postgres tmp/postgres.log clean: db-clean @rm -f $(AUTHZD_BIN) $(SPARKLED_BIN) Procfile Procfile.dev - @go clean -testcache + @$(GO) clean -testcache setup: - @mise install + @$(MISE) install @if command -v brew >/dev/null 2>&1; then \ brew bundle; \ fi - @mise exec python -- pip install dumb-init + @$(MISE) exec python -- pip install dumb-init Procfile: Procfile.template @grep -v "# DEV_ONLY:" Procfile.template > Procfile @@ -41,31 +44,31 @@ test-schema: @$(ZED) validate etc/authzd/*.yaml test-unit: - @go test -shuffle=on ./... + @$(GO) test -shuffle=on ./... test-race: - @CGO_ENABLED=1 go test -race -shuffle=on ./... + @CGO_ENABLED=1 $(GO) test -race -shuffle=on ./... test-integration: build-image - @IMAGE_TAG=$(IMAGE_TAG) go test -tags=integration ./test/integration/... + @IMAGE_TAG=$(IMAGE_TAG) $(GO) test -tags=integration ./test/integration/... -test: clean test-unit test-schema test-integration +test: clean test-unit test-race test-integration test-schema build-image: Procfile - @docker build --network=host --no-cache --tag $(IMAGE_TAG) . + @$(DOCKER) build --network=host --tag $(IMAGE_TAG) . run: clean build Procfile.dev db-init @$(TOOL) godotenv -f .env.local,.env $(TOOL) minit -f Procfile.dev run-image: clean build-image - @docker run --rm --network host --env-file .env.local -p 10000:10000 -it $(IMAGE_TAG) + @$(DOCKER) run --rm --network host --env-file .env.local -p 10000:10000 -it $(IMAGE_TAG) lint: @$(TOOL) yamlfmt -lint -exclude vendor . @$(ZED) validate etc/authzd/* tidy: - @go mod tidy + @$(GO) mod tidy @$(TOOL) yamlfmt -exclude vendor . db-schema-load: @@ -75,20 +78,20 @@ db-seed: @$(ZED) import etc/authzd/relationships.yaml db-stop: - @mise exec postgres -- pg_ctl -D tmp/postgres stop || true + @$(MISE) exec postgres -- pg_ctl -D tmp/postgres stop || true db-reset: db-stop db-clean db-create db-init: - @[ ! -d tmp/postgres ] && mise exec postgres -- initdb -D tmp/postgres || true + @[ ! -d tmp/postgres ] && $(MISE) exec postgres -- initdb -D tmp/postgres || true db-create: db-init - @mise exec postgres -- createdb -h /tmp sparkle_development || true + @$(MISE) exec postgres -- createdb -h /tmp sparkle_development || true db-migrate: @$(TOOL) godotenv -f .env.local,.env -- sh -c '$(SPICEDB) datastore migrate head --datastore-engine postgres --datastore-conn-uri "$$DATABASE_URL" --log-level trace' --skip-release-check db-console: - @mise exec postgres -- psql -h /tmp sparkle_development + @$(MISE) exec postgres -- psql -h /tmp sparkle_development -db-setup: db-create db-schema-load db-seed +db-setup: db-create # db-schema-load db-seed diff --git a/bin/mise b/bin/mise new file mode 100755 index 0000000..7f6c85b --- /dev/null +++ b/bin/mise @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e +[ -n "$DEBUG" ] && set -x + +cd "$(dirname "$0")/.." + +if ! command -v mise >/dev/null 2>&1; then + echo "Install mise: https://github.com/jdx/mise" + exit 1 +fi + +exec mise $@ @@ -10,4 +10,4 @@ if ! command -v zed >/dev/null 2>&1; then exit 1 fi -./bin/tool godotenv -f .env.local,.env go tool zed --insecure $@ +./bin/tool godotenv -f .env.local,.env zed --insecure $@ diff --git a/test/integration/container_test.go b/test/integration/container_test.go index 4273eff..51b19a5 100644 --- a/test/integration/container_test.go +++ b/test/integration/container_test.go @@ -46,8 +46,7 @@ func TestContainer(t *testing.T) { databaseURL, err := pgContainer.ConnectionString(ctx, "sslmode=disable") require.NoError(t, err) - envVars := environmentVariables(srv, databaseURL) - container := NewContainer(t, ctx, envVars) + container := NewContainer(t, ctx, environmentVariables(srv, databaseURL)) defer testcontainers.TerminateContainer(container) require.True(t, container.IsRunning()) |
