From e730f4b397b2a95f4d699aad364f740cdeb77577 Mon Sep 17 00:00:00 2001 From: Rafael Espinoza Date: Sat, 29 Jun 2024 11:59:29 -0700 Subject: [PATCH] build: Replace make with just * Adjust the '$ git describe --tag' invocation in the Justfile to work on a shallow clone of a repo. This error was always present when building via makefile, but execution was allowed to continue. When just is used, then the error is a show-stopper. * Use shell interpreter in some Justfile recipes so that build environments can use the default shell, /bin/sh, rather than requiring them to install bash. * Remove .dockerignore because we only need to pay attention to files under version control, and therefore could leverage the gitignore. Docker-related artifacts should be built from repo clones, which will only contain version-controlled files. Use of the ci.Justfile when building docker artifacts will make that happen. --- .ci/cassandra/client.Dockerfile | 2 +- .ci/cassandra/client.sh | 6 +- .ci/client_base.Dockerfile | 2 +- .ci/mysql/client.Dockerfile | 2 +- .ci/mysql/client.sh | 6 +- .ci/postgres/client.Dockerfile | 2 +- .ci/postgres/client.sh | 6 +- .ci/sqlite3/Dockerfile | 2 +- .ci/sqlite3/client.sh | 6 +- .ci/sqlserver/client.Dockerfile | 2 +- .ci/sqlserver/client.sh | 6 +- .dockerignore | 3 - .github/workflows/build-cassandra.yml | 12 ++- .github/workflows/build-mysql.yml | 18 +++-- .github/workflows/build-postgres.yml | 12 ++- .github/workflows/build-sqlite3.yml | 6 +- .github/workflows/build-sqlserver.yml | 6 +- .github/workflows/static.yml | 4 +- Justfile | 101 +++++++++++++++++++++++ Makefile | 108 ------------------------- README.md | 52 ++++++------ ci.Justfile | 111 ++++++++++++++++++++++++++ ci.Makefile | 89 --------------------- 23 files changed, 299 insertions(+), 265 deletions(-) delete mode 100644 .dockerignore create mode 100755 Justfile delete mode 100644 Makefile create mode 100755 ci.Justfile delete mode 100644 ci.Makefile diff --git a/.ci/cassandra/client.Dockerfile b/.ci/cassandra/client.Dockerfile index 9474b46..9f2cd21 100644 --- a/.ci/cassandra/client.Dockerfile +++ b/.ci/cassandra/client.Dockerfile @@ -1,7 +1,7 @@ FROM godfish_test/client_base:latest WORKDIR /src -RUN make build-cassandra +RUN just build-cassandra # Alpine linux doesn't have a cassandra client. Build a golang binary to check # if server is ready and setup the test DB. Use it in the entrypoint. diff --git a/.ci/cassandra/client.sh b/.ci/cassandra/client.sh index 93483bf..8e8bd9a 100755 --- a/.ci/cassandra/client.sh +++ b/.ci/cassandra/client.sh @@ -5,9 +5,9 @@ set -eu dbhost="${1:?missing dbhost}" echo "building binary" -make build-cassandra +just build-cassandra echo "testing godfish" -make test ARGS='-v -count=1 -coverprofile=/tmp/cover.out' +just test '-v -count=1 -coverprofile=/tmp/cover.out' # Wait for db server to be ready, with some limits. num_attempts=0 @@ -25,4 +25,4 @@ done >&2 echo "db is up" echo "testing godfish against live db" -make test-cassandra ARGS='-v -count=1 -coverprofile=/tmp/cover_driver.out' +just test-cassandra '-v -count=1 -coverprofile=/tmp/cover_driver.out' diff --git a/.ci/client_base.Dockerfile b/.ci/client_base.Dockerfile index b5b9a45..cae9d23 100644 --- a/.ci/client_base.Dockerfile +++ b/.ci/client_base.Dockerfile @@ -1,6 +1,6 @@ FROM golang:alpine WORKDIR /src -RUN apk update && apk --no-cache add gcc g++ git make +RUN apk update && apk --no-cache add gcc g++ git just COPY go.mod /src RUN go mod download && go mod verify COPY . /src diff --git a/.ci/mysql/client.Dockerfile b/.ci/mysql/client.Dockerfile index 056790e..e228823 100644 --- a/.ci/mysql/client.Dockerfile +++ b/.ci/mysql/client.Dockerfile @@ -3,7 +3,7 @@ FROM godfish_test/client_base:latest WORKDIR /src RUN apk update && \ apk --no-cache add mysql-client && \ - make build-mysql + just build-mysql COPY .ci/mysql/client.sh / ENTRYPOINT /client.sh diff --git a/.ci/mysql/client.sh b/.ci/mysql/client.sh index eb553c2..caebc17 100755 --- a/.ci/mysql/client.sh +++ b/.ci/mysql/client.sh @@ -6,9 +6,9 @@ dbhost="${1:?missing dbhost}" dbuser='godfish' echo "building binary" -make build-mysql +just build-mysql echo "testing godfish" -make test ARGS='-v -count=1 -coverprofile=/tmp/cover.out' +just test '-v -count=1 -coverprofile=/tmp/cover.out' # Wait for db server to be ready, with some limits. @@ -27,4 +27,4 @@ done >&2 echo "db is up" echo "testing godfish against live db" -make test-mysql ARGS='-v -count=1 -coverprofile=/tmp/cover_driver.out' +just test-mysql '-v -count=1 -coverprofile=/tmp/cover_driver.out' diff --git a/.ci/postgres/client.Dockerfile b/.ci/postgres/client.Dockerfile index 50a2a0f..4b8f2bf 100644 --- a/.ci/postgres/client.Dockerfile +++ b/.ci/postgres/client.Dockerfile @@ -3,7 +3,7 @@ FROM godfish_test/client_base:latest WORKDIR /src RUN apk update && \ apk --no-cache add postgresql-client && \ - make build-postgres + just build-postgres COPY .ci/postgres/client.sh / ENTRYPOINT /client.sh diff --git a/.ci/postgres/client.sh b/.ci/postgres/client.sh index 96427dd..9f55f20 100755 --- a/.ci/postgres/client.sh +++ b/.ci/postgres/client.sh @@ -7,9 +7,9 @@ dbname='godfish_test' dbuser='godfish' echo "building binary" -make build-postgres +just build-postgres echo "testing godfish" -make test ARGS='-v -count=1 -coverprofile=/tmp/cover.out' +just test '-v -count=1 -coverprofile=/tmp/cover.out' # Wait for db server to be ready, with some limits. @@ -27,4 +27,4 @@ done >&2 echo "db is up" echo "testing godfish against live db" -make test-postgres ARGS='-v -count=1 -coverprofile=/tmp/cover_driver.out' +just test-postgres '-v -count=1 -coverprofile=/tmp/cover_driver.out' diff --git a/.ci/sqlite3/Dockerfile b/.ci/sqlite3/Dockerfile index 49eb5e6..b503784 100644 --- a/.ci/sqlite3/Dockerfile +++ b/.ci/sqlite3/Dockerfile @@ -5,7 +5,7 @@ ENV DB_DSN="file:/godfish_test.db" WORKDIR /src RUN apk update && \ apk --no-cache add musl-dev sqlite && \ - make build-sqlite3 + just build-sqlite3 COPY .ci/sqlite3/client.sh / ENTRYPOINT /client.sh diff --git a/.ci/sqlite3/client.sh b/.ci/sqlite3/client.sh index e05866f..866fc56 100755 --- a/.ci/sqlite3/client.sh +++ b/.ci/sqlite3/client.sh @@ -3,10 +3,10 @@ set -eu echo "building binary" -make build-sqlite3 +just build-sqlite3 echo "testing godfish" -make test ARGS='-v -count=1 -coverprofile=/tmp/cover.out' +just test '-v -count=1 -coverprofile=/tmp/cover.out' echo "testing godfish against live db" -make test-sqlite3 ARGS='-v -count=1 -coverprofile=/tmp/cover_driver.out' +just test-sqlite3 '-v -count=1 -coverprofile=/tmp/cover_driver.out' diff --git a/.ci/sqlserver/client.Dockerfile b/.ci/sqlserver/client.Dockerfile index 4feb2fb..cb5b615 100644 --- a/.ci/sqlserver/client.Dockerfile +++ b/.ci/sqlserver/client.Dockerfile @@ -1,7 +1,7 @@ FROM godfish_test/client_base:latest WORKDIR /src -RUN make build-sqlserver +RUN just build-sqlserver # Alpine linux doesn't have a SQL Server client. Build a golang binary to # check if server is ready. Use it in the entrypoint. diff --git a/.ci/sqlserver/client.sh b/.ci/sqlserver/client.sh index 6406f72..f8a1e2d 100755 --- a/.ci/sqlserver/client.sh +++ b/.ci/sqlserver/client.sh @@ -3,9 +3,9 @@ set -eu echo "building binary" -make build-sqlserver +just build-sqlserver echo "testing godfish" -make test ARGS='-v -count=1 -coverprofile=/tmp/cover.out' +just test '-v -count=1 -coverprofile=/tmp/cover.out' # Wait for db server to be ready, with some limits. @@ -24,4 +24,4 @@ done >&2 echo "db is up" echo "testing godfish against live db" -make test-sqlserver ARGS='-v -count=1 -coverprofile=/tmp/cover_driver.out' +just test-sqlserver '-v -count=1 -coverprofile=/tmp/cover_driver.out' diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index c7501ab..0000000 --- a/.dockerignore +++ /dev/null @@ -1,3 +0,0 @@ -.env* -.git -.scratch diff --git a/.github/workflows/build-cassandra.yml b/.github/workflows/build-cassandra.yml index 7ed9d5a..49e35cb 100644 --- a/.github/workflows/build-cassandra.yml +++ b/.github/workflows/build-cassandra.yml @@ -7,8 +7,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-cassandra3-up + run: just -f ci.Justfile ci-cassandra3-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -17,15 +19,17 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-cassandra3-down + run: just -f ci.Justfile ci-cassandra3-down v4: name: cassandra_v4 runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-cassandra4-up + run: just -f ci.Justfile ci-cassandra4-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -34,4 +38,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-cassandra4-down + run: just -f ci.Justfile ci-cassandra4-down diff --git a/.github/workflows/build-mysql.yml b/.github/workflows/build-mysql.yml index ae349a1..17d630c 100644 --- a/.github/workflows/build-mysql.yml +++ b/.github/workflows/build-mysql.yml @@ -7,8 +7,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-mariadb-up + run: just -f ci.Justfile ci-mariadb-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -17,15 +19,17 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-mariadb-down + run: just -f ci.Justfile ci-mariadb-down mysql_v57: name: mysql v5.7 runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-mysql57-up + run: just -f ci.Justfile ci-mysql57-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -34,15 +38,17 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-mysql57-down + run: just -f ci.Justfile ci-mysql57-down mysql_v8: name: mysql v8.0 runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-mysql8-up + run: just -f ci.Justfile ci-mysql8-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -51,4 +57,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-mysql8-down + run: just -f ci.Justfile ci-mysql8-down diff --git a/.github/workflows/build-postgres.yml b/.github/workflows/build-postgres.yml index 95a7e78..7cb0434 100644 --- a/.github/workflows/build-postgres.yml +++ b/.github/workflows/build-postgres.yml @@ -7,8 +7,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-postgres14-up + run: just -f ci.Justfile ci-postgres14-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -17,15 +19,17 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-postgres14-down + run: just -f ci.Justfile ci-postgres14-down v15: name: postgres v15 runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-postgres15-up + run: just -f ci.Justfile ci-postgres15-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -34,4 +38,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-postgres15-down + run: just -f ci.Justfile ci-postgres15-down diff --git a/.github/workflows/build-sqlite3.yml b/.github/workflows/build-sqlite3.yml index 68dcfd5..edcb725 100644 --- a/.github/workflows/build-sqlite3.yml +++ b/.github/workflows/build-sqlite3.yml @@ -6,8 +6,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-sqlite3-up + run: just -f ci.Justfile ci-sqlite3-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -16,4 +18,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-sqlite3-down + run: just -f ci.Justfile ci-sqlite3-down diff --git a/.github/workflows/build-sqlserver.yml b/.github/workflows/build-sqlserver.yml index 4872703..d0ecdf1 100644 --- a/.github/workflows/build-sqlserver.yml +++ b/.github/workflows/build-sqlserver.yml @@ -6,8 +6,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 + - name: Install just + uses: extractions/setup-just@v2 - name: Build environment and run tests - run: make -f ci.Makefile ci-sqlserver-up + run: just -f ci.Justfile ci-sqlserver-up - name: Upload code coverage uses: codecov/codecov-action@v4 with: @@ -16,4 +18,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} verbose: true - name: Teardown - run: make -f ci.Makefile ci-sqlserver-down + run: just -f ci.Justfile ci-sqlserver-down diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 1590227..42c0262 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -20,5 +20,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.18 + - name: Install just + uses: extractions/setup-just@v2 - name: Vet source - run: make vet + run: just vet diff --git a/Justfile b/Justfile new file mode 100755 index 0000000..e00d484 --- /dev/null +++ b/Justfile @@ -0,0 +1,101 @@ +#!/usr/bin/env -S just -f + +GO := "go" +BIN_DIR := justfile_directory() / "bin" +PKG_IMPORT_PATH := "github.com/rafaelespinoza/godfish" +_CORE_SRC_PKG_PATHS := PKG_IMPORT_PATH + " " + PKG_IMPORT_PATH / "internal" / "..." +_BASE_DRIVER_PATH := PKG_IMPORT_PATH / "drivers" +_LDFLAGS_BASE_PREFIX := "-X " + PKG_IMPORT_PATH + "/internal/cmd" +_LDFLAGS_DELIMITER := "\n\t" +LDFLAGS := ( + _LDFLAGS_BASE_PREFIX + ".versionBranchName=" + `git rev-parse --abbrev-ref HEAD` + _LDFLAGS_DELIMITER + + _LDFLAGS_BASE_PREFIX + ".versionBuildTime=" + `date --utc +%FT%T%z` + _LDFLAGS_DELIMITER + + _LDFLAGS_BASE_PREFIX + ".versionCommitHash=" + `git rev-parse --short=7 HEAD` + _LDFLAGS_DELIMITER + + _LDFLAGS_BASE_PREFIX + ".versionGoVersion=" + `go version | awk '{ print $3 }'` + _LDFLAGS_DELIMITER + + _LDFLAGS_BASE_PREFIX + ".versionTag=" + `git describe --tag 2>/dev/null || echo 'dev'` + _LDFLAGS_DELIMITER +) + +# list available recipes +@default: + {{ justfile() }} --list --unsorted + +# run unit tests on core source packages +test ARGS='': + {{ GO }} test {{ ARGS }} {{ _CORE_SRC_PKG_PATHS }} + +# examine source code for suspicious constructs +vet ARGS='': + {{ GO }} vet {{ ARGS }} {{ _CORE_SRC_PKG_PATHS }} {{ PKG_IMPORT_PATH }}/drivers/... + +# Remove BIN_DIR +clean: + rm -rf {{ BIN_DIR }} + +GOSEC := "gosec" + +# This Justfile won't install the scanner binary for you, so check out the +# gosec README for instructions: https://github.com/securego/gosec +# +# If necessary, specify the path to the built binary with the GOSEC variable. +# +# Also note, the package paths (last positional input to gosec command) should +# be a "relative" package path. That is, starting with a dot. +# +# Run a security scanner over the source code +gosec ARGS='': + {{ GOSEC }} {{ ARGS }} . ./internal/... ./drivers/... + +_CASSANDRA_PATH := _BASE_DRIVER_PATH / "cassandra" + +# Compile binary for cassandra driver +build-cassandra: (_build_driver "cassandra" (_CASSANDRA_PATH / "godfish")) + +# Run unit tests on a live cassandra instance at DB_DSN +test-cassandra ARGS='': + {{ GO }} test {{ ARGS }} {{ _CASSANDRA_PATH }}/... + +_MYSQL_PATH := _BASE_DRIVER_PATH / "mysql" + +# Compile binary for mysql driver +build-mysql: (_build_driver "mysql" (_MYSQL_PATH / "godfish")) + +# Run unit tests on a live mysql instance at DB_DSN +test-mysql ARGS='': + {{ GO }} test {{ ARGS }} {{ _MYSQL_PATH }}/... + +_POSTGRES_PATH := _BASE_DRIVER_PATH / "postgres" + +# Compile binary for postgres driver +build-postgres: (_build_driver "postgres" (_POSTGRES_PATH / "godfish")) + +# Run unit tests on a live postgres instance at DB_DSN +test-postgres ARGS='': + {{ GO }} test {{ ARGS }} {{ _POSTGRES_PATH }}/... + +_SQLSERVER_PATH := _BASE_DRIVER_PATH / "sqlserver" + +# Compile binary for sqlserver driver +build-sqlserver: (_build_driver "sqlserver" (_SQLSERVER_PATH / "godfish")) + +# Run unit tests on a live sqlserver instance at DB_DSN +test-sqlserver ARGS='': + {{ GO }} test {{ ARGS }} {{ _SQLSERVER_PATH }}/... + +_SQLITE3_PATH := _BASE_DRIVER_PATH / "sqlite3" + +# Compile binary for sqlite3 driver +build-sqlite3: (_build_driver "sqlite3" (_SQLITE3_PATH / "godfish")) + +# Run unit tests on a live sqlite3 instance at DB_DSN +test-sqlite3 ARGS='': + {{ GO }} test {{ ARGS }} {{ _SQLITE3_PATH }}/... + +_build_driver DRIVER_NAME SRC_PATH: + #!/bin/sh + set -eu + bin={{ clean(BIN_DIR / "godfish_" + DRIVER_NAME) }} + mkdir -pv {{ BIN_DIR }} + ldflags="{{ LDFLAGS }}{{ _LDFLAGS_BASE_PREFIX }}.versionDriver={{ DRIVER_NAME }}" + {{ GO }} build -o="${bin}" -v -ldflags="${ldflags}" {{ SRC_PATH }} + "${bin}" version + echo "built {{ DRIVER_NAME }} to ${bin}" diff --git a/Makefile b/Makefile deleted file mode 100644 index 52b283b..0000000 --- a/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -GO ?= go -BIN_DIR=bin -PKG_IMPORT_PATH=github.com/rafaelespinoza/godfish -GOSEC ?= gosec - -CORE_SRC_PKG_PATHS=$(PKG_IMPORT_PATH) $(PKG_IMPORT_PATH)/internal/... -CASSANDRA_PATH=$(PKG_IMPORT_PATH)/drivers/cassandra -SQLSERVER_PATH=$(PKG_IMPORT_PATH)/drivers/sqlserver -MYSQL_PATH=$(PKG_IMPORT_PATH)/drivers/mysql -POSTGRES_PATH=$(PKG_IMPORT_PATH)/drivers/postgres -SQLITE3_PATH=$(PKG_IMPORT_PATH)/drivers/sqlite3 - -# inject this metadata when building a binary. -define LDFLAGS --X $(PKG_IMPORT_PATH)/internal/cmd.versionBranchName=$(shell git rev-parse --abbrev-ref HEAD) \ --X $(PKG_IMPORT_PATH)/internal/cmd.versionBuildTime=$(shell date --utc +%FT%T%z) \ --X $(PKG_IMPORT_PATH)/internal/cmd.versionCommitHash=$(shell git rev-parse --short=7 HEAD) \ --X $(PKG_IMPORT_PATH)/internal/cmd.versionGoVersion=$(shell $(GO) version | awk '{ print $$3 }') \ --X $(PKG_IMPORT_PATH)/internal/cmd.versionTag=$(shell git describe --tag) -endef - -test: - $(GO) test $(ARGS) $(CORE_SRC_PKG_PATHS) - -vet: - $(GO) vet $(ARGS) $(CORE_SRC_PKG_PATHS) $(PKG_IMPORT_PATH)/drivers/... - -clean: - rm -rf $(BIN_DIR) - -_mkdir: - mkdir -pv $(BIN_DIR) - -# Run a security scanner over the source code. This Makefile won't install the -# scanner binary for you, so check out the gosec README for instructions: -# https://github.com/securego/gosec -# -# If necessary, specify the path to the built binary with the GOSEC env var. -# -# Also note, the package paths (last positional input to gosec command) should -# be a "relative" package path. That is, starting with a dot. -gosec: - $(GOSEC) $(ARGS) . ./internal/... ./drivers/... - -# -# Cassandra -# -build-cassandra: BIN=$(BIN_DIR)/godfish_cassandra -build-cassandra: _mkdir - $(GO) build -o $(BIN) -v \ - -ldflags "$(LDFLAGS) \ - -X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=cassandra" \ - $(CASSANDRA_PATH)/godfish - @echo "built cassandra to $(BIN)" -test-cassandra: - $(GO) test $(ARGS) $(CASSANDRA_PATH)/... - -# -# Postgres -# -build-postgres: BIN=$(BIN_DIR)/godfish_postgres -build-postgres: _mkdir - $(GO) build -o $(BIN) -v \ - -ldflags "$(LDFLAGS) \ - -X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=postgres" \ - $(POSTGRES_PATH)/godfish - @echo "built postgres to $(BIN)" -test-postgres: - $(GO) test $(ARGS) $(POSTGRES_PATH)/... - -# -# Microsoft SQL Server -# -build-sqlserver: BIN=$(BIN_DIR)/godfish_sqlserver -build-sqlserver: - $(GO) build -o $(BIN) -v \ - -ldflags "$(LDFLAGS) \ - -X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=sqlserver" \ - $(SQLSERVER_PATH)/godfish - @echo "built sqlserver to $(BIN)" -test-sqlserver: - $(GO) test $(ARGS) $(SQLSERVER_PATH)/... - -# -# MySQL -# -build-mysql: BIN=$(BIN_DIR)/godfish_mysql -build-mysql: _mkdir - $(GO) build -o $(BIN) -v \ - -ldflags "$(LDFLAGS) \ - -X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=mysql" \ - $(MYSQL_PATH)/godfish - @echo "built mysql to $(BIN)" -test-mysql: - $(GO) test $(ARGS) $(MYSQL_PATH)/... - -# -# SQLite3 -# -build-sqlite3: BIN=$(BIN_DIR)/godfish_sqlite3 -build-sqlite3: _mkdir - $(GO) build -o $(BIN) -v \ - -ldflags "$(LDFLAGS) \ - -X $(PKG_IMPORT_PATH)/internal/cmd.versionDriver=sqlite3" \ - $(SQLITE3_PATH)/godfish - @echo "built sqlite3 to $(BIN)" -test-sqlite3: - $(GO) test $(ARGS) $(SQLITE3_PATH)/... diff --git a/README.md b/README.md index 58ce2a7..ee80b47 100644 --- a/README.md +++ b/README.md @@ -22,15 +22,17 @@ ## build +NOTE: these require [just](https://just.systems). + Make a CLI binary for the DB you want to use. This tool comes with some driver implementations. Build one like so: ``` -make build-cassandra -make build-mysql -make build-postgres -make build-sqlite3 -make build-sqlserver +just build-cassandra +just build-mysql +just build-postgres +just build-sqlite3 +just build-sqlserver ``` From there you could move it to `$GOPATH/bin`, move it to your project or @@ -147,45 +149,45 @@ generated godoc looks weird. There are also tests, those should pass. The GitHub Actions run a security scanner on all of the source code using [gosec](https://github.com/securego/gosec). There should be no rule violations -here. The Makefile provides a convenience target if you want to run `gosec` on +here. The Justfile provides a convenience target if you want to run `gosec` on your development machine. ## tests Docker and docker-compose are used to create environments and run the tests against a live database. Each database has a separate configuration. All of this -lives in `ci.Makefile` and the `.ci/` directory. +lives in `ci.Justfile` and the `.ci/` directory. Build environments and run tests ```sh -make -f ci.Makefile ci-cassandra3-up -make -f ci.Makefile ci-cassandra4-up +just -f ci.Justfile ci-cassandra3-up +just -f ci.Justfile ci-cassandra4-up -make -f ci.Makefile ci-sqlserver-up +just -f ci.Justfile ci-sqlserver-up -make -f ci.Makefile ci-mariadb-up -make -f ci.Makefile ci-mysql57-up -make -f ci.Makefile ci-mysql8-up +just -f ci.Justfile ci-mariadb-up +just -f ci.Justfile ci-mysql57-up +just -f ci.Justfile ci-mysql8-up -make -f ci.Makefile ci-postgres14-up -make -f ci.Makefile ci-postgres15-up +just -f ci.Justfile ci-postgres14-up +just -f ci.Justfile ci-postgres15-up -make -f ci.Makefile ci-sqlite3-up +just -f ci.Justfile ci-sqlite3-up ``` Teardown ```sh -make -f ci.Makefile ci-cassandra3-down -make -f ci.Makefile ci-cassandra4-down +just -f ci.Justfile ci-cassandra3-down +just -f ci.Justfile ci-cassandra4-down -make -f ci.Makefile ci-sqlserver-down +just -f ci.Justfile ci-sqlserver-down -make -f ci.Makefile ci-mariadb-down -make -f ci.Makefile ci-mysql57-down -make -f ci.Makefile ci-mysql8-down +just -f ci.Justfile ci-mariadb-down +just -f ci.Justfile ci-mysql57-down +just -f ci.Justfile ci-mysql8-down -make -f ci.Makefile ci-postgres14-down -make -f ci.Makefile ci-postgres15-down +just -f ci.Justfile ci-postgres14-down +just -f ci.Justfile ci-postgres15-down -make -f ci.Makefile ci-sqlite3-down +just -f ci.Justfile ci-sqlite3-down ``` diff --git a/ci.Justfile b/ci.Justfile new file mode 100755 index 0000000..1ef3fa0 --- /dev/null +++ b/ci.Justfile @@ -0,0 +1,111 @@ +#!/usr/bin/env -S just -f + +BASENAME := "godfish_test" +CI_DIR := justfile_directory() / ".ci" +BASE_BUILD_DIR := "/tmp" / BASENAME + +# +# Build CI environment, run test suite against a live DB. +# NOTE: The client entrypoints require the other Justfile. +# + +# list available recipes +@default: + {{ justfile() }} --list --unsorted + +CASSANDRA_V3_FILE := CI_DIR / "cassandra" / "v3.yml" + +# setup, perform integration tests for cassandra driver, server v3 +ci-cassandra3-up: (_up "cassandra_v3" CASSANDRA_V3_FILE) + +# cleanup integration test environment for cassandra driver, cassandra server v3 +ci-cassandra3-down: (_docker_compose_down CASSANDRA_V3_FILE) + +CASSANDRA_V4_FILE := CI_DIR / "cassandra" / "v4.yml" + +# setup, perform integration tests for cassandra driver, cassandra server v4 +ci-cassandra4-up: (_up "cassandra_v4" CASSANDRA_V4_FILE) + +# cleanup integration test environment for cassandra driver, cassandra server v4 +ci-cassandra4-down: (_docker_compose_down CASSANDRA_V4_FILE) + +MARIA_DB_FILE := CI_DIR / "mysql" / "mariadb_v10.yml" + +# setup, perform integration tests for mysql driver, mariadb server +ci-mariadb-up: (_up "mariadb" MARIA_DB_FILE) + +# cleanup integration test environment for mysql driver, mariadb server +ci-mariadb-down: (_docker_compose_down MARIA_DB_FILE) + +MYSQL_V57_FILE := CI_DIR / "mysql" / "mysql_v57.yml" + +# setup, perform integration tests for mysql driver, mysql v5.7 server +ci-mysql57-up: (_up "mysql_v57" MYSQL_V57_FILE) + +# cleanup integration test environment for mysql driver, mysql v5.7 server +ci-mysql57-down: (_docker_compose_down MYSQL_V57_FILE) + +MYSQL_V8_FILE := CI_DIR / "mysql" / "mysql_v8.yml" + +# setup, perform integration tests for mysql driver, mysql v8 server +ci-mysql8-up: (_up "mysql_v8" MYSQL_V8_FILE) + +# cleanup integration test environment for mysql driver, mysql v8 server +ci-mysql8-down: (_docker_compose_down MYSQL_V8_FILE) + +POSTGRES_V14_FILE := CI_DIR / "postgres" / "v14.yml" + +# setup, perform integration tests for postgres driver, postgres v14 server +ci-postgres14-up: (_up "postgres_v14" POSTGRES_V14_FILE) + +# cleanup integration test environment for postgres driver, postgres v14 server +ci-postgres14-down: (_docker_compose_down POSTGRES_V14_FILE) + +POSTGRES_V15_FILE := CI_DIR / "postgres" / "v15.yml" + +# setup, perform integration tests for postgres driver, postgres v15 server +ci-postgres15-up: (_up "postgres_v15" POSTGRES_V15_FILE) + +# cleanup integration test environment for postgres driver, postgres v15 server +ci-postgres15-down: (_docker_compose_down POSTGRES_V15_FILE) + +SQLITE3_FILE := CI_DIR / "sqlite3" / "docker-compose.yml" + +# setup, perform integration tests for sqlite3 driver +ci-sqlite3-up: (_up "sqlite3" SQLITE3_FILE) + +# cleanup integration test environment for sqlite3 driver +ci-sqlite3-down: (_docker_compose_down SQLITE3_FILE) + +SQLSERVER_FILE := CI_DIR / "sqlserver" / "docker-compose.yml" + +# setup, perform integration tests for sqlserver driver +ci-sqlserver-up: (_up "sqlserver" SQLSERVER_FILE) + +# cleanup integration test environment for sqlserver driver +ci-sqlserver-down: (_docker_compose_down SQLSERVER_FILE) + +_up DRIVER_BASENAME COMPOSE_FILE: (build-base DRIVER_BASENAME) (_docker_compose_up DRIVER_BASENAME COMPOSE_FILE) (_cp_coverage_to_host COMPOSE_FILE) + +_docker_compose_up DRIVER_BASENAME COMPOSE_FILE: + BUILD_DIR={{ clean(BASE_BUILD_DIR / DRIVER_BASENAME) }} docker-compose -f {{ COMPOSE_FILE }} up --build --exit-code-from client + +_cp_coverage_to_host COMPOSE_FILE: + {{ CI_DIR }}/cp_coverage_to_host.sh {{ COMPOSE_FILE }} + +_docker_compose_down COMPOSE_FILE: + docker-compose -f {{ COMPOSE_FILE }} down --rmi all --volumes + +# Build and tag base image +build-base DRIVER_BASENAME: + #!/bin/sh + set -eu + build_dir={{ clean(BASE_BUILD_DIR / DRIVER_BASENAME) }} + [ -d "${build_dir}" ] && rm -rf "${build_dir}" + mkdir -pv "${build_dir}" && chmod -v 700 "${build_dir}" + git clone --depth=1 file://{{ justfile_directory() }} "${build_dir}" + docker image build -f {{ CI_DIR }}/client_base.Dockerfile -t {{ BASENAME }}/client_base "${build_dir}" + +# Remove base image +rmi-base: + docker image rmi $(docker image ls -aq {{ BASENAME }}/client_base) diff --git a/ci.Makefile b/ci.Makefile deleted file mode 100644 index f1f313e..0000000 --- a/ci.Makefile +++ /dev/null @@ -1,89 +0,0 @@ -BASENAME=godfish_test -CI_DIR=./.ci - -# -# Build CI environment, run test suite against a live DB. -# NOTE: The client entrypoints require the other Makefile. -# -CASSANDRA_V3_FILE=$(CI_DIR)/cassandra/v3.yml -ci-cassandra3-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(CASSANDRA_V3_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(CASSANDRA_V3_FILE) -ci-cassandra3-down: - docker-compose -f $(CASSANDRA_V3_FILE) down --rmi all --volumes - -CASSANDRA_V4_FILE=$(CI_DIR)/cassandra/v4.yml -ci-cassandra4-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(CASSANDRA_V4_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(CASSANDRA_V4_FILE) -ci-cassandra4-down: - docker-compose -f $(CASSANDRA_V4_FILE) down --rmi all --volumes - -POSTGRES_V14_FILE=$(CI_DIR)/postgres/v14.yml -ci-postgres14-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(POSTGRES_V14_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(POSTGRES_V14_FILE) -ci-postgres14-down: - docker-compose -f $(POSTGRES_V14_FILE) down --rmi all --volumes - -POSTGRES_V15_FILE=$(CI_DIR)/postgres/v15.yml -ci-postgres15-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(POSTGRES_V15_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(POSTGRES_V15_FILE) -ci-postgres15-down: - docker-compose -f $(POSTGRES_V15_FILE) down --rmi all --volumes - -MARIA_DB_FILE=$(CI_DIR)/mysql/mariadb_v10.yml -ci-mariadb-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(MARIA_DB_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(MARIA_DB_FILE) -ci-mariadb-down: - docker-compose -f $(MARIA_DB_FILE) down --rmi all --volumes - -MYSQL_V57_FILE=$(CI_DIR)/mysql/mysql_v57.yml -ci-mysql57-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(MYSQL_V57_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(MYSQL_V57_FILE) -ci-mysql57-down: - docker-compose -f $(MYSQL_V57_FILE) down --rmi all --volumes - -MYSQL_V8_FILE=$(CI_DIR)/mysql/mysql_v8.yml -ci-mysql8-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(MYSQL_V8_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(MYSQL_V8_FILE) -ci-mysql8-down: - docker-compose -f $(MYSQL_V8_FILE) down --rmi all --volumes - -SQLITE3_FILE=$(CI_DIR)/sqlite3/docker-compose.yml -ci-sqlite3-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(SQLITE3_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(SQLITE3_FILE) -ci-sqlite3-down: - docker-compose -f $(SQLITE3_FILE) down --rmi all --volumes - -SQLSERVER_FILE=$(CI_DIR)/sqlserver/docker-compose.yml -ci-sqlserver-up: build-base - BUILD_DIR=$(BUILD_DIR) docker-compose -f $(SQLSERVER_FILE) up --build --exit-code-from client && \ - .ci/cp_coverage_to_host.sh $(SQLSERVER_FILE) -ci-sqlserver-down: - docker-compose -f $(SQLSERVER_FILE) down --rmi all --volumes - -# -# Build and tag base image. -# -# Initializing the BUILD_DIR variable is written this way to address the same -# issue described at https://stackoverflow.com/q/1909188. That is, create a temp -# dir and capture the name, but only when this rule is invoked rather than every -# single time the file is parsed. This avoids creating a bunch of empty temp -# dirs, which is annoying. -# -build-base: - $(eval BUILD_DIR=$(shell mktemp -d -p /tmp $(BASENAME)_XXXXXX)) - git clone --depth=1 file://$(PWD) $(BUILD_DIR) - docker image build -f $(CI_DIR)/client_base.Dockerfile -t $(BASENAME)/client_base $(BUILD_DIR) - -# -# More cleanup stuff. -# -rmi-base: - docker image rmi $(shell docker image ls -aq $(BASENAME)/client_base)