Skip to content
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

Replace packr to embed #110

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ dist

test/gethData
test/coverage.out

db/db-packr.go
packrd/
2 changes: 0 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ release:
before:
hooks:
- go mod download
- go install github.com/gobuffalo/packr/v2/[email protected]
- packr2

builds:
- main: ./cmd/
Expand Down
18 changes: 8 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# CONTAINER FOR BUILDING BINARY
FROM golang:1.21 AS build

WORKDIR $GOPATH/src/github.com/0xPolygon/cdk-data-availability

# INSTALL DEPENDENCIES
RUN go install github.com/gobuffalo/packr/v2/[email protected]
COPY go.mod go.sum /src/
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

# BUILD BINARY
COPY . /src

WORKDIR /src/db
RUN packr2

WORKDIR /src
COPY . .
RUN make build

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.16.0
COPY --from=build /src/dist/cdk-data-availability /app/cdk-data-availability

COPY --from=build /go/src/github.com/0xPolygon/cdk-data-availability/dist/cdk-data-availability /app/cdk-data-availability

EXPOSE 8444

CMD ["/bin/sh", "-c", "/app/cdk-data-availability run"]
15 changes: 12 additions & 3 deletions db/migrations.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package db

import (
"embed"

"github.com/0xPolygon/cdk-data-availability/log"
"github.com/gobuffalo/packr/v2"
"github.com/jmoiron/sqlx"
migrate "github.com/rubenv/sql-migrate"
)

var packrMigrations = packr.New("migrations", "./migrations")
var (
//go:embed migrations/*.sql
embedMigrations embed.FS
)

// RunMigrationsUp runs migrate-up for the given config.
func RunMigrationsUp(pg *sqlx.DB) error {
Expand All @@ -19,12 +23,17 @@ func RunMigrationsUp(pg *sqlx.DB) error {
// the database updated with the latest changes in either direction,
// up or down.
func runMigrations(db *sqlx.DB, direction migrate.MigrationDirection) error {
var migrations = &migrate.PackrMigrationSource{Box: packrMigrations}
migrations := &migrate.EmbedFileSystemMigrationSource{
FileSystem: embedMigrations,
Root: "migrations",
}

nMigrations, err := migrate.Exec(db.DB, "postgres", migrations, direction)
if err != nil {
return err
}

log.Info("successfully ran ", nMigrations, " migrations")

return nil
}
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/DATA-DOG/go-sqlmock v1.5.1
github.com/didip/tollbooth/v6 v6.1.2
github.com/ethereum/go-ethereum v1.13.14
github.com/gobuffalo/packr/v2 v2.8.3
github.com/gorilla/websocket v1.5.0
github.com/hermeznetwork/tracerr v0.3.2
github.com/invopop/jsonschema v0.7.0
Expand Down Expand Up @@ -53,9 +52,6 @@ require (
github.com/klauspost/compress v1.17.0 // indirect
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/markbates/errx v1.1.0 // indirect
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -68,7 +64,6 @@ require (
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand All @@ -91,7 +86,6 @@ require (
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.15.0 // indirect
Expand Down
Loading
Loading