Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(pg): embed alpine linux postgres which is used for our docker image based on alpine linux (#627)
Danny Xuec8c435e434e
diff --git a/resources/README.md b/resources/README.mdindex 6198263daa..f947eade12 100644--- a/resources/README.md+++ b/resources/README.md@@ -4,6 +4,8 @@We will embed Postgres binaries to serve and store backend data. We will extract the binary to a binary path and use embedded-postgres to a Postgres server.-linux/amd64 used for Docker image and Linux platform (MD5 3b5b460450f09543f1055e7ffd1cf773): https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-linux-amd64/14.2.0/embedded-postgres-binaries-linux-amd64-14.2.0.jar+linux/amd64 used for Linux (MD5 3b5b460450f09543f1055e7ffd1cf773): https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-linux-amd64/14.2.0/embedded-postgres-binaries-linux-amd64-14.2.0.jar++linux/amd64 used for Docker image (MD5 2f7e10b17683bcbcba264057d7c4215d): https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-linux-amd64-alpine/14.2.0/embedded-postgres-binaries-linux-amd64-alpine-14.2.0.jardarwin/amd64 used for MacOS development (MD5 d95d5c5fccc1e1ef45de6533fd8e6d0a): https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-darwin-amd64/14.2.0/embedded-postgres-binaries-darwin-amd64-14.2.0.jardiff --git a/resources/resources.go b/resources/resources.goindex 17ac23f14a..1bef460a6b 100644--- a/resources/resources.go+++ b/resources/resources.go@@ -3,6 +3,7 @@ package resourcesimport ("archive/tar""bytes"+ "embed""fmt""io""log"@@ -11,6 +12,7 @@ import ("path""path/filepath""runtime"+ "strings"// Embeded postgres binaries._ "embed"@@ -18,25 +20,30 @@ import ("github.com/xi2/xz")-//go:embed postgres-darwin-x86_64.txz-var postgresDarwin []byte--//go:embed postgres-linux-x86_64.txz-var postgresLinux []byte+//go:embed postgres-darwin-x86_64.txz postgres-linux-x86_64-alpine_linux.txz postgres-linux-x86_64.txz+var postgresResources embed.FS// InstallPostgres returns the postgres binary depending on the OS.func InstallPostgres(resourceDir, pgDataDir, pgUser string) (string, error) {- var version string- var data []byte- log.Printf("Installing Postgres OS %q Arch %q\n", runtime.GOOS, runtime.GOARCH)+ var tarName stringswitch runtime.GOOS {case "darwin":- version, data = "postgres-darwin-amd64-14.2.0", postgresDarwin+ tarName = "postgres-darwin-x86_64.txz"case "linux":- version, data = "postgres-linux-amd64-14.2.0", postgresLinux+ if isAlpineLinux() {+ tarName = "postgres-linux-x86_64-alpine_linux.txz"+ } else {+ tarName = "postgres-linux-x86_64.txz"+ }default:return "", fmt.Errorf("OS %q is not supported", runtime.GOOS)}+ log.Printf("Installing Postgres OS %q Arch %q txz %q\n", runtime.GOOS, runtime.GOARCH, tarName)+ data, err := postgresResources.ReadFile(tarName)+ if err != nil {+ return "", err+ }+ version := strings.TrimRight(tarName, ".txz")pgBinDir := path.Join(resourceDir, version)if _, err := os.Stat(pgBinDir); err != nil {@@ -64,10 +71,15 @@ func InstallPostgres(resourceDir, pgDataDir, pgUser string) (string, error) {return pgBinDir, nil}+func isAlpineLinux() bool {+ _, err := os.Stat("/etc/alpine-release")+ return err == nil+}+func extractTXZ(directory string, data []byte) error {xzReader, err := xz.NewReader(bytes.NewReader(data), 0)if err != nil {- return nil+ return err}tarReader := tar.NewReader(xzReader)reader := func() io.Reader {