From bc40d3743bb9b28bd4f364cc0fd5f262d943638d Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 00:36:52 +0800 Subject: [PATCH 01/44] chore(prisma): upgrade to prisma 4.9.0 --- .github/workflows/integration-test.yml | 2 +- binaries/binaries.go | 4 +-- binaries/bindata/bindata.go | 15 ++-------- generator/run.go | 4 +-- test/integration/integration.dockerfile | 4 ++- test/integration/schemax.prisma | 37 +++++++++++++------------ 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 97d65208..44521240 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -16,4 +16,4 @@ jobs: - uses: actions/checkout@v3 - name: integration - run: docker build . -f test/integration/integration.dockerfile -t integration && docker run integration + run: docker build . --platform linux/amd64 -f test/integration/integration.dockerfile -t integration && docker run --platform linux/amd64 integration diff --git a/binaries/binaries.go b/binaries/binaries.go index f5d354c4..2629569f 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -15,11 +15,11 @@ import ( ) // PrismaVersion is a hardcoded version of the Prisma CLI. -const PrismaVersion = "4.7.1" +const PrismaVersion = "4.9.0" // EngineVersion is a hardcoded version of the Prisma Engine. // The versions can be found under https://github.com/prisma/prisma-engines/commits/master -const EngineVersion = "272861e07ab64f234d3ffc4094e32bd61775599c" +const EngineVersion = "ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5" // PrismaURL points to an S3 bucket URL where the CLI binaries are stored. var PrismaURL = "https://packaged-cli.prisma.sh/%s-%s-%s-x64.gz" diff --git a/binaries/bindata/bindata.go b/binaries/bindata/bindata.go index a2abe4eb..9750dca3 100644 --- a/binaries/bindata/bindata.go +++ b/binaries/bindata/bindata.go @@ -34,23 +34,12 @@ func WriteFile(name, pkg, platform, from, to string) error { func writeHeader(w io.Writer, pkg, name, platform string) error { var constraints string if platform == "linux" { - if name == "linux" { - // TODO dynamically construct these with allTargets in run.go - // TODO only include these for engines, not for the CLI - constraints = `// +build !debian_openssl_1_0_x -// +build !debian_openssl_1_1_x -// +build !rhel_openssl_1_0_x -// +build !rhel_openssl_1_1_x` - constraints += "\n" - } else { - constraints = "// +build linux\n" - } + constraints = "// +build linux\n" } _, err := fmt.Fprintf(w, `// Code generated by Prisma Client Go. DO NOT EDIT. //nolint // +build !codeanalysis -// +build %s // +build !prisma_ignore %s package %s @@ -62,7 +51,7 @@ import ( func init() { unpack.Unpack(data, "%s", "%s") } -`, name, constraints, pkg, name, binaries.EngineVersion) +`, constraints, pkg, name, binaries.EngineVersion) return err } diff --git a/generator/run.go b/generator/run.go index b7a1652b..6dd48c86 100644 --- a/generator/run.go +++ b/generator/run.go @@ -149,7 +149,6 @@ func generateBinaries(input *Root) error { } targets = add(targets, "native") - targets = add(targets, "linux") // TODO refactor for _, name := range targets { @@ -178,6 +177,7 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name) + // TODO change pt := name if strings.Contains(name, "debian") || strings.Contains(name, "rhel") { pt = "linux" @@ -187,7 +187,7 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err to := path.Join(outputDir, filename) // TODO check if already exists, but make sure version matches - if err := bindata.WriteFile(strings.ReplaceAll(name, "-", "_"), pkg, pt, enginePath, to); err != nil { + if err := bindata.WriteFile(name, pkg, pt, enginePath, to); err != nil { return fmt.Errorf("generate write go file: %w", err) } diff --git a/test/integration/integration.dockerfile b/test/integration/integration.dockerfile index 3a6af263..e40cc68f 100644 --- a/test/integration/integration.dockerfile +++ b/test/integration/integration.dockerfile @@ -13,6 +13,8 @@ RUN go mod download -x RUN go run github.com/prisma/prisma-client-go db push --schema schemax.prisma +RUN ls -Rlah /app/test/integration + # build the integration binary with all dependencies RUN go build -o /app/main . @@ -24,7 +26,7 @@ WORKDIR /app COPY --from=build /app/main /app/main COPY --from=build /app/test/integration/dev.db /app/dev.db -ENV PRISMA_CLIENT_GO_LOG=info +ENV PRISMA_CLIENT_GO_LOG=debug ENV DEBUG=* CMD ["/app/main"] diff --git a/test/integration/schemax.prisma b/test/integration/schemax.prisma index 6261e412..c41db74d 100644 --- a/test/integration/schemax.prisma +++ b/test/integration/schemax.prisma @@ -1,31 +1,32 @@ datasource db { - provider = "sqlite" - url = "file:dev.db" + provider = "sqlite" + url = "file:dev.db" } generator db { - provider = "go run github.com/prisma/prisma-client-go" - disableGitignore = true + provider = "go run github.com/prisma/prisma-client-go" + disableGitignore = true + binaryTargets = ["debian-openssl-1.1.x"] } model User { - id String @default(cuid()) @id @map("_id") - createdAt DateTime @default(now()) - email String @unique - name String? - age Int? + id String @default(cuid()) @id @map("_id") + createdAt DateTime @default(now()) + email String @unique + name String? + age Int? - posts Post[] + posts Post[] } model Post { - id String @default(cuid()) @id @map("_id") - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - published Boolean - title String - content String? + id String @default(cuid()) @id @map("_id") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + published Boolean + title String + content String? - author User @relation(fields: [authorID], references: [id]) - authorID String + author User @relation(fields: [authorID], references: [id]) + authorID String } From 491e2a7b963517b74755e27fbee9ddb3dcc462ec Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 13:00:50 +0800 Subject: [PATCH 02/44] chore(prisma): upgrade to prisma 4.10.0 --- binaries/binaries.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 2629569f..48da8635 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -15,11 +15,11 @@ import ( ) // PrismaVersion is a hardcoded version of the Prisma CLI. -const PrismaVersion = "4.9.0" +const PrismaVersion = "4.10.0" // EngineVersion is a hardcoded version of the Prisma Engine. // The versions can be found under https://github.com/prisma/prisma-engines/commits/master -const EngineVersion = "ceb5c99003b99c9ee2c1d2e618e359c14aef2ea5" +const EngineVersion = "ca7fcef713137fa11029d519a9780db130cca91d" // PrismaURL points to an S3 bucket URL where the CLI binaries are stored. var PrismaURL = "https://packaged-cli.prisma.sh/%s-%s-%s-x64.gz" From 6146228d07877f401a710d0b95bb4f2ce0dd7fd4 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 13:04:54 +0800 Subject: [PATCH 03/44] fix(bindata): always use platform constraint --- binaries/bindata/bindata.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/binaries/bindata/bindata.go b/binaries/bindata/bindata.go index 9750dca3..e5913dce 100644 --- a/binaries/bindata/bindata.go +++ b/binaries/bindata/bindata.go @@ -32,16 +32,12 @@ func WriteFile(name, pkg, platform, from, to string) error { } func writeHeader(w io.Writer, pkg, name, platform string) error { - var constraints string - if platform == "linux" { - constraints = "// +build linux\n" - } _, err := fmt.Fprintf(w, `// Code generated by Prisma Client Go. DO NOT EDIT. //nolint // +build !codeanalysis // +build !prisma_ignore -%s +// +build %s package %s import ( @@ -51,7 +47,7 @@ import ( func init() { unpack.Unpack(data, "%s", "%s") } -`, constraints, pkg, name, binaries.EngineVersion) +`, platform, pkg, name, binaries.EngineVersion) return err } From 195cccb6631d37f52de9b26b059663b7e4792473 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 16:52:14 +0800 Subject: [PATCH 04/44] test(binaries): remove native option --- test/projects/binaries/schema.prisma | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/projects/binaries/schema.prisma b/test/projects/binaries/schema.prisma index 0245daf4..922f36a5 100644 --- a/test/projects/binaries/schema.prisma +++ b/test/projects/binaries/schema.prisma @@ -1,20 +1,20 @@ datasource db { - provider = "sqlite" - url = env("__REPLACE__") + provider = "sqlite" + url = env("__REPLACE__") } generator db { - provider = "go run github.com/prisma/prisma-client-go" - output = "." - disableGitignore = true - package = "binaries" - binaryTargets = ["native", "debian-openssl-1.1.x"] + provider = "go run github.com/prisma/prisma-client-go" + output = "." + disableGitignore = true + package = "binaries" + binaryTargets = ["debian-openssl-1.1.x"] } model User { - id String @id @default(cuid()) @map("_id") - email String @unique - username String - name String? - stuff String? + id String @id @default(cuid()) @map("_id") + email String @unique + username String + name String? + stuff String? } From 7324b6771e983e79fcb7bbbd6718eb18f8a2a0e5 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 16:53:55 +0800 Subject: [PATCH 05/44] fix(binaries): remove introspection & fmt --- binaries/binaries.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 48da8635..7769d270 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -38,12 +38,6 @@ var Engines = []Engine{{ }, { "migration-engine", "PRISMA_MIGRATION_ENGINE_BINARY", -}, { - "introspection-engine", - "PRISMA_INTROSPECTION_ENGINE_BINARY", -}, { - "prisma-fmt", - "PRISMA_FMT_BINARY", }} // init overrides URLs if env variables are specific for debugging purposes and to From 2af555f5d04fc51152b98fc879422e64e35f6318 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 17:10:54 +0800 Subject: [PATCH 06/44] remove binary targets --- test/integration/schemax.prisma | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/schemax.prisma b/test/integration/schemax.prisma index c41db74d..d147787f 100644 --- a/test/integration/schemax.prisma +++ b/test/integration/schemax.prisma @@ -6,7 +6,6 @@ datasource db { generator db { provider = "go run github.com/prisma/prisma-client-go" disableGitignore = true - binaryTargets = ["debian-openssl-1.1.x"] } model User { From 374b59a106cd737254f745623b2a97416ec32d30 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 17:35:04 +0800 Subject: [PATCH 07/44] reformat build tags --- binaries/bindata/bindata.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/binaries/bindata/bindata.go b/binaries/bindata/bindata.go index e5913dce..e0fa77eb 100644 --- a/binaries/bindata/bindata.go +++ b/binaries/bindata/bindata.go @@ -34,10 +34,10 @@ func WriteFile(name, pkg, platform, from, to string) error { func writeHeader(w io.Writer, pkg, name, platform string) error { _, err := fmt.Fprintf(w, `// Code generated by Prisma Client Go. DO NOT EDIT. +//go:build !codeanalysis && !prisma_ignore && %s +// +build !codeanalysis,!prisma_ignore,%s + //nolint -// +build !codeanalysis -// +build !prisma_ignore -// +build %s package %s import ( @@ -47,7 +47,7 @@ import ( func init() { unpack.Unpack(data, "%s", "%s") } -`, platform, pkg, name, binaries.EngineVersion) +`, platform, platform, pkg, name, binaries.EngineVersion) return err } From 646e2255d57fa8b68326519c365dc917a3b5609a Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 17:35:47 +0800 Subject: [PATCH 08/44] fix(generator): remove introspection engine field --- generator/generator.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/generator/generator.go b/generator/generator.go index 82a2fef7..97f11a32 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -94,6 +94,4 @@ type BinaryPaths struct { MigrationEngine map[string]string `json:"migrationEngine"` // key target, value path // QueryEngine (optional) QueryEngine map[string]string `json:"queryEngine"` - // IntrospectionEngine (optional) - IntrospectionEngine map[string]string `json:"introspectionEngine"` } From 9e399f582fca18e729afce01e5b8a181faa2e39a Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 17:54:50 +0800 Subject: [PATCH 09/44] fix(generator): ignore native when darwin or windows --- generator/run.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/generator/run.go b/generator/run.go index 6dd48c86..17a30894 100644 --- a/generator/run.go +++ b/generator/run.go @@ -143,12 +143,20 @@ func generateBinaries(input *Root) error { } var targets []string + var isNonLinux bool for _, target := range input.Generator.BinaryTargets { targets = append(targets, target.Value) + if target.Value == "darwin" || target.Value == "windows" { + isNonLinux = true + } } - targets = add(targets, "native") + // add native by default if native binary is darwin or linux + // this prevents conflicts when building on linux + if isNonLinux || len(targets) == 0 { + targets = add(targets, "native") + } // TODO refactor for _, name := range targets { From 3f13a381ab109d73efdd358c7b2481aafb1a012f Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 18:45:34 +0800 Subject: [PATCH 10/44] test(binaries): use openssl 3 --- test/projects/binaries/schema.prisma | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/projects/binaries/schema.prisma b/test/projects/binaries/schema.prisma index 922f36a5..a98aad9a 100644 --- a/test/projects/binaries/schema.prisma +++ b/test/projects/binaries/schema.prisma @@ -8,7 +8,8 @@ generator db { output = "." disableGitignore = true package = "binaries" - binaryTargets = ["debian-openssl-1.1.x"] + // GitHub actions uses debian with OpenSSL 3.0.x + binaryTargets = ["debian-openssl-3.0.x"] } model User { From 5cb41b1f50291186ce75717ff243c915aafbf3fd Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 18:45:52 +0800 Subject: [PATCH 11/44] ci(all): use ubuntu-22.04 --- .github/workflows/e2e-test.yml | 2 +- .github/workflows/integration-test.yml | 2 +- .github/workflows/lint-pr.yaml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/release-draft.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index c389ee2a..7d888d9f 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -5,7 +5,7 @@ env: jobs: e2e: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 44521240..551deac2 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] # macos is not supported by GitHub actions + os: [ubuntu-22.04] # macos is not supported by GitHub actions runs-on: ${{ matrix.os }} diff --git a/.github/workflows/lint-pr.yaml b/.github/workflows/lint-pr.yaml index 9f7cfcd0..dc22e634 100644 --- a/.github/workflows/lint-pr.yaml +++ b/.github/workflows/lint-pr.yaml @@ -10,7 +10,7 @@ env: jobs: enforce-semantic-title: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: amannn/action-semantic-pull-request@v5.1.0 env: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2aee20f5..928d6e1a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,7 +6,7 @@ env: jobs: lint: name: lint - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/release-draft.yml b/.github/workflows/release-draft.yml index 29318aca..9494f5ac 100644 --- a/.github/workflows/release-draft.yml +++ b/.github/workflows/release-draft.yml @@ -8,7 +8,7 @@ env: jobs: update-release-draft: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: release-drafter/release-drafter@v5 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index acbb0b34..a6ab7aea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ env: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 From 20c9a06d75fe2392acf638935863589aa067671c Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 18:59:40 +0800 Subject: [PATCH 12/44] fix(unpack): use unpacked QE --- binaries/unpack/unpack.go | 6 ++++++ engine/lifecycle.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/binaries/unpack/unpack.go b/binaries/unpack/unpack.go index b9173884..2f76936c 100644 --- a/binaries/unpack/unpack.go +++ b/binaries/unpack/unpack.go @@ -13,6 +13,8 @@ import ( // TODO check checksum after expanding file +const FileEnv = "PRISMA_INTERNAL_QUERY_ENGINE_DIR" + // noinspection GoUnusedExportedFunction func Unpack(data []byte, name string, version string) { start := time.Now() @@ -53,4 +55,8 @@ func Unpack(data []byte, name string, version string) { } logger.Debug.Printf("unpacked at %s in %s", file, time.Since(start)) + + if err := os.Setenv(FileEnv, file); err != nil { + panic(err) + } } diff --git a/engine/lifecycle.go b/engine/lifecycle.go index b8212647..cae4c350 100644 --- a/engine/lifecycle.go +++ b/engine/lifecycle.go @@ -14,6 +14,7 @@ import ( "github.com/prisma/prisma-client-go/binaries" "github.com/prisma/prisma-client-go/binaries/platform" + "github.com/prisma/prisma-client-go/binaries/unpack" "github.com/prisma/prisma-client-go/logger" ) @@ -101,6 +102,9 @@ func (e *QueryEngine) ensure() (string, error) { file = prismaQueryEngineBinary forceVersion = false + } else if qe := os.Getenv(unpack.FileEnv); qe != "" { + logger.Debug.Printf("using PRISMA_INTERNAL_QUERY_ENGINE_DIR %s", qe) + file = qe } else { if info, err := os.Stat(localExactPath); err == nil { file = localExactPath From aa3a76c59b0d92a0ac68f5c652d00fd7ec40472c Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 22:37:30 +0800 Subject: [PATCH 13/44] fix binaries schema --- test/projects/binaries/schema.prisma | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/projects/binaries/schema.prisma b/test/projects/binaries/schema.prisma index a98aad9a..11c9a676 100644 --- a/test/projects/binaries/schema.prisma +++ b/test/projects/binaries/schema.prisma @@ -8,8 +8,8 @@ generator db { output = "." disableGitignore = true package = "binaries" - // GitHub actions uses debian with OpenSSL 3.0.x - binaryTargets = ["debian-openssl-3.0.x"] + // GitHub actions uses debian with OpenSSL 1.1.x + binaryTargets = ["debian-openssl-1.1.x"] } model User { From f09c4fbeb4c5881fddcc8426a153d5fa57cd26f3 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 22:40:29 +0800 Subject: [PATCH 14/44] chore(integration): run just on ubuntu-22.04 --- .github/workflows/integration-test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 551deac2..d3e743ae 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -5,12 +5,7 @@ env: jobs: integration: - strategy: - fail-fast: false - matrix: - os: [ubuntu-22.04] # macos is not supported by GitHub actions - - runs-on: ${{ matrix.os }} + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 From 93aa27f1077b245f4d84fce3ff60652efb3b3971 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 8 Feb 2023 23:03:33 +0800 Subject: [PATCH 15/44] test(binaries): just check for requested binary --- test/projects/binaries/binaries_test.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/projects/binaries/binaries_test.go b/test/projects/binaries/binaries_test.go index 033ab609..a6cc54cf 100644 --- a/test/projects/binaries/binaries_test.go +++ b/test/projects/binaries/binaries_test.go @@ -5,17 +5,11 @@ import ( "testing" "github.com/stretchr/testify/assert" - - "github.com/prisma/prisma-client-go/binaries/platform" ) func TestBinaries(t *testing.T) { t.Parallel() - // this test only verifies that specifying `binaryTargets` downloaded the separate file into the directory - _, err := os.Stat("./query-engine-" + platform.BinaryPlatformName() + "_gen.go") - assert.Equal(t, err, nil) - - _, err = os.Stat("./query-engine-debian-openssl-1.1.x_gen.go") + _, err := os.Stat("./query-engine-debian-openssl-1.1.x_gen.go") assert.Equal(t, err, nil) } From c22164cac8857a62ea02ab563aefcb657a1a98d1 Mon Sep 17 00:00:00 2001 From: steebchen Date: Thu, 9 Feb 2023 01:43:05 +0800 Subject: [PATCH 16/44] Revert "chore(integration): run just on ubuntu-22.04" This reverts commit e4051a756e45a3ec881fa05f322b265bec357715. --- .github/workflows/integration-test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index d3e743ae..551deac2 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -5,7 +5,12 @@ env: jobs: integration: - runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04] # macos is not supported by GitHub actions + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 From f785f4abf46231eafdd7805fec06cf896666b402 Mon Sep 17 00:00:00 2001 From: steebchen Date: Thu, 9 Feb 2023 01:43:12 +0800 Subject: [PATCH 17/44] Revert "ci(all): use ubuntu-22.04" This reverts commit 843e059f95d2e786cc41107a81454569089bac24. --- .github/workflows/e2e-test.yml | 2 +- .github/workflows/integration-test.yml | 2 +- .github/workflows/lint-pr.yaml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/release-draft.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 7d888d9f..c389ee2a 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -5,7 +5,7 @@ env: jobs: e2e: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 551deac2..44521240 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04] # macos is not supported by GitHub actions + os: [ubuntu-latest] # macos is not supported by GitHub actions runs-on: ${{ matrix.os }} diff --git a/.github/workflows/lint-pr.yaml b/.github/workflows/lint-pr.yaml index dc22e634..9f7cfcd0 100644 --- a/.github/workflows/lint-pr.yaml +++ b/.github/workflows/lint-pr.yaml @@ -10,7 +10,7 @@ env: jobs: enforce-semantic-title: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: amannn/action-semantic-pull-request@v5.1.0 env: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 928d6e1a..2aee20f5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,7 +6,7 @@ env: jobs: lint: name: lint - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/release-draft.yml b/.github/workflows/release-draft.yml index 9494f5ac..29318aca 100644 --- a/.github/workflows/release-draft.yml +++ b/.github/workflows/release-draft.yml @@ -8,7 +8,7 @@ env: jobs: update-release-draft: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: release-drafter/release-drafter@v5 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a6ab7aea..acbb0b34 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ env: jobs: test: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 9e65348edca12764ef88fe6a5fe1add7d9f9abaa Mon Sep 17 00:00:00 2001 From: steebchen Date: Thu, 9 Feb 2023 12:01:30 +0800 Subject: [PATCH 18/44] fix(run): add more debug logs --- generator/run.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generator/run.go b/generator/run.go index 17a30894..ce1f73b8 100644 --- a/generator/run.go +++ b/generator/run.go @@ -145,6 +145,8 @@ func generateBinaries(input *Root) error { var targets []string var isNonLinux bool + logger.Debug.Printf("defined binary targets: %v", input.Generator.BinaryTargets) + for _, target := range input.Generator.BinaryTargets { targets = append(targets, target.Value) if target.Value == "darwin" || target.Value == "windows" { @@ -158,6 +160,8 @@ func generateBinaries(input *Root) error { targets = add(targets, "native") } + logger.Debug.Printf("final binary targets: %v", targets) + // TODO refactor for _, name := range targets { if name == "native" { From 9704096c7cf84b37d8e8a5252058e515ecc72bf9 Mon Sep 17 00:00:00 2001 From: steebchen Date: Thu, 9 Feb 2023 12:14:21 +0800 Subject: [PATCH 19/44] fix(run): adapt for musl --- generator/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/run.go b/generator/run.go index ce1f73b8..62634e72 100644 --- a/generator/run.go +++ b/generator/run.go @@ -191,7 +191,7 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err // TODO change pt := name - if strings.Contains(name, "debian") || strings.Contains(name, "rhel") { + if strings.Contains(name, "debian") || strings.Contains(name, "rhel") || strings.Contains(name, "musl") { pt = "linux" } From 3d709bfb0c7a023b94d79d268526c8511da4d51a Mon Sep 17 00:00:00 2001 From: steebchen Date: Thu, 9 Feb 2023 12:24:42 +0800 Subject: [PATCH 20/44] fix(run): check for PRISMA_CLI_BINARY_TARGETS --- generator/run.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generator/run.go b/generator/run.go index 62634e72..173b8fec 100644 --- a/generator/run.go +++ b/generator/run.go @@ -24,6 +24,16 @@ func addDefaults(input *Root) { if input.Generator.Config.Package == "" { input.Generator.Config.Package = DefaultPackageName } + + if binaryTargets := os.Getenv("PRISMA_CLI_BINARY_TARGETS"); binaryTargets != "" { + s := strings.Split(binaryTargets, ",") + var targets []BinaryTarget + for _, t := range s { + targets = append(targets, BinaryTarget{Value: t}) + } + input.Generator.BinaryTargets = targets + logger.Debug.Printf("overriding binary targets: %+v", targets) + } } // Run invokes the generator, which builds the templates and writes to the specified output file. From 352ab5d49e2ec3709b9b723a961028a376eb82eb Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Tue, 21 Feb 2023 16:06:31 +0700 Subject: [PATCH 21/44] fix(binaries): revert to 4.7.1 (#811) * revert to 4.7.1 * revert engines --- binaries/binaries.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 7769d270..f5d354c4 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -15,11 +15,11 @@ import ( ) // PrismaVersion is a hardcoded version of the Prisma CLI. -const PrismaVersion = "4.10.0" +const PrismaVersion = "4.7.1" // EngineVersion is a hardcoded version of the Prisma Engine. // The versions can be found under https://github.com/prisma/prisma-engines/commits/master -const EngineVersion = "ca7fcef713137fa11029d519a9780db130cca91d" +const EngineVersion = "272861e07ab64f234d3ffc4094e32bd61775599c" // PrismaURL points to an S3 bucket URL where the CLI binaries are stored. var PrismaURL = "https://packaged-cli.prisma.sh/%s-%s-%s-x64.gz" @@ -38,6 +38,12 @@ var Engines = []Engine{{ }, { "migration-engine", "PRISMA_MIGRATION_ENGINE_BINARY", +}, { + "introspection-engine", + "PRISMA_INTROSPECTION_ENGINE_BINARY", +}, { + "prisma-fmt", + "PRISMA_FMT_BINARY", }} // init overrides URLs if env variables are specific for debugging purposes and to From e8df90612926672b97cf09e767bac125efb34bfa Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Mon, 12 Jun 2023 15:59:02 +0100 Subject: [PATCH 22/44] Update integration-test.yml --- .github/workflows/integration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 36c00783..4c791fbd 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -33,4 +33,4 @@ jobs: - name: integration if: steps.changes.outputs.go == 'true' - run: docker build . --platform linux/amd64 -f test/integration/integration.dockerfile -t integration && docker run --platform linux/amd64 integration + run: docker build . -f test/integration/integration.dockerfile -t integration && docker run integration From 7255190a34dcda343afefde12b50a7b2963a346f Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Mon, 12 Jun 2023 16:24:53 +0100 Subject: [PATCH 23/44] Update integration.dockerfile --- test/integration/integration.dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/integration/integration.dockerfile b/test/integration/integration.dockerfile index 412bc6e4..a0d6a848 100644 --- a/test/integration/integration.dockerfile +++ b/test/integration/integration.dockerfile @@ -13,8 +13,6 @@ RUN go mod download -x RUN go run github.com/prisma/prisma-client-go db push --schema schemax.prisma -RUN ls -Rlah /app/test/integration - # build the integration binary with all dependencies RUN go build -o /app/main . From 1b25ab440fc1b0fefd3d4ff146e95b2ba1bdc77f Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 02:27:23 +0100 Subject: [PATCH 24/44] fix(binaries): adapt arch specific unpacking --- binaries/bindata/bindata.go | 2 +- binaries/unpack/unpack.go | 5 ++++- generator/run.go | 12 +++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/binaries/bindata/bindata.go b/binaries/bindata/bindata.go index 2bd90b52..53abc854 100644 --- a/binaries/bindata/bindata.go +++ b/binaries/bindata/bindata.go @@ -62,7 +62,7 @@ import ( func init() { unpack.Unpack(data, "%s", "%s") } -`, name, constraints, pkg, name, binaries.EngineVersion) +`, platform, constraints, pkg, name, binaries.EngineVersion) return err } diff --git a/binaries/unpack/unpack.go b/binaries/unpack/unpack.go index 15a2d0cc..1ea0c24c 100644 --- a/binaries/unpack/unpack.go +++ b/binaries/unpack/unpack.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path" + "strings" "time" "github.com/steebchen/prisma-client-go/binaries" @@ -17,6 +18,8 @@ import ( func Unpack(data []byte, name string, version string) { start := time.Now() + name = strings.ReplaceAll(name, "_", "-") + filename := fmt.Sprintf("prisma-query-engine-%s", name) // TODO check if dev env/dev binary in ~/.prisma @@ -31,7 +34,7 @@ func Unpack(data []byte, name string, version string) { } if _, err := os.Stat(file); err == nil { - logger.Debug.Printf("query engine exists, not unpacking. %s", time.Since(start)) + logger.Debug.Printf("query engine exists, not unpacking. %s. at %s", time.Since(start), file) return } diff --git a/generator/run.go b/generator/run.go index 2c36c111..7f4957d3 100644 --- a/generator/run.go +++ b/generator/run.go @@ -9,6 +9,7 @@ import ( "os" "path" "path/filepath" + "runtime" "strings" "text/template" @@ -172,17 +173,18 @@ func generateBinaries(input *Root) error { func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) error { for _, name := range binaryTargets { + pt := name + if strings.Contains(name, "debian") || strings.Contains(name, "rhel") { + pt = "linux" + } + if name == "native" { name = platform.BinaryPlatformName() + pt = runtime.GOOS } enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name) - pt := name - if strings.Contains(name, "debian") || strings.Contains(name, "rhel") { - pt = "linux" - } - filename := fmt.Sprintf("query-engine-%s_gen.go", name) to := path.Join(outputDir, filename) From 932139d1f5452a673578226ceafbb2a33dc4c62e Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 13:54:07 +0100 Subject: [PATCH 25/44] wip --- test/projects/binaries/schema.prisma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/projects/binaries/schema.prisma b/test/projects/binaries/schema.prisma index da3e150e..5e1fd442 100644 --- a/test/projects/binaries/schema.prisma +++ b/test/projects/binaries/schema.prisma @@ -8,7 +8,7 @@ generator db { output = "." disableGitignore = true package = "binaries" - // GitHub actions uses debian with OpenSSL 1.1.xbinaryTargets = ["debian-openssl-1.1.x"] + binaryTargets = ["debian-openssl-1.1.x"] } model User { From 6bf61484f4a106212602266ef38e52d453f587f0 Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 14:11:04 +0100 Subject: [PATCH 26/44] fix platform build --- generator/run.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/generator/run.go b/generator/run.go index f403d6f3..a4bf8108 100644 --- a/generator/run.go +++ b/generator/run.go @@ -194,14 +194,13 @@ func generateBinaries(input *Root) error { func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) error { for _, name := range binaryTargets { - pt := name + pt := runtime.GOOS if strings.Contains(name, "debian") || strings.Contains(name, "rhel") || strings.Contains(name, "musl") { pt = "linux" } if name == "native" { name = platform.BinaryPlatformName() - pt = runtime.GOOS } enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name) From 6371fd6d49592564c400b3676290ad487b118414 Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 16:04:03 +0100 Subject: [PATCH 27/44] debug --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c73707c..e7a9c9f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,3 +42,5 @@ jobs: - name: test if: steps.changes.outputs.go == 'true' run: go test ./... -v + env: + PRISMA_CLIENT_GO_LOG: debug From 3835e01cca8c568ff8f8a3d58163d4925713f562 Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 16:15:09 +0100 Subject: [PATCH 28/44] add static binary name --- binaries/binaries.go | 2 +- binaries/platform/platform.go | 25 ++++++++++++++++++++++--- cli/cli.go | 2 +- engine/lifecycle.go | 6 +++--- generator/run.go | 4 ++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index edba1b2d..0e2e1ac3 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -165,7 +165,7 @@ func GetEnginePath(dir, engine, binaryName string) string { } func DownloadEngine(name string, toDir string) (file string, err error) { - binaryName := platform.BinaryPlatformName() + binaryName := platform.BinaryPlatformNameDynamic() logger.Debug.Printf("checking %s...", name) diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index 2600ea47..3046c5d2 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -12,9 +12,9 @@ import ( var binaryNameWithSSLCache string -// BinaryPlatformName returns the name of the prisma binary which should be used, -// for example "darwin" or "linux-openssl-1.1.x" -func BinaryPlatformName() string { +// BinaryPlatformNameDynamic returns the name of the prisma binary which should be used, +// for example "darwin" or "linux-openssl-1.1.x". This can include dynamically linked binaries. +func BinaryPlatformNameDynamic() string { if binaryNameWithSSLCache != "" { return binaryNameWithSSLCache } @@ -47,6 +47,25 @@ func BinaryPlatformName() string { return name } +// BinaryPlatformNameStatic returns the name of the prisma binary which should be used, +// for example "darwin" or "linux-static-x64". This only includes statically linked binaries. +func BinaryPlatformNameStatic() string { + platform := Name() + arch := Arch() + + // other supported platforms are darwin and windows + if platform != "linux" { + // special case for darwin arm64 + if platform == "darwin" && arch == "arm64" { + return "darwin-arm64" + } + // otherwise, return `darwin` or `windows` + return platform + } + + return fmt.Sprintf("linux-static-%s", arch) +} + // Name returns the platform name func Name() string { return runtime.GOOS diff --git a/cli/cli.go b/cli/cli.go index 4ea17f47..a156faf8 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -28,7 +28,7 @@ func Run(arguments []string, output bool) error { logger.Debug.Printf("running %s %+v", path.Join(dir, prisma), arguments) cmd := exec.Command(path.Join(dir, prisma), arguments...) //nolint:gosec - binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformName()) + binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameDynamic()) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "PRISMA_HIDE_UPDATE_MESSAGE=true") diff --git a/engine/lifecycle.go b/engine/lifecycle.go index 739c99a4..f2131786 100644 --- a/engine/lifecycle.go +++ b/engine/lifecycle.go @@ -72,8 +72,8 @@ func (e *QueryEngine) ensure() (string, error) { binariesPath := binaries.GlobalUnpackDir(binaries.EngineVersion) // check for darwin/windows/linux first - binaryName := platform.CheckForExtension(platform.Name(), platform.Name()) - exactBinaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformName()) + binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameStatic()) + exactBinaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameDynamic()) var file string // forceVersion saves whether a version check should be done, which should be disabled @@ -103,7 +103,7 @@ func (e *QueryEngine) ensure() (string, error) { file = prismaQueryEngineBinary forceVersion = false } else if qe := os.Getenv(unpack.FileEnv); qe != "" { - logger.Debug.Printf("using PRISMA_INTERNAL_QUERY_ENGINE_DIR %s", qe) + logger.Debug.Printf("using unpacked file env %s %s", unpack.FileEnv, qe) file = qe } else { if info, err := os.Stat(localExactPath); err == nil { diff --git a/generator/run.go b/generator/run.go index a4bf8108..8fc7eed5 100644 --- a/generator/run.go +++ b/generator/run.go @@ -176,7 +176,7 @@ func generateBinaries(input *Root) error { // TODO refactor for _, name := range targets { if name == "native" { - name = platform.BinaryPlatformName() + name = platform.BinaryPlatformNameDynamic() } // first, ensure they are actually downloaded @@ -200,7 +200,7 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err } if name == "native" { - name = platform.BinaryPlatformName() + name = platform.BinaryPlatformNameDynamic() } enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name) From 9534c9d852cb352eaee313c78b7a4d1dbab6100f Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 16:32:11 +0100 Subject: [PATCH 29/44] use static --- generator/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/run.go b/generator/run.go index 8fc7eed5..7fe8a185 100644 --- a/generator/run.go +++ b/generator/run.go @@ -176,7 +176,7 @@ func generateBinaries(input *Root) error { // TODO refactor for _, name := range targets { if name == "native" { - name = platform.BinaryPlatformNameDynamic() + name = platform.BinaryPlatformNameStatic() } // first, ensure they are actually downloaded From feb03340ee08204993b9be64eac9f8c3d3e019fe Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 16:33:45 +0100 Subject: [PATCH 30/44] fail fast --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7a9c9f3..20cacf9c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,6 +41,6 @@ jobs: - name: test if: steps.changes.outputs.go == 'true' - run: go test ./... -v + run: go test ./... -v -failfast env: PRISMA_CLIENT_GO_LOG: debug From 5205e38d38367cc4bd49ba4630f845caf45166ca Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 16:38:44 +0100 Subject: [PATCH 31/44] logs --- binaries/binaries.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 0e2e1ac3..1f67ce4e 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -95,17 +95,18 @@ func FetchEngine(toDir string, engineName string, binaryPlatformName string) err if binaryPlatformRemoteName == "linux" { binaryPlatformRemoteName = "linux-static-x64" } - url := platform.CheckForExtension(binaryPlatformName, fmt.Sprintf(EngineURL, EngineVersion, binaryPlatformRemoteName, engineName)) - - logger.Debug.Printf("download url %s", url) if _, err := os.Stat(to); !os.IsNotExist(err) { - logger.Debug.Printf("%s is cached", to) + logger.Debug.Printf("%s is cached at %s", engineName, to) return nil } + url := platform.CheckForExtension(binaryPlatformName, fmt.Sprintf(EngineURL, EngineVersion, binaryPlatformRemoteName, engineName)) + logger.Debug.Printf("%s is missing, downloading...", engineName) + logger.Debug.Printf("downloading %s from %s to %s", engineName, url, to) + if err := download(url, to); err != nil { return fmt.Errorf("could not download %s to %s: %w", url, to, err) } From 01a60e6911fa083d352013556f9ecc75869297ce Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 17:27:37 +0100 Subject: [PATCH 32/44] use static --- generator/run.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/run.go b/generator/run.go index 7fe8a185..ba4d99ec 100644 --- a/generator/run.go +++ b/generator/run.go @@ -177,6 +177,7 @@ func generateBinaries(input *Root) error { for _, name := range targets { if name == "native" { name = platform.BinaryPlatformNameStatic() + logger.Debug.Printf("swapping 'native' binary target with '%s'", name) } // first, ensure they are actually downloaded @@ -200,7 +201,7 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err } if name == "native" { - name = platform.BinaryPlatformNameDynamic() + name = platform.BinaryPlatformNameStatic() } enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name) From b5c4be8a31d8a5a1b3f16f7a0346f70a98793c83 Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 18:41:00 +0100 Subject: [PATCH 33/44] WIP no idea what i am doing at this point --- binaries/binaries.go | 45 +++++++------------------------------------- cli/cli.go | 2 +- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 1f67ce4e..99228a3b 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -8,7 +8,6 @@ import ( "os" "path" "path/filepath" - "time" "github.com/steebchen/prisma-client-go/binaries/platform" "github.com/steebchen/prisma-client-go/logger" @@ -86,12 +85,12 @@ func GlobalCacheDir() string { return path.Join(cache, baseDirName, "cli", PrismaVersion) } -func FetchEngine(toDir string, engineName string, binaryPlatformName string) error { +func FetchEngine(dir string, engineName string, binaryName string) error { logger.Debug.Printf("checking %s...", engineName) - to := platform.CheckForExtension(binaryPlatformName, path.Join(toDir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engineName, binaryPlatformName))) + to := GlobalCacheDir() - binaryPlatformRemoteName := binaryPlatformName + binaryPlatformRemoteName := binaryName if binaryPlatformRemoteName == "linux" { binaryPlatformRemoteName = "linux-static-x64" } @@ -101,7 +100,7 @@ func FetchEngine(toDir string, engineName string, binaryPlatformName string) err return nil } - url := platform.CheckForExtension(binaryPlatformName, fmt.Sprintf(EngineURL, EngineVersion, binaryPlatformRemoteName, engineName)) + url := platform.CheckForExtension(binaryName, fmt.Sprintf(EngineURL, EngineVersion, binaryPlatformRemoteName, engineName)) logger.Debug.Printf("%s is missing, downloading...", engineName) @@ -131,7 +130,7 @@ func FetchNative(toDir string) error { } for _, e := range Engines { - if _, err := DownloadEngine(e.Name, toDir); err != nil { + if err := FetchEngine(toDir, e.Name, platform.BinaryPlatformNameStatic()); err != nil { return fmt.Errorf("could not download engines: %w", err) } } @@ -161,38 +160,8 @@ func DownloadCLI(toDir string) error { return nil } -func GetEnginePath(dir, engine, binaryName string) string { - return platform.CheckForExtension(binaryName, path.Join(dir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engine, binaryName))) -} - -func DownloadEngine(name string, toDir string) (file string, err error) { - binaryName := platform.BinaryPlatformNameDynamic() - - logger.Debug.Printf("checking %s...", name) - - to := platform.CheckForExtension(binaryName, path.Join(toDir, EngineVersion, fmt.Sprintf("prisma-%s-%s", name, binaryName))) - - url := platform.CheckForExtension(binaryName, fmt.Sprintf(EngineURL, EngineVersion, binaryName, name)) - - logger.Debug.Printf("download url %s", url) - - if _, err := os.Stat(to); !os.IsNotExist(err) { - logger.Debug.Printf("%s is cached", to) - return to, nil - } - - logger.Debug.Printf("%s is missing, downloading...", name) - - startDownload := time.Now() - if err := download(url, to); err != nil { - return "", fmt.Errorf("could not download %s to %s: %w", url, to, err) - } - - logger.Debug.Printf("%s engine download took %s", name, time.Since(startDownload)) - - logger.Debug.Printf("%s done", name) - - return to, nil +func GetEnginePath(dir, engineName, binaryName string) string { + return platform.CheckForExtension(binaryName, path.Join(dir, EngineVersion, fmt.Sprintf("prisma-%s-%s", engineName, binaryName))) } func download(url string, to string) error { diff --git a/cli/cli.go b/cli/cli.go index a156faf8..e40d82e5 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -28,7 +28,7 @@ func Run(arguments []string, output bool) error { logger.Debug.Printf("running %s %+v", path.Join(dir, prisma), arguments) cmd := exec.Command(path.Join(dir, prisma), arguments...) //nolint:gosec - binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameDynamic()) + binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameStatic()) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "PRISMA_HIDE_UPDATE_MESSAGE=true") From eb82aeb82b1f8b54a8b494d02e4fb324a3beda7f Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 18:56:46 +0100 Subject: [PATCH 34/44] fix engine dir --- binaries/binaries.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 99228a3b..6008791c 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -88,7 +88,7 @@ func GlobalCacheDir() string { func FetchEngine(dir string, engineName string, binaryName string) error { logger.Debug.Printf("checking %s...", engineName) - to := GlobalCacheDir() + to := GetEnginePath(dir, engineName, binaryName) binaryPlatformRemoteName := binaryName if binaryPlatformRemoteName == "linux" { From 3e4c4cfacc74f1a86ddd0be873b279a1b3689951 Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 18 Jun 2023 20:02:04 +0100 Subject: [PATCH 35/44] consider cache path in path detection --- engine/lifecycle.go | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/engine/lifecycle.go b/engine/lifecycle.go index f2131786..aa8db05b 100644 --- a/engine/lifecycle.go +++ b/engine/lifecycle.go @@ -70,7 +70,9 @@ func (e *QueryEngine) Disconnect() error { func (e *QueryEngine) ensure() (string, error) { ensureEngine := time.Now() - binariesPath := binaries.GlobalUnpackDir(binaries.EngineVersion) + unpackPath := binaries.GlobalUnpackDir(binaries.EngineVersion) + cachePath := binaries.GlobalCacheDir() + // check for darwin/windows/linux first binaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameStatic()) exactBinaryName := platform.CheckForExtension(platform.Name(), platform.BinaryPlatformNameDynamic()) @@ -81,13 +83,16 @@ func (e *QueryEngine) ensure() (string, error) { forceVersion := true name := "prisma-query-engine-" - localPath := path.Join("./", name+binaryName) - localExactPath := path.Join("./", name+exactBinaryName) - globalPath := path.Join(binariesPath, name+binaryName) - globalExactPath := path.Join(binariesPath, name+exactBinaryName) + localStatic := path.Join("./", name+binaryName) + localExact := path.Join("./", name+exactBinaryName) + globalUnpackStatic := path.Join(unpackPath, name+binaryName) + globalUnpackExact := path.Join(unpackPath, name+exactBinaryName) + cacheStatic := path.Join(cachePath, binaries.EngineVersion, name+binaryName) + cacheExact := path.Join(cachePath, binaries.EngineVersion, name+exactBinaryName) - logger.Debug.Printf("expecting local query engine `%s` or `%s`", localPath, localExactPath) - logger.Debug.Printf("expecting global query engine `%s` or `%s`", globalPath, globalExactPath) + logger.Debug.Printf("expecting local query engine `%s` or `%s`", localStatic, localExact) + logger.Debug.Printf("expecting global query engine `%s` or `%s`", globalUnpackStatic, globalUnpackExact) + logger.Debug.Printf("expecting cached query engine `%s` or `%s`", cacheStatic, cacheExact) // TODO write tests for all cases @@ -106,19 +111,27 @@ func (e *QueryEngine) ensure() (string, error) { logger.Debug.Printf("using unpacked file env %s %s", unpack.FileEnv, qe) file = qe } else { - if info, err := os.Stat(localExactPath); err == nil { - file = localExactPath + if info, err := os.Stat(localExact); err == nil { + file = localExact logger.Debug.Printf("exact query engine found in working directory: %s %+v", file, info) - } else if info, err = os.Stat(localPath); err == nil { - file = localPath + } else if info, err = os.Stat(localStatic); err == nil { + file = localStatic logger.Debug.Printf("query engine found in working directory: %s %+v", file, info) } - if info, err := os.Stat(globalExactPath); err == nil { - file = globalExactPath + if info, err := os.Stat(cacheExact); err == nil { + file = cacheExact + logger.Debug.Printf("query engine found in cache path: %s %+v", file, info) + } else if info, err = os.Stat(cacheStatic); err == nil { + file = cacheStatic + logger.Debug.Printf("exact query engine found in cache path: %s %+v", file, info) + } + + if info, err := os.Stat(globalUnpackExact); err == nil { + file = globalUnpackExact logger.Debug.Printf("query engine found in global path: %s %+v", file, info) - } else if info, err = os.Stat(globalPath); err == nil { - file = globalPath + } else if info, err = os.Stat(globalUnpackStatic); err == nil { + file = globalUnpackStatic logger.Debug.Printf("exact query engine found in global path: %s %+v", file, info) } } From 841c143bcc5cbb510d9f1a44b2381d64c64bda8b Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Wed, 21 Jun 2023 22:19:19 +0100 Subject: [PATCH 36/44] Update test.yml --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 20cacf9c..0dcc487d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,5 +42,3 @@ jobs: - name: test if: steps.changes.outputs.go == 'true' run: go test ./... -v -failfast - env: - PRISMA_CLIENT_GO_LOG: debug From adec5d7a26a02d91df4961c1f46fcbef97c5489b Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 22:53:41 +0100 Subject: [PATCH 37/44] minor fixes --- .dockerignore | 3 +++ binaries/unpack/unpack.go | 2 +- engine/lifecycle.go | 28 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9c385f9e..a9d8d646 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,3 +15,6 @@ schema.graphql **/*_gen.go **/prisma-* **/query-engine-* + +Dockerfile +*.dockerfile diff --git a/binaries/unpack/unpack.go b/binaries/unpack/unpack.go index a3397f82..9b7e512a 100644 --- a/binaries/unpack/unpack.go +++ b/binaries/unpack/unpack.go @@ -14,7 +14,7 @@ import ( // TODO check checksum after expanding file -const FileEnv = "PRISMA_INTERNAL_QUERY_ENGINE_DIR" +const FileEnv = "PRISMA_INTERNAL_QUERY_ENGINE_PATH" // noinspection GoUnusedExportedFunction func Unpack(data []byte, name string, version string) { diff --git a/engine/lifecycle.go b/engine/lifecycle.go index aa8db05b..d9191463 100644 --- a/engine/lifecycle.go +++ b/engine/lifecycle.go @@ -90,9 +90,9 @@ func (e *QueryEngine) ensure() (string, error) { cacheStatic := path.Join(cachePath, binaries.EngineVersion, name+binaryName) cacheExact := path.Join(cachePath, binaries.EngineVersion, name+exactBinaryName) - logger.Debug.Printf("expecting local query engine `%s` or `%s`", localStatic, localExact) - logger.Debug.Printf("expecting global query engine `%s` or `%s`", globalUnpackStatic, globalUnpackExact) - logger.Debug.Printf("expecting cached query engine `%s` or `%s`", cacheStatic, cacheExact) + logger.Debug.Printf("checking for local query engine `%s` or `%s`", localStatic, localExact) + logger.Debug.Printf("checking for global query engine `%s` or `%s`", globalUnpackStatic, globalUnpackExact) + logger.Debug.Printf("checking for cached query engine `%s` or `%s`", cacheStatic, cacheExact) // TODO write tests for all cases @@ -107,27 +107,31 @@ func (e *QueryEngine) ensure() (string, error) { file = prismaQueryEngineBinary forceVersion = false - } else if qe := os.Getenv(unpack.FileEnv); qe != "" { - logger.Debug.Printf("using unpacked file env %s %s", unpack.FileEnv, qe) - file = qe } else { + if qe := os.Getenv(unpack.FileEnv); qe != "" { + logger.Debug.Printf("using unpacked file env %s %s", unpack.FileEnv, qe) + + if info, err := os.Stat(qe); err == nil { + file = qe + logger.Debug.Printf("exact query engine found in working directory: %s %+v", file, info) + } else { + return "", fmt.Errorf("prisma query engine was expected at %s via FileEnv but was not found", qe) + } + } + if info, err := os.Stat(localExact); err == nil { file = localExact logger.Debug.Printf("exact query engine found in working directory: %s %+v", file, info) } else if info, err = os.Stat(localStatic); err == nil { file = localStatic logger.Debug.Printf("query engine found in working directory: %s %+v", file, info) - } - - if info, err := os.Stat(cacheExact); err == nil { + } else if info, err = os.Stat(cacheExact); err == nil { file = cacheExact logger.Debug.Printf("query engine found in cache path: %s %+v", file, info) } else if info, err = os.Stat(cacheStatic); err == nil { file = cacheStatic logger.Debug.Printf("exact query engine found in cache path: %s %+v", file, info) - } - - if info, err := os.Stat(globalUnpackExact); err == nil { + } else if info, err = os.Stat(globalUnpackExact); err == nil { file = globalUnpackExact logger.Debug.Printf("query engine found in global path: %s %+v", file, info) } else if info, err = os.Stat(globalUnpackStatic); err == nil { From a68a9ce1d28cd2916c3036ba1ebad92509d1538d Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 22:53:53 +0100 Subject: [PATCH 38/44] fix alpine --- binaries/platform/platform.go | 4 ---- generator/run.go | 13 +++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/binaries/platform/platform.go b/binaries/platform/platform.go index 3046c5d2..4249d32e 100644 --- a/binaries/platform/platform.go +++ b/binaries/platform/platform.go @@ -34,10 +34,6 @@ func BinaryPlatformNameDynamic() string { distro := getLinuxDistro() - if distro == "alpine" { - return fmt.Sprintf("linux-static-%s", arch) - } - ssl := getOpenSSL() name := fmt.Sprintf("%s-openssl-%s", distro, ssl) diff --git a/generator/run.go b/generator/run.go index ba4d99ec..1b90d081 100644 --- a/generator/run.go +++ b/generator/run.go @@ -180,6 +180,8 @@ func generateBinaries(input *Root) error { logger.Debug.Printf("swapping 'native' binary target with '%s'", name) } + name = TransformBinaryTarget(name) + // first, ensure they are actually downloaded if err := binaries.FetchEngine(binaries.GlobalCacheDir(), "query-engine", name); err != nil { return fmt.Errorf("failed fetching binaries: %w", err) @@ -204,6 +206,8 @@ func generateQueryEngineFiles(binaryTargets []string, pkg, outputDir string) err name = platform.BinaryPlatformNameStatic() } + name = TransformBinaryTarget(name) + enginePath := binaries.GetEnginePath(binaries.GlobalCacheDir(), "query-engine", name) filename := fmt.Sprintf("query-engine-%s_gen.go", name) @@ -228,3 +232,12 @@ func add(list []string, item string) []string { } return list } + +func TransformBinaryTarget(name string) string { + // TODO this is a temp fix as the exact alpine libraries are not working + if name == "linux" || strings.Contains(name, "musl") { + name = "linux-static-x64" + logger.Debug.Printf("overriding binary name with '%s' due to linux or musl", name) + } + return name +} From 9004991eba4984dd51ede71e71ac0a4e10f06444 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 22:54:18 +0100 Subject: [PATCH 39/44] add integration tests for alpine --- .github/workflows/integration-test-alpine.yml | 43 +++++++++++++++++++ ...on-test.yml => integration-test-cross.yml} | 6 +-- test/integration/README.md | 2 +- test/integration/integration.dockerfile | 12 ++++-- 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/integration-test-alpine.yml rename .github/workflows/{integration-test.yml => integration-test-cross.yml} (87%) diff --git a/.github/workflows/integration-test-alpine.yml b/.github/workflows/integration-test-alpine.yml new file mode 100644 index 00000000..52b85a6c --- /dev/null +++ b/.github/workflows/integration-test-alpine.yml @@ -0,0 +1,43 @@ +name: integration test all +on: pull_request +jobs: + integration: + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + go: + - '.github/workflows/**/*.yml' + - '**/*.go' + - '**/*.gotpl' + - '**/*.mod' + - '**/*.sum' + - '**/*.work' + + # fix for GitHub actions MacOS + - name: Setup docker + if: runner.os == 'macos' && steps.changes.outputs.go == 'true' + run: | + brew install docker + colima start + + # For testcontainers to find the Colima socket + # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running + sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock + + - uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache + restore-keys: ${{ runner.os }}-go- + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: test on alpine + if: steps.changes.outputs.go == 'true' + run: docker build . --build-arg IMAGE="golang:1-alpine" -f test/integration/integration.dockerfile -t integration && docker run integration diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test-cross.yml similarity index 87% rename from .github/workflows/integration-test.yml rename to .github/workflows/integration-test-cross.yml index 4372f1d0..1de86c4f 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test-cross.yml @@ -1,7 +1,7 @@ name: integration test all on: pull_request jobs: - integration: + integration-alpine: strategy: fail-fast: false matrix: @@ -43,6 +43,6 @@ jobs: restore-keys: ${{ runner.os }}-go- key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - - name: integration + - name: test if: steps.changes.outputs.go == 'true' - run: docker build . -f test/integration/integration.dockerfile -t integration && docker run integration + run: docker build . --build-arg IMAGE="golang:1-alpine" -f test/integration/integration.dockerfile -t integration && docker run integration diff --git a/test/integration/README.md b/test/integration/README.md index 03343ed5..4750df94 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -2,4 +2,4 @@ This folder acts as a small Prisma Client Go example and a full integration test of the runtime binary fetching. -This integration test folder needs to be run with docker (see [`.github/workflows/integration-test.yml`](/.github/workflows/integration-test.yml)). +This integration test folder needs to be run with docker (see [`.github/workflows/integration-test-cross.yml`](/.github/workflows/integration-test-cross.yml)). diff --git a/test/integration/integration.dockerfile b/test/integration/integration.dockerfile index d73a7bbf..299e3d38 100644 --- a/test/integration/integration.dockerfile +++ b/test/integration/integration.dockerfile @@ -1,23 +1,27 @@ -FROM golang:1.20.5 as build +ARG IMAGE +FROM $IMAGE as build WORKDIR /app +RUN go version + ENV PRISMA_CLIENT_GO_LOG=info ENV DEBUG=* +COPY go.mod go.sum ./ +RUN go mod download -x + COPY . ./ WORKDIR /app/test/integration -RUN go mod download -x - RUN go run github.com/steebchen/prisma-client-go db push --schema schemax.prisma # build the integration binary with all dependencies RUN go build -o /app/main . # start a new stage to test if the runtime fetching works -FROM golang:1.20.5 +FROM $IMAGE WORKDIR /app From fd4d5ba93c2c48aab8f9e0b80f8ed03aa4426ee3 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 23:23:39 +0100 Subject: [PATCH 40/44] fix alpine checks --- binaries/binaries.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index 6008791c..a85a39e1 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -86,21 +86,16 @@ func GlobalCacheDir() string { } func FetchEngine(dir string, engineName string, binaryName string) error { - logger.Debug.Printf("checking %s...", engineName) + logger.Debug.Printf("checking %s %s...", engineName, binaryName) to := GetEnginePath(dir, engineName, binaryName) - binaryPlatformRemoteName := binaryName - if binaryPlatformRemoteName == "linux" { - binaryPlatformRemoteName = "linux-static-x64" - } - if _, err := os.Stat(to); !os.IsNotExist(err) { logger.Debug.Printf("%s is cached at %s", engineName, to) return nil } - url := platform.CheckForExtension(binaryName, fmt.Sprintf(EngineURL, EngineVersion, binaryPlatformRemoteName, engineName)) + url := platform.CheckForExtension(binaryName, fmt.Sprintf(EngineURL, EngineVersion, binaryName, engineName)) logger.Debug.Printf("%s is missing, downloading...", engineName) From 21f661cbbf79ef2ddbf8f85f7b13aa94789adca6 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 23:24:59 +0100 Subject: [PATCH 41/44] fix integration tests --- .github/workflows/integration-test-alpine.yml | 2 +- .github/workflows/integration-test-cross.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration-test-alpine.yml b/.github/workflows/integration-test-alpine.yml index 52b85a6c..3deb9d5d 100644 --- a/.github/workflows/integration-test-alpine.yml +++ b/.github/workflows/integration-test-alpine.yml @@ -2,7 +2,7 @@ name: integration test all on: pull_request jobs: integration: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/integration-test-cross.yml b/.github/workflows/integration-test-cross.yml index 1de86c4f..63a1497c 100644 --- a/.github/workflows/integration-test-cross.yml +++ b/.github/workflows/integration-test-cross.yml @@ -45,4 +45,4 @@ jobs: - name: test if: steps.changes.outputs.go == 'true' - run: docker build . --build-arg IMAGE="golang:1-alpine" -f test/integration/integration.dockerfile -t integration && docker run integration + run: docker build . --build-arg IMAGE="golang:1" -f test/integration/integration.dockerfile -t integration && docker run integration From 9cc3138da4b70a36d1ab5e37dbbc542a8fe34053 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 23:28:31 +0100 Subject: [PATCH 42/44] fix integration tests --- .github/workflows/integration-test-alpine.yml | 43 ------------------- ...on-test-cross.yml => integration-test.yml} | 43 ++++++++++++++++++- test/integration/README.md | 2 +- 3 files changed, 43 insertions(+), 45 deletions(-) delete mode 100644 .github/workflows/integration-test-alpine.yml rename .github/workflows/{integration-test-cross.yml => integration-test.yml} (52%) diff --git a/.github/workflows/integration-test-alpine.yml b/.github/workflows/integration-test-alpine.yml deleted file mode 100644 index 3deb9d5d..00000000 --- a/.github/workflows/integration-test-alpine.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: integration test all -on: pull_request -jobs: - integration: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - uses: dorny/paths-filter@v2 - id: changes - with: - filters: | - go: - - '.github/workflows/**/*.yml' - - '**/*.go' - - '**/*.gotpl' - - '**/*.mod' - - '**/*.sum' - - '**/*.work' - - # fix for GitHub actions MacOS - - name: Setup docker - if: runner.os == 'macos' && steps.changes.outputs.go == 'true' - run: | - brew install docker - colima start - - # For testcontainers to find the Colima socket - # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running - sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock - - - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache - restore-keys: ${{ runner.os }}-go- - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - - - name: test on alpine - if: steps.changes.outputs.go == 'true' - run: docker build . --build-arg IMAGE="golang:1-alpine" -f test/integration/integration.dockerfile -t integration && docker run integration diff --git a/.github/workflows/integration-test-cross.yml b/.github/workflows/integration-test.yml similarity index 52% rename from .github/workflows/integration-test-cross.yml rename to .github/workflows/integration-test.yml index 63a1497c..af6cf62a 100644 --- a/.github/workflows/integration-test-cross.yml +++ b/.github/workflows/integration-test.yml @@ -1,7 +1,7 @@ name: integration test all on: pull_request jobs: - integration-alpine: + integration: strategy: fail-fast: false matrix: @@ -46,3 +46,44 @@ jobs: - name: test if: steps.changes.outputs.go == 'true' run: docker build . --build-arg IMAGE="golang:1" -f test/integration/integration.dockerfile -t integration && docker run integration + + integration-alpine: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + go: + - '.github/workflows/**/*.yml' + - '**/*.go' + - '**/*.gotpl' + - '**/*.mod' + - '**/*.sum' + - '**/*.work' + + # fix for GitHub actions MacOS + - name: Setup docker + if: runner.os == 'macos' && steps.changes.outputs.go == 'true' + run: | + brew install docker + colima start + + # For testcontainers to find the Colima socket + # https://github.com/abiosoft/colima/blob/main/docs/FAQ.md#cannot-connect-to-the-docker-daemon-at-unixvarrundockersock-is-the-docker-daemon-running + sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock + + - uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache + restore-keys: ${{ runner.os }}-go- + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: test on alpine + if: steps.changes.outputs.go == 'true' + run: docker build . --build-arg IMAGE="golang:1-alpine" -f test/integration/integration.dockerfile -t integration && docker run integration diff --git a/test/integration/README.md b/test/integration/README.md index 4750df94..03343ed5 100644 --- a/test/integration/README.md +++ b/test/integration/README.md @@ -2,4 +2,4 @@ This folder acts as a small Prisma Client Go example and a full integration test of the runtime binary fetching. -This integration test folder needs to be run with docker (see [`.github/workflows/integration-test-cross.yml`](/.github/workflows/integration-test-cross.yml)). +This integration test folder needs to be run with docker (see [`.github/workflows/integration-test.yml`](/.github/workflows/integration-test.yml)). From f7b0b6a31a54a0a44db3bf0dee00a5818262ea58 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 23:30:14 +0100 Subject: [PATCH 43/44] bump prisma to v4.16.0 --- binaries/binaries.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binaries/binaries.go b/binaries/binaries.go index a85a39e1..b68584d8 100644 --- a/binaries/binaries.go +++ b/binaries/binaries.go @@ -14,11 +14,11 @@ import ( ) // PrismaVersion is a hardcoded version of the Prisma CLI. -const PrismaVersion = "4.15.0" +const PrismaVersion = "4.16.0" // EngineVersion is a hardcoded version of the Prisma Engine. // The versions can be found under https://github.com/prisma/prisma-engines/commits/main -const EngineVersion = "70a9adfd11f836696eca398396544fe07a8d8edb" +const EngineVersion = "b20ead4d3ab9e78ac112966e242ded703f4a052c" // PrismaURL points to an S3 bucket URL where the CLI binaries are stored. var PrismaURL = "https://packaged-cli.prisma.sh/%s-%s-%s-%s.gz" From b97d9e9e744627917c83d167e189bdef68c0124d Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 21 Jun 2023 23:34:53 +0100 Subject: [PATCH 44/44] set arch on linux --- generator/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/run.go b/generator/run.go index 1b90d081..19870e17 100644 --- a/generator/run.go +++ b/generator/run.go @@ -236,7 +236,7 @@ func add(list []string, item string) []string { func TransformBinaryTarget(name string) string { // TODO this is a temp fix as the exact alpine libraries are not working if name == "linux" || strings.Contains(name, "musl") { - name = "linux-static-x64" + name = "linux-static-" + platform.Arch() logger.Debug.Printf("overriding binary name with '%s' due to linux or musl", name) } return name