Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: remove embed pg (#15887)

Danny Xuace589d37380
diff --git a/backend/bin/server/cmd/profile.go b/backend/bin/server/cmd/profile.go
index 930dfb7b0f..247188a58b 100644
--- a/backend/bin/server/cmd/profile.go
+++ b/backend/bin/server/cmd/profile.go
@@ -6,7 +6,6 @@ import (
"github.com/google/uuid"
- "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/component/config"
)
@@ -28,7 +27,6 @@ func getBaseProfile(dataDir string) *config.Profile {
Debug: flags.debug,
IsDocker: isDocker(),
DataDir: dataDir,
- ResourceDir: common.GetResourceDir(dataDir),
Demo: flags.demo,
Version: version,
GitCommit: gitcommit,
diff --git a/backend/common/util.go b/backend/common/util.go
index b44d970f55..bba13101f3 100644
--- a/backend/common/util.go
+++ b/backend/common/util.go
@@ -5,7 +5,6 @@ import (
"encoding/base64"
"fmt"
"math/big"
- "path"
"strconv"
"strings"
"unicode/utf8"
@@ -77,11 +76,6 @@ func GetPostgresSocketDir() string {
return "/tmp"
}
-// GetResourceDir returns the resource directory of Bytebase.
-func GetResourceDir(dataDir string) string {
- return path.Join(dataDir, "resources")
-}
-
// TruncateString truncates the string to have a maximum length of `limit` characters.
func TruncateString(str string, limit int) (string, bool) {
chars := 0
diff --git a/backend/component/config/profile.go b/backend/component/config/profile.go
index eac233f539..484b6e57d1 100644
--- a/backend/component/config/profile.go
+++ b/backend/component/config/profile.go
@@ -31,8 +31,6 @@ type Profile struct {
Debug bool
// DataDir is the directory stores the data including Bytebase's own database, backups, etc.
DataDir string
- // ResourceDir is the directory that stores resources, including embedded Postgres.
- ResourceDir string
// Demo mode.
Demo bool
// HA replica mode.
diff --git a/backend/resources/README.md b/backend/resources/README.md
deleted file mode 100644
index 4fc835c245..0000000000
--- a/backend/resources/README.md
+++ /dev/null
@@ -1,24 +0,0 @@
-# Resources
-
-## Postgresql
-
-We will embed Postgres binaries to serve and store backend data. We will extract the binary to a binary path and install Postgres. We will use Go file suffix build tags to include the embedded file only for the build platform. For example, resources_darwin_amd64.go will only be included for building Bytebase on darwin/amd64 platform.
-
-Compressing command: tar c . | xz > ../postgres-darwin-arm64.txz
-
-linux/amd64 used for Linux: 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/arm64 used for Linux arm64: https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-linux-arm64v8/14.2.0/embedded-postgres-binaries-linux-arm64v8-14.2.0.jar
-
-darwin/amd64 used for MacOS amd64: 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.jar
-
-darwin/arm64v8 used for MacOS arm64v8: https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-darwin-arm64v8/14.2.0/embedded-postgres-binaries-darwin-arm64v8-14.2.0.jar
-
-## Embeded Postgres binary
-
-https://github.com/zonkyio/embedded-postgres-binaries
-
-./gradlew clean install -Pversion=16.0.0 -PpgVersion=16.0 -ParchName=amd64
-./gradlew clean install -Pversion=16.0.0 -PpgVersion=16.0 -ParchName=arm64v8
-
-Darwin should bring in "lib/libpq*".
diff --git a/backend/resources/postgres/meta_instance.go b/backend/resources/postgres/meta_instance.go
index 0b6b298e6b..08254839d9 100644
--- a/backend/resources/postgres/meta_instance.go
+++ b/backend/resources/postgres/meta_instance.go
@@ -10,14 +10,14 @@ import (
)
// StartMetadataInstance starts the metadata instance.
-func StartMetadataInstance(ctx context.Context, pgBinDir, pgDataDir string, port int, mode common.ReleaseMode) (func(), error) {
+func StartMetadataInstance(ctx context.Context, pgDataDir string, port int, mode common.ReleaseMode) (func(), error) {
slog.Info("-----Embedded Postgres BEGIN-----")
slog.Info(fmt.Sprintf("Start embedded Postgres datastorePort=%d pgDataDir=%s", port, pgDataDir))
- if err := initDB(pgBinDir, pgDataDir, "bb"); err != nil {
+ if err := initDB(pgDataDir, "bb"); err != nil {
return nil, err
}
serverLog := mode == common.ReleaseModeDev
- if err := start(port, pgBinDir, pgDataDir, serverLog); err != nil {
+ if err := start(port, pgDataDir, serverLog); err != nil {
return nil, err
}
slog.Info("-----Embedded Postgres END-----")
@@ -38,7 +38,7 @@ func StartMetadataInstance(ctx context.Context, pgBinDir, pgDataDir string, port
}
return func() {
- if err := stop(pgBinDir, pgDataDir); err != nil {
+ if err := stop(pgDataDir); err != nil {
panic(err)
}
}, nil
diff --git a/backend/resources/postgres/postgres.go b/backend/resources/postgres/postgres.go
index 3b9a421983..88dccdd31c 100644
--- a/backend/resources/postgres/postgres.go
+++ b/backend/resources/postgres/postgres.go
@@ -7,76 +7,22 @@ import (
"os"
"os/exec"
"os/user"
- "path"
"path/filepath"
- "runtime"
"strconv"
"syscall"
"github.com/pkg/errors"
"github.com/bytebase/bytebase/backend/common"
- "github.com/bytebase/bytebase/backend/resources/utils"
)
-const (
- currentVersion = "16"
-)
-
-// Install will extract the postgres and utility tar in resourceDir.
-// Returns the bin directory on success.
-func Install(resourceDir string) (string, error) {
- pkgNamePrefix, err := getTarName()
- if err != nil {
- return "", err
- }
- tarName := pkgNamePrefix + ".txz"
-
- var pgBaseDir string
- if currentVersion == "14" {
- pgBaseDir = path.Join(resourceDir, pkgNamePrefix)
- } else {
- pgBaseDir = path.Join(resourceDir, fmt.Sprintf("%s-%s", pkgNamePrefix, currentVersion))
- }
-
- if _, err := os.Stat(pgBaseDir); err != nil {
- if !os.IsNotExist(err) {
- return "", errors.Wrapf(err, "failed to check postgres binary base directory path %q", pgBaseDir)
- }
-
- slog.Info("Installing PostgreSQL utilities...")
- version := fmt.Sprintf("%s%s", pkgNamePrefix, currentVersion)
- if err := utils.InstallImpl(resourceDir, pgBaseDir, tarName, version, resources); err != nil {
- return "", errors.Wrap(err, "cannot install postgres")
- }
- }
-
- pgBinDir := path.Join(pgBaseDir, "bin")
- return pgBinDir, nil
-}
-
-func getTarName() (string, error) {
- switch {
- case runtime.GOOS == "darwin" && runtime.GOARCH == "arm64":
- return "postgres-darwin-arm64", nil
- case runtime.GOOS == "linux" && runtime.GOARCH == "amd64":
- return "postgres-linux-amd64", nil
- case runtime.GOOS == "linux" && runtime.GOARCH == "arm64":
- return "postgres-linux-arm64", nil
- default:
- return "", errors.Errorf("unsupported combination of OS %q and ARCH %q", runtime.GOOS, runtime.GOARCH)
- }
-}
-
// start starts a postgres database instance.
// If port is 0, then it will choose a random unused port.
-func start(port int, binDir, dataDir string, serverLog bool) (err error) {
- pgbin := filepath.Join(binDir, "pg_ctl")
-
+func start(port int, dataDir string, serverLog bool) (err error) {
// See -p -k -h option definitions in the link below.
// https://www.postgresql.org/docs/current/app-postgres.html
// We also set max_connections to 500 for tests.
- p := exec.Command(pgbin, "start", "-w",
+ p := exec.Command("pg_ctl", "start", "-w",
"-D", dataDir,
"-o", fmt.Sprintf(`-p %d -k %s -N 500 -h ""`, port, common.GetPostgresSocketDir()))
@@ -104,9 +50,8 @@ func start(port int, binDir, dataDir string, serverLog bool) (err error) {
}
// stop stops a postgres instance, outputs to stdout and stderr.
-func stop(pgBinDir, pgDataDir string) error {
- pgbin := filepath.Join(pgBinDir, "pg_ctl")
- p := exec.Command(pgbin, "stop", "-w", "-D", pgDataDir)
+func stop(pgDataDir string) error {
+ p := exec.Command("pg_ctl", "stop", "-w", "-D", pgDataDir)
uid, _, sameUser, err := shouldSwitchUser()
if err != nil {
return err
@@ -125,7 +70,7 @@ func stop(pgBinDir, pgDataDir string) error {
}
// initDB inits a postgres database if not yet.
-func initDB(pgBinDir, pgDataDir, pgUser string) error {
+func initDB(pgDataDir, pgUser string) error {
versionPath := filepath.Join(pgDataDir, "PG_VERSION")
_, err := os.Stat(versionPath)
if err != nil && !os.IsNotExist(err) {
@@ -181,8 +126,7 @@ func initDB(pgBinDir, pgDataDir, pgUser string) error {
"-U", pgUser,
"-D", pgDataDir,
}
- initDBBinary := filepath.Join(pgBinDir, "initdb")
- p := exec.Command(initDBBinary, args...)
+ p := exec.Command("initdb", args...)
p.Env = append(os.Environ(),
"LC_ALL=en_US.UTF-8",
"LC_CTYPE=en_US.UTF-8",
diff --git a/backend/resources/postgres/resources_darwin_arm64.go b/backend/resources/postgres/resources_darwin_arm64.go
deleted file mode 100644
index 2b68a493b8..0000000000
--- a/backend/resources/postgres/resources_darwin_arm64.go
+++ /dev/null
@@ -1,6 +0,0 @@
-package postgres
-
-import "embed"
-
-//go:embed postgres-darwin-arm64.txz
-var resources embed.FS
diff --git a/backend/resources/postgres/resources_linux_amd64.go b/backend/resources/postgres/resources_linux_amd64.go
deleted file mode 100644
index 99d77aabbc..0000000000
--- a/backend/resources/postgres/resources_linux_amd64.go
+++ /dev/null
@@ -1,8 +0,0 @@
-//go:build !docker
-
-package postgres
-
-import "embed"
-
-//go:embed postgres-linux-amd64.txz
-var resources embed.FS
diff --git a/backend/resources/postgres/resources_linux_arm64.go b/backend/resources/postgres/resources_linux_arm64.go
deleted file mode 100644
index c1248ccfe8..0000000000
--- a/backend/resources/postgres/resources_linux_arm64.go
+++ /dev/null
@@ -1,8 +0,0 @@
-//go:build !docker
-
-package postgres
-
-import "embed"
-
-//go:embed postgres-linux-arm64.txz
-var resources embed.FS
diff --git a/backend/resources/postgres/resources_not_embeded_linux_amd64.go b/backend/resources/postgres/resources_not_embeded_linux_amd64.go
deleted file mode 100644
index df52ebbee4..0000000000
--- a/backend/resources/postgres/resources_not_embeded_linux_amd64.go
+++ /dev/null
@@ -1,7 +0,0 @@
-//go:build docker
-
-package postgres
-
-import "embed"
-
-var resources embed.FS
diff --git a/backend/resources/postgres/resources_not_embeded_linux_arm64.go b/backend/resources/postgres/resources_not_embeded_linux_arm64.go
deleted file mode 100644
index df52ebbee4..0000000000
--- a/backend/resources/postgres/resources_not_embeded_linux_arm64.go
+++ /dev/null
@@ -1,7 +0,0 @@
-//go:build docker
-
-package postgres
-
-import "embed"
-
-var resources embed.FS
diff --git a/backend/resources/postgres/sample_instance.go b/backend/resources/postgres/sample_instance.go
index ded1042da3..662b6c1cb7 100644
--- a/backend/resources/postgres/sample_instance.go
+++ b/backend/resources/postgres/sample_instance.go
@@ -35,7 +35,7 @@ var (
)
// StartAllSampleInstances starts all postgres sample instances.
-func StartAllSampleInstances(ctx context.Context, pgBinDir, dataDir string, basePort int) []func() {
+func StartAllSampleInstances(ctx context.Context, dataDir string, basePort int) []func() {
sampleData, err := loadSampleData()
if err != nil {
slog.Error("failed to load sample data", log.BBError(err))
@@ -48,18 +48,18 @@ func StartAllSampleInstances(ctx context.Context, pgBinDir, dataDir string, base
port := basePort + i
dataDir := path.Join(dataDir, "pgdata-sample", env)
- if err := initDB(pgBinDir, dataDir, SampleUser); err != nil {
+ if err := initDB(dataDir, SampleUser); err != nil {
slog.Error("failed to init sample instance", log.BBError(err))
continue
}
slog.Info(fmt.Sprintf("Start sample instance %v at port %d", env, port))
- if err := start(port, pgBinDir, dataDir, true /* serverLog */); err != nil {
+ if err := start(port, dataDir, true /* serverLog */); err != nil {
slog.Error("failed to start sample instance", log.BBError(err))
continue
}
stoppers = append(stoppers, func() {
- if err := stop(pgBinDir, dataDir); err != nil {
+ if err := stop(dataDir); err != nil {
panic(err)
}
})
diff --git a/backend/resources/utils/extract.go b/backend/resources/utils/extract.go
deleted file mode 100644
index f4ac42e419..0000000000
--- a/backend/resources/utils/extract.go
+++ /dev/null
@@ -1,97 +0,0 @@
-// Package utils provides the library for installing resources..
-package utils
-
-import (
- "archive/tar"
- "compress/gzip"
- "io"
- "os"
- "path"
- "path/filepath"
- "strings"
-
- "github.com/pkg/errors"
- "github.com/xi2/xz"
-)
-
-// ExtractTarGz extracts the given file as .tar.gz format to the given directory.
-func ExtractTarGz(tarGzF io.Reader, targetDir string) error {
- gzipR, err := gzip.NewReader(tarGzF)
- if err != nil {
- return err
- }
- defer gzipR.Close()
- return extractTar(gzipR, targetDir)
-}
-
-// ExtractTarXz extracts the given file as .tar.xz or .txz format to the given directory.
-func ExtractTarXz(tarXzF io.Reader, targetDir string) error {
- xzR, err := xz.NewReader(tarXzF, 0)
- if err != nil {
- return err
- }
- return extractTar(xzR, targetDir)
-}
-
-func extractTar(r io.Reader, targetDir string) error {
- tarReader := tar.NewReader(r)
- for {
- header, err := tarReader.Next()
- if err == io.EOF {
- break
- }
- if err != nil {
- return err
- }
-
- targetPath, err := filepath.Abs(filepath.Join(targetDir, header.Name))
- if err != nil {
- return errors.Wrapf(err, "failed to get absolute path for %q", header.Name)
- }
-
- // Ensure that output paths constructed from zip archive entries
- // are validated to prevent writing files to unexpected locations.
- if strings.Contains(targetPath, "..") {
- return errors.Errorf("invalid path %q", targetPath)
- }
-
- if err := os.MkdirAll(path.Dir(targetPath), os.ModePerm); err != nil {
- return errors.Wrapf(err, "failed to create directory %q", header.Name)
- }
-
- switch header.Typeflag {
- case tar.TypeReg:
- outFile, err := os.OpenFile(targetPath, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
- if err != nil {
- return err
- }
-
- var totalWritten int64
- for totalWritten < header.Size {
- written, err := io.CopyN(outFile, tarReader, 1024)
- if err != nil {
- if err == io.EOF {
- break
- }
- return err
- }
- totalWritten += written
- }
- if err := outFile.Close(); err != nil {
- return err
- }
- case tar.TypeDir:
- if err := os.MkdirAll(targetPath, os.FileMode(header.Mode)); err != nil {
- return err
- }
- case tar.TypeSymlink:
- if err := os.Symlink(header.Linkname, targetPath); err != nil {
- return err
- }
- default:
- return errors.Errorf("unsupported type flag %d", header.Typeflag)
- }
- }
-
- return nil
-}
diff --git a/backend/resources/utils/install_util_embeded.go b/backend/resources/utils/install_util_embeded.go
deleted file mode 100644
index 7f12fa84bd..0000000000
--- a/backend/resources/utils/install_util_embeded.go
+++ /dev/null
@@ -1,43 +0,0 @@
-//go:build !docker
-
-package utils
-
-import (
- "embed"
- "fmt"
- "os"
- "path"
- "strings"
-
- "github.com/pkg/errors"
-)
-
-// InstallImpl installs postgres in resourceDir.
-func InstallImpl(resourceDir, utilDir, tarName, version string, resources embed.FS) error {
- tmpDir := path.Join(resourceDir, fmt.Sprintf("tmp-%s", version))
- if err := os.RemoveAll(tmpDir); err != nil {
- return errors.Wrapf(err, "failed to remove util binaries temp directory %q", tmpDir)
- }
-
- f, err := resources.Open(tarName)
- if err != nil {
- return errors.Wrapf(err, "failed to find %q in embedded resources", tarName)
- }
- defer f.Close()
-
- if strings.Contains(tarName, ".txz") {
- if err := ExtractTarXz(f, tmpDir); err != nil {
- return errors.Wrap(err, "failed to extract .txz file")
- }
- } else if strings.Contains(tarName, ".tar.gz") {
- if err := ExtractTarGz(f, tmpDir); err != nil {
- return errors.Wrap(err, "failed to extract tar.gz file")
- }
- }
-
- if err := os.Rename(tmpDir, utilDir); err != nil {
- return errors.Wrapf(err, "failed to rename util binaries directory from %q to %q", tmpDir, utilDir)
- }
-
- return nil
-}
diff --git a/backend/resources/utils/install_util_not_embeded.go b/backend/resources/utils/install_util_not_embeded.go
deleted file mode 100644
index 955ede42bd..0000000000
--- a/backend/resources/utils/install_util_not_embeded.go
+++ /dev/null
@@ -1,47 +0,0 @@
-//go:build docker
-
-package utils
-
-import (
- "embed"
- "fmt"
- "os"
- "runtime"
- "strings"
-
- "github.com/pkg/errors"
-)
-
-// InstallImpl installs postgres in resourceDir.
-func InstallImpl(_, utilDir, tarName, version string, _ embed.FS) error {
- preloadingDir := getPreloadingUtilDir(utilDir)
- if _, err := os.Stat(preloadingDir); err != nil {
- if os.IsNotExist(err) {
- // source file doesn't exist.
- return errors.Errorf("preloadingDir %q does not exist", preloadingDir)
- }
- return errors.Wrapf(err, "preloadingDir %q error", preloadingDir)
- }
- if utilDir == preloadingDir {
- // utilDir and preloadingDir are same, nothing to do.
- return nil
- }
-
- // create a symbolic link if utilDir and preloadingDir are different.
- if err := os.Symlink(preloadingDir, utilDir); err != nil {
- // panic if failed to create symbolic link.
- return errors.Wrapf(err, "failed to create a symbolic link for utilDir %q", utilDir)
- }
-
- // create symbolic link success.
- return nil
-}
-
-// getPreloadingUtilDir returns the preloading directory which decided at the build time for the given util directory.
-func getPreloadingUtilDir(utilDir string) string {
- if strings.Contains(utilDir, "postgres") {
- // we only support linux/amd64 or linux/arm64 now.
- return fmt.Sprintf("/bytebase/resources/postgres-linux-%s-16", runtime.GOARCH)
- }
- return utilDir
-}
diff --git a/backend/server/server.go b/backend/server/server.go
index 542562dc2a..01fea3ad0a 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -7,7 +7,6 @@ import (
"log/slog"
"net"
"net/http"
- "os"
"path"
"sync"
"time"
@@ -106,7 +105,6 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
slog.Info("-----Config BEGIN-----")
slog.Info(fmt.Sprintf("mode=%s", profile.Mode))
slog.Info(fmt.Sprintf("dataDir=%s", profile.DataDir))
- slog.Info(fmt.Sprintf("resourceDir=%s", profile.ResourceDir))
slog.Info(fmt.Sprintf("demo=%v", profile.Demo))
slog.Info(fmt.Sprintf("instanceRunUUID=%s", profile.DeployID))
slog.Info("-----Config END-------")
@@ -118,18 +116,6 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
}
}()
- var err error
- if err = os.MkdirAll(profile.ResourceDir, os.ModePerm); err != nil {
- return nil, errors.Wrapf(err, "failed to create directory: %q", profile.ResourceDir)
- }
-
- // Installs the Postgres and utility binaries and creates the 'activeProfile.pgUser' user/database
- // to store Bytebase's own metadata.
- pgBinDir, err := postgres.Install(profile.ResourceDir)
- if err != nil {
- return nil, err
- }
-
var pgURL string
if profile.UseEmbedDB() {
pgDataDir := path.Join(profile.DataDir, "pgdata")
@@ -137,7 +123,7 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
pgDataDir = path.Join(profile.DataDir, "pgdata-demo")
}
- stopper, err := postgres.StartMetadataInstance(ctx, pgBinDir, pgDataDir, profile.DatastorePort, profile.Mode)
+ stopper, err := postgres.StartMetadataInstance(ctx, pgDataDir, profile.DatastorePort, profile.Mode)
if err != nil {
return nil, err
}
@@ -152,7 +138,7 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
if profile.SampleDatabasePort != 0 {
// Only create batch sample databases in demo mode. For normal mode, user starts from the free version
// and batch databases are useless because batch requires enterprise license.
- stopper := postgres.StartAllSampleInstances(ctx, pgBinDir, profile.DataDir, profile.SampleDatabasePort)
+ stopper := postgres.StartAllSampleInstances(ctx, profile.DataDir, profile.SampleDatabasePort)
s.stopper = append(s.stopper, stopper...)
}
diff --git a/backend/tests/main_test.go b/backend/tests/main_test.go
index fcd965aebc..61747e11fa 100644
--- a/backend/tests/main_test.go
+++ b/backend/tests/main_test.go
@@ -5,8 +5,6 @@ import (
"log"
"os"
"testing"
-
- "github.com/bytebase/bytebase/backend/resources/postgres"
)
func TestMain(m *testing.M) {
@@ -20,11 +18,6 @@ func TestMain(m *testing.M) {
}
func startMain(ctx context.Context, m *testing.M) (int, error) {
- resourceDir = os.TempDir()
- if _, err := postgres.Install(resourceDir); err != nil {
- return 0, err
- }
-
pgContainer, err := getPgContainer(ctx)
defer func() {
pgContainer.Close(ctx)
diff --git a/backend/tests/tests.go b/backend/tests/tests.go
index 6c12ddcdf5..7c85e65790 100644
--- a/backend/tests/tests.go
+++ b/backend/tests/tests.go
@@ -97,9 +97,6 @@ var (
externalPgPort string
nextDatabaseNumber = 20210113
-
- // resourceDir is the shared resource directory.
- resourceDir string
)
func getTestPort() int {
@@ -134,7 +131,7 @@ func (ctl *controller) StartServerWithExternalPg(ctx context.Context) (context.C
pgURL := fmt.Sprintf("postgresql://postgres:root-password@%s:%s/%s", externalPgHost, externalPgPort, databaseName)
serverPort := getTestPort()
- profile := getTestProfileWithExternalPg(resourceDir, serverPort, pgURL)
+ profile := getTestProfileWithExternalPg(serverPort, pgURL)
server, err := server.NewServer(ctx, profile)
if err != nil {
return nil, err
@@ -210,13 +207,12 @@ func (ctl *controller) initWorkspaceProfile(ctx context.Context) error {
// GetTestProfileWithExternalPg will return a profile for testing with external Postgres.
// We require port as an argument of GetTestProfile so that test can run in parallel in different ports,
// pgURL for connect to Postgres.
-func getTestProfileWithExternalPg(resourceDir string, port int, pgURL string) *component.Profile {
+func getTestProfileWithExternalPg(port int, pgURL string) *component.Profile {
return &component.Profile{
Mode: common.ReleaseModeDev,
ExternalURL: fmt.Sprintf("http://localhost:%d", port),
Port: port,
SampleDatabasePort: 0,
- ResourceDir: resourceDir,
PgURL: pgURL,
}
}
diff --git a/go.mod b/go.mod
index 9d9821a3c0..e80c5a66a5 100644
--- a/go.mod
+++ b/go.mod
@@ -91,7 +91,6 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75
github.com/trinodb/trino-go-client v0.323.0
github.com/vjeantet/ldapserver v1.0.1
- github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
github.com/xuri/excelize/v2 v2.9.0
github.com/yterajima/go-sitemap v0.4.0
github.com/zeebo/xxh3 v1.0.2
diff --git a/go.sum b/go.sum
index fb8bbaefdb..3d9ba1ee8f 100644
--- a/go.sum
+++ b/go.sum
@@ -2059,8 +2059,6 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
-github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
-github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
diff --git a/scripts/Dockerfile b/scripts/Dockerfile
index d2a555559f..c8275b31a3 100644
--- a/scripts/Dockerfile
+++ b/scripts/Dockerfile
@@ -37,18 +37,6 @@ RUN go build \
-ldflags="-w -s -X 'github.com/bytebase/bytebase/backend/bin/server/cmd.version=${VERSION}' -X 'github.com/bytebase/bytebase/backend/bin/server/cmd.gitcommit=${GIT_COMMIT}'" \
-o bytebase ./backend/bin/server/main.go
-FROM alpine:3.21 AS decompressor
-
-ARG TARGETARCH
-
-RUN apk add --no-cache xz
-COPY ./backend/resources /tmp/bytebase/resources/
-# These paths must match the paths in backened/resources/utils/utils_dir.go.
-# The real resource dir is decided by the backend at runtime. But we can only extract these at build time.
-# we extract resources to a specific dir here and the backend will create symlinks at runtime.
-RUN mkdir -p /var/opt/bytebase/resources/postgres-linux-${TARGETARCH}-16
-RUN tar -Jxf /tmp/bytebase/resources/postgres/postgres-linux-${TARGETARCH}.txz -C /var/opt/bytebase/resources/postgres-linux-${TARGETARCH}-16/
-
# Use debian because mysql requires glibc.
FROM debian:bookworm-slim AS monolithic
@@ -68,26 +56,26 @@ RUN mkdir -p /var/opt/bytebase
RUN mkdir -p /var/opt/bytebase/pgdata-demo
RUN apt-get update
RUN apt-get install -y gnupg locales curl psmisc procps libncurses5 krb5-user libkrb5-dev
+# Install postgresql.
+RUN apt-get install -y postgresql-common
+RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
+RUN apt-get -y install postgresql-16
+RUN rm -rf /var/lib/postgresql/
+ENV PATH="$PATH:/usr/lib/postgresql/16/bin/"
+# Generate en_US.UTF-8 locale which is needed to start postgres server.
+# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
+RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
+
# Install mongosh.
RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list
RUN apt-get update
-RUN apt-get install -y mongodb-mongosh
-
-# Generate en_US.UTF-8 locale which is needed to start postgres server.
-# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
-RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
-ENV PATH="${PATH}:/var/opt/bytebase/resources/postgres-linux-${TARGETARCH}-16/bin"
+RUN apt-get install -y mongodb-mongosh
-# Copy utility scripts, we have
-# - Demo script to launch Bytebase in readonly demo mode
-COPY ./scripts /usr/local/bin/
-COPY ./scripts/.psqlrc /root/.psqlrc
# The file indicates running in docker environment.
RUN touch /etc/bb.env
COPY --from=backend /backend-build/bytebase /usr/local/bin/
COPY --from=backend /etc/ssl/certs /etc/ssl/certs
-COPY --from=decompressor /var/opt/bytebase/resources /bytebase/resources
ENV OPENSSL_CONF=/etc/ssl/
diff --git a/scripts/Dockerfile.aws b/scripts/Dockerfile.aws
index 224a468b21..f7d4839c6b 100644
--- a/scripts/Dockerfile.aws
+++ b/scripts/Dockerfile.aws
@@ -37,18 +37,6 @@ RUN go build \
-ldflags="-w -s -X 'github.com/bytebase/bytebase/backend/bin/server/cmd.version=${VERSION}' -X 'github.com/bytebase/bytebase/backend/bin/server/cmd.gitcommit=${GIT_COMMIT}'" \
-o bytebase ./backend/bin/server/main.go
-FROM alpine:3.21 AS decompressor
-
-ARG TARGETARCH
-
-RUN apk add --no-cache xz
-COPY ./backend/resources /tmp/bytebase/resources/
-# These paths must match the paths in backened/resources/utils/utils_dir.go.
-# The real resource dir is decided by the backend at runtime. But we can only extract these at build time.
-# we extract resources to a specific dir here and the backend will create symlinks at runtime.
-RUN mkdir -p /var/opt/bytebase/resources/postgres-linux-${TARGETARCH}-16
-RUN tar -Jxf /tmp/bytebase/resources/postgres/postgres-linux-${TARGETARCH}.txz -C /var/opt/bytebase/resources/postgres-linux-${TARGETARCH}-16/
-
# Use debian because mysql requires glibc.
FROM debian:bookworm-slim AS monolithic
@@ -66,23 +54,28 @@ RUN addgroup --gid 113 --system bytebase && adduser --uid 113 --system bytebase
RUN mkdir -p /var/opt/bytebase
# Directory to store the demo data.
RUN mkdir -p /var/opt/bytebase/pgdata-demo
-# Our HEALTHCHECK instruction in dockerfile needs curl.
RUN apt-get update
-RUN DEBIAN_FRONTEND=noninteractive apt-get install -y locales curl psmisc procps libncurses5 krb5-user libkrb5-dev
+RUN apt-get install -y gnupg locales curl psmisc procps libncurses5 krb5-user libkrb5-dev
+# Install postgresql.
+RUN apt-get install -y postgresql-common
+RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
+RUN apt-get -y install postgresql-16
+RUN rm -rf /var/lib/postgresql/
+ENV PATH="$PATH:/usr/lib/postgresql/16/bin/"
# Generate en_US.UTF-8 locale which is needed to start postgres server.
# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
-ENV PATH="${PATH}:/var/opt/bytebase/resources/postgres-linux-${TARGETARCH}-16/bin"
-# Copy utility scripts, we have
-# - Demo script to launch Bytebase in readonly demo mode
-COPY ./scripts /usr/local/bin/
-COPY ./scripts/.psqlrc /root/.psqlrc
+# Install mongosh.
+RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
+RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | tee /etc/apt/sources.list.d/mongodb-org-8.0.list
+RUN apt-get update
+RUN apt-get install -y mongodb-mongosh
+
# The file indicates running in docker environment.
RUN touch /etc/bb.env
COPY --from=backend /backend-build/bytebase /usr/local/bin/
COPY --from=backend /etc/ssl/certs /etc/ssl/certs
-COPY --from=decompressor /var/opt/bytebase/resources /bytebase/resources
ENV OPENSSL_CONF=/etc/ssl/
ENV AWS_PRODUCT_ID="prod-n4dmmye4e6hjo"