Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions cmd/sqlc-test-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,31 @@ func installPostgreSQL() error {
// runtime (e.g. libossp-uuid16 for uuid-ossp).
func installPgDeps() error {
log.Println("installing postgresql runtime dependencies")
if err := run("sudo", "apt-get", "install", "-y", "--no-install-recommends", "libossp-uuid16"); err != nil {
if err := aptGet("install", "-y", "--no-install-recommends", "libossp-uuid16"); err != nil {
return fmt.Errorf("apt-get install libossp-uuid16: %w", err)
}
return nil
}

// aptGet runs sudo apt-get with the given arguments. The runner's Ubuntu
// mirror occasionally fails to resolve or serve a package, so apt retries
// each download, and a failed run is tried once more after refreshing the
// package lists, which also picks up a package the stale lists point at a
// version the mirror no longer has.
func aptGet(args ...string) error {
cmd := append([]string{"env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "-o", "Acquire::Retries=5"}, args...)
err := run("sudo", cmd...)
if err == nil {
return nil
}
log.Printf("apt-get %s failed (%v), refreshing package lists and retrying", strings.Join(args, " "), err)
time.Sleep(10 * time.Second)
if uerr := run("sudo", "env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "-o", "Acquire::Retries=5", "update"); uerr != nil {
log.Printf("apt-get update failed: %v", uerr)
}
return run("sudo", cmd...)
}

// supportedPlatforms returns a comma-separated list of supported platforms.
func supportedPlatforms() string {
platforms := make([]string, 0, len(pgBinaries))
Expand Down Expand Up @@ -485,7 +504,7 @@ func installMySQL() error {
}

log.Println("fixing missing dependencies with apt-get install -f")
if err := run("sudo", "apt-get", "install", "-f", "-y"); err != nil {
if err := aptGet("install", "-f", "-y"); err != nil {
return fmt.Errorf("apt-get install -f: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/sqlc-test-setup/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ func installMSSQL() error {
return err
}

if err := run("sudo", "apt-get", "update"); err != nil {
if err := aptGet("update"); err != nil {
return fmt.Errorf("apt-get update: %w", err)
}
log.Println("installing mssql-server")
if err := run("sudo", "env", "DEBIAN_FRONTEND=noninteractive", "apt-get", "install", "-y", "mssql-server"); err != nil {
if err := aptGet("install", "-y", "mssql-server"); err != nil {
return fmt.Errorf("apt-get install mssql-server: %w", err)
}

Expand Down
Loading