Skip to content

fix: use gcr.io postgres image to remove ratelimit #8016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
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
3 changes: 1 addition & 2 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbauthz"
"github.com/coder/coder/coderd/database/dbmetrics"
"github.com/coder/coder/coderd/database/dbtype"
"github.com/coder/coder/coderd/gitauth"
"github.com/coder/coder/coderd/gitsshkey"
"github.com/coder/coder/coderd/healthcheck"
Expand Down Expand Up @@ -948,7 +947,7 @@ func (api *API) CreateInMemoryProvisionerDaemon(ctx context.Context, debounce ti
CreatedAt: database.Now(),
Name: name,
Provisioners: []database.ProvisionerType{database.ProvisionerTypeEcho, database.ProvisionerTypeTerraform},
Tags: dbtype.StringMap{
Tags: database.StringMap{
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization,
},
})
Expand Down
3 changes: 1 addition & 2 deletions coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbauthz"
"github.com/coder/coder/coderd/database/dbtype"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/cryptorand"
)
Expand Down Expand Up @@ -278,7 +277,7 @@ func ProvisionerJob(t testing.TB, db database.Store, orig database.ProvisionerJo
// Always set some tags to prevent Acquire from grabbing jobs it should not.
if !orig.StartedAt.Time.IsZero() {
if orig.Tags == nil {
orig.Tags = make(dbtype.StringMap)
orig.Tags = make(database.StringMap)
}
// Make sure when we acquire the job, we only get this one.
orig.Tags[id.String()] = "true"
Expand Down
29 changes: 0 additions & 29 deletions coderd/database/dbtype/dbtype.go
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
package dbtype

import (
"database/sql/driver"
"encoding/json"

"golang.org/x/xerrors"
)

type StringMap map[string]string

func (m *StringMap) Scan(src interface{}) error {
if src == nil {
return nil
}
switch src := src.(type) {
case []byte:
err := json.Unmarshal(src, m)
if err != nil {
return err
}
default:
return xerrors.Errorf("unsupported Scan, storing driver.Value type %T into type %T", src, m)
}
return nil
}

func (m StringMap) Value() (driver.Value, error) {
return json.Marshal(m)
}
5 changes: 2 additions & 3 deletions coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func OpenContainerized(port int) (string, func(), error) {
}

resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "postgres",
Repository: "gcr.io/coder-dev-1/postgres",
Tag: "13",
Env: []string{
"POSTGRES_PASSWORD=postgres",
Expand Down
5 changes: 2 additions & 3 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions coderd/database/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ overrides:
go:
overrides:
- column: "provisioner_daemons.tags"
go_type: "github.com/coder/coder/coderd/database/dbtype.StringMap"
go_type:
type: "StringMap"
- column: "provisioner_jobs.tags"
go_type: "github.com/coder/coder/coderd/database/dbtype.StringMap"
go_type:
type: "StringMap"
- column: "users.rbac_roles"
go_type: "github.com/lib/pq.StringArray"
- column: "templates.user_acl"
Expand Down
14 changes: 0 additions & 14 deletions coderd/database/time.go

This file was deleted.

34 changes: 34 additions & 0 deletions coderd/database/drivers.go → coderd/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"database/sql/driver"
"encoding/json"
"time"

"golang.org/x/xerrors"

Expand Down Expand Up @@ -43,3 +44,36 @@ func (t *TemplateACL) Scan(src interface{}) error {
func (t TemplateACL) Value() (driver.Value, error) {
return json.Marshal(t)
}

type StringMap map[string]string

func (m *StringMap) Scan(src interface{}) error {
if src == nil {
return nil
}
switch src := src.(type) {
case []byte:
err := json.Unmarshal(src, m)
if err != nil {
return err
}
default:
return xerrors.Errorf("unsupported Scan, storing driver.Value type %T into type %T", src, m)
}
return nil
}

func (m StringMap) Value() (driver.Value, error) {
return json.Marshal(m)
}

// Now returns a standardized timezone used for database resources.
func Now() time.Time {
return Time(time.Now().UTC())
}

// Time returns a time compatible with Postgres. Postgres only stores dates with
// microsecond precision.
func Time(t time.Time) time.Time {
return t.Round(time.Microsecond)
}
5 changes: 2 additions & 3 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/coder/coder/coderd/database/dbauthz"
"github.com/coder/coder/coderd/database/dbgen"
"github.com/coder/coder/coderd/database/dbtestutil"
"github.com/coder/coder/coderd/database/dbtype"
"github.com/coder/coder/coderd/parameter"
"github.com/coder/coder/coderd/rbac"
"github.com/coder/coder/coderd/schedule"
Expand Down Expand Up @@ -589,7 +588,7 @@ func TestWorkspaceFilterAllStatus(t *testing.T) {
InitiatorID: owner.UserID,
WorkerID: uuid.NullUUID{},
FileID: file.ID,
Tags: dbtype.StringMap{
Tags: database.StringMap{
"custom": "true",
},
})
Expand Down Expand Up @@ -617,7 +616,7 @@ func TestWorkspaceFilterAllStatus(t *testing.T) {
job.Type = database.ProvisionerJobTypeWorkspaceBuild
job.OrganizationID = owner.OrganizationID
// Need to prevent acquire from getting this job.
job.Tags = dbtype.StringMap{
job.Tags = database.StringMap{
jobID.String(): "true",
}
job = dbgen.ProvisionerJob(t, db, job)
Expand Down
5 changes: 2 additions & 3 deletions coderd/wsbuilder/wsbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbmock"
"github.com/coder/coder/coderd/database/dbtype"
"github.com/coder/coder/coderd/provisionerdserver"
"github.com/coder/coder/coderd/wsbuilder"
"github.com/coder/coder/codersdk"
Expand Down Expand Up @@ -614,7 +613,7 @@ func withActiveVersion(params []database.TemplateVersionParameter) func(mTx *dbm
StorageMethod: database.ProvisionerStorageMethodFile,
Type: database.ProvisionerJobTypeTemplateVersionImport,
Input: nil,
Tags: dbtype.StringMap{
Tags: database.StringMap{
"version": "active",
provisionerdserver.TagScope: provisionerdserver.ScopeUser,
},
Expand Down Expand Up @@ -654,7 +653,7 @@ func withInactiveVersion(params []database.TemplateVersionParameter) func(mTx *d
StorageMethod: database.ProvisionerStorageMethodFile,
Type: database.ProvisionerJobTypeTemplateVersionImport,
Input: nil,
Tags: dbtype.StringMap{
Tags: database.StringMap{
"version": "inactive",
provisionerdserver.TagScope: provisionerdserver.ScopeUser,
},
Expand Down