Skip to content

Commit be18aa1

Browse files
authored
Merge pull request #1132 from tylerauerbeck/bindata-to-embed
backend: migrate go-bindata to embed
2 parents fa071a3 + e5dc59a commit be18aa1

8 files changed

Lines changed: 15 additions & 763 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818

1919
- Postgresql 17.x is now the tested and default version. For existing Kubernetes deployment, you might need to run a manual intervention (see: [charts/nebraska/README.md](https://github.com/flatcar/nebraska/blob/main/charts/nebraska/README.md#upgrade-postgresql))([nebraska#1088](https://github.com/flatcar/nebraska/pull/1088))
2020
- backend: updated kinvolk references to flatcar ([nebraska#1091](https://github.com/flatcar/nebraska/pull/1091/files))
21+
- backend: migrate from go-bindata to embed ([nebraska#1132](https://github.com/flatcar/nebraska/pull/1132))
2122

2223
### Bugfixes
2324

backend/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
bin
22
coverage.out
3-
tools/go-bindata
43
tools/golangci-lint
54
tools/swag
65
tools/oapi-codegen

backend/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ tools: bin/initdb
8383
bin/initdb:
8484
go build -o bin/initdb ./cmd/initdb
8585

86-
tools/go-bindata: go.mod go.sum
87-
env GOBIN=$(CURDIR)/tools/ go install github.com/kevinburke/go-bindata/go-bindata@v3.24.0
88-
8986
tools/golangci-lint: go.mod go.sum
9087
env GOBIN=$(CURDIR)/tools/ go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.2.1
9188

@@ -96,7 +93,7 @@ tools/swag:
9693
ci: build test-clean-work-tree-backend check-backend-with-container
9794

9895
.PHONY: run-generators
99-
run-generators: tools/go-bindata
96+
run-generators:
10097
PATH="$(abspath tools):$${PATH}" go generate ./...
10198

10299
bin/nebraska: run-generators

backend/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ require (
1414
github.com/jackc/pgx/v4 v4.18.3
1515
github.com/jinzhu/copier v0.4.0
1616
github.com/jmoiron/sqlx v1.4.0
17-
github.com/kevinburke/go-bindata v3.24.0+incompatible
1817
github.com/kinvolk/go-omaha v0.0.2-0.20221206142015-1518a03b832b
1918
github.com/knadh/koanf v1.5.0
2019
github.com/labstack/echo-contrib v0.17.4

backend/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,6 @@ github.com/julz/importas v0.2.0 h1:y+MJN/UdL63QbFJHws9BVC5RpA2iq0kpjrFajTGivjQ=
467467
github.com/julz/importas v0.2.0/go.mod h1:pThlt589EnCYtMnmhmRYY/qn9lCf/frPOK+WMx3xiJY=
468468
github.com/karamaru-alpha/copyloopvar v1.2.1 h1:wmZaZYIjnJ0b5UoKDjUHrikcV0zuPyyxI4SVplLd2CI=
469469
github.com/karamaru-alpha/copyloopvar v1.2.1/go.mod h1:nFmMlFNlClC2BPvNaHMdkirmTJxVCY0lhxBtlfOypMM=
470-
github.com/kevinburke/go-bindata v3.24.0+incompatible h1:qajFA3D0pH94OTLU4zcCCKCDgR+Zr2cZK/RPJHDdFoY=
471-
github.com/kevinburke/go-bindata v3.24.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
472470
github.com/kinvolk/go-omaha v0.0.2-0.20221206142015-1518a03b832b h1:+D/yo45hVrp5qdcifcHzQAcRWRXIOpxZpk0BW2Z4G1w=
473471
github.com/kinvolk/go-omaha v0.0.2-0.20221206142015-1518a03b832b/go.mod h1:SAEkKv9dpmCAVA3KxGdlHMoO4VaCAfIZuui57PqGQbg=
474472
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=

backend/pkg/api/api.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"database/sql"
5+
"embed"
56
"errors"
67
"fmt"
78
"os"
@@ -23,14 +24,12 @@ import (
2324
"time"
2425
)
2526

26-
// To re-generate the bindata.go file, use go-bindata from
27-
// github.com/kevinburke/go-bindata (a fork of the discontinued
28-
// go-bindata project). Run the following command from the root of the
29-
// repository:
30-
//
31-
// make bindata
32-
33-
//go:generate go-bindata -mode 0644 -ignore=\.swp -pkg=api -modtime=1 db db/migrations
27+
var (
28+
//go:embed db/*.sql
29+
sqlFolder embed.FS
30+
//go:embed db/migrations/*.sql
31+
migrationsFolder embed.FS
32+
)
3433

3534
const (
3635
defaultDbURL = "postgres://postgres:nebraska@127.0.0.1:5432/nebraska?sslmode=disable&connect_timeout=10"
@@ -193,19 +192,18 @@ func (api *API) MigrateDown(version string) (int, error) {
193192
return count, nil
194193
}
195194

196-
func migrationAssets() *migrate.AssetMigrationSource {
197-
return &migrate.AssetMigrationSource{
198-
Asset: Asset,
199-
AssetDir: AssetDir,
200-
Dir: "db/migrations",
195+
func migrationAssets() *migrate.EmbedFileSystemMigrationSource {
196+
return &migrate.EmbedFileSystemMigrationSource{
197+
FileSystem: migrationsFolder,
198+
Root: "db/migrations",
201199
}
202200
}
203201

204202
// OptionInitDB will initialize the database during the API instance creation,
205203
// dropping all existing tables, which will force all migration scripts to be
206204
// re-executed. Use with caution, this will DESTROY ALL YOUR DATA.
207205
func OptionInitDB(api *API) error {
208-
sqlFile, err := Asset("db/drop_all_tables.sql")
206+
sqlFile, err := sqlFolder.ReadFile("db/drop_all_tables.sql")
209207
if err != nil {
210208
return err
211209
}
@@ -239,7 +237,7 @@ func NewForTest(options ...func(*API) error) (*API, error) {
239237
return nil, err
240238
}
241239

242-
sqlFile, err := Asset("db/sample_data.sql")
240+
sqlFile, err := sqlFolder.ReadFile("db/sample_data.sql")
243241
if err != nil {
244242
return nil, err
245243
}

backend/pkg/api/bindata.go

Lines changed: 0 additions & 739 deletions
This file was deleted.

backend/tools/tools.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ package tools
44

55
import (
66
_ "github.com/golangci/golangci-lint/v2/cmd/golangci-lint"
7-
_ "github.com/kevinburke/go-bindata"
87
)

0 commit comments

Comments
 (0)