Skip to content

Commit

Permalink
Bundle migrations in binary
Browse files Browse the repository at this point in the history
Use the go-bindata tool to generate a golang migrations file to
compile the content of the db_migrations folder into the bundle. This
ensures that the compiled binaries are portable and do not require
around the migrations themselves along with the binary.

Also updated the makefile to pull the go-bindata file and generate the
`migration.go` file as part of `make build`
  • Loading branch information
kevinrizza committed Oct 15, 2019
1 parent c529d3d commit 4621b4f
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 11 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CMDS := $(addprefix bin/, $(shell go list $(MOD_FLAGS) ./cmd/... | xargs -I{} b

.PHONY: build test vendor clean

all: clean test build
all: clean install-go-bindata test build

$(CMDS):
go build $(MOD_FLAGS) $(extra_flags) -o $@ ./cmd/$(shell basename $@)
Expand All @@ -25,6 +25,12 @@ image-upstream:
vendor:
go mod vendor

install-go-bindata:
go get -u github.com/go-bindata/go-bindata/...

generate-migration-bundle:
go-bindata -pkg sqlite -o ./pkg/sqlite/migrations.go ./pkg/sqlite/db_migrations/

codegen:
protoc -I pkg/api/ --go_out=plugins=grpc:pkg/api pkg/api/*.proto
protoc -I pkg/api/grpc_health_v1 --go_out=plugins=grpc:pkg/api/grpc_health_v1 pkg/api/grpc_health_v1/*.proto
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/operator-framework/operator-registry
require (
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6
github.com/ghodss/yaml v1.0.0
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/golang-migrate/migrate/v4 v4.6.2
github.com/golang/mock v1.2.0
github.com/golang/protobuf v1.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb h1:D4uzjWwKYQ5XnAvU
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
Expand Down
7 changes: 6 additions & 1 deletion pkg/sqlite/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ func NewSQLLiteLoader(outFilename, migrationsPath string) (*SQLLoader, error) {
}

// Apply the current latest database version to keep net new databases in sync with upgradeable ones
migrator := NewSQLLiteMigrator(db, migrationsPath)
migrator, err := NewSQLLiteMigrator(db, migrationsPath)
if err != nil {
return nil, err
}
defer migrator.CleanUpMigrator()

err = migrator.InitMigrationVersion()
if err != nil {
return nil, err
Expand Down
264 changes: 264 additions & 0 deletions pkg/sqlite/migrations.go

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

Loading

0 comments on commit 4621b4f

Please sign in to comment.