-
Notifications
You must be signed in to change notification settings - Fork 8
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
chore: rename to serverservice and add migrate and version subcommands #32
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
FROM golang:1.17 as builder | ||
|
||
# Build the goose binary | ||
RUN CGO_ENABLED=0 GOOS=linux go install github.com/pressly/goose/cmd/goose@v2.7.0 | ||
|
||
# Use the official Alpine image for a lean production container. | ||
# https://hub.docker.com/_/alpine | ||
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | ||
FROM alpine:3 | ||
FROM alpine:3 as alpine | ||
RUN apk add --no-cache ca-certificates | ||
|
||
# Copy the binary to the production image from the builder stage. | ||
COPY hollow-dcim /hollow-dcim | ||
FROM scratch | ||
# Copy ca-certs from alpine | ||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
|
||
# Copy goose and database migration files | ||
COPY --from=builder /go/bin/goose /goose | ||
COPY db/migrations /db-migrations | ||
# Copy the binary that goreleaser built | ||
COPY serverservice /serverservice | ||
|
||
# Run the web service on container startup. | ||
ENTRYPOINT ["/hollow-dcim"] | ||
ENTRYPOINT ["/serverservice"] | ||
CMD ["serve"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// Package cmd provides our CLI interface for the hollow binary | ||
package cmd // import "go.hollow.sh/dcim/cmd" | ||
package cmd // import "go.hollow.sh/serverservice/cmd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cmd | ||
|
||
import ( | ||
|
||
// import the crdbpgx for automatic retries of errors for crdb that support retry | ||
_ "github.com/cockroachdb/cockroach-go/v2/crdb/crdbpgx" | ||
"github.com/pressly/goose/v3" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
dbm "go.hollow.sh/serverservice/db" | ||
) | ||
|
||
// migrateCmd represents the migrate command | ||
var migrateCmd = &cobra.Command{ | ||
Use: "migrate <command> [args]", | ||
Short: "A brief description of your command", | ||
Long: `Migrate provides a wrapper around the "goose" migration tool. | ||
|
||
Commands: | ||
up Migrate the DB to the most recent version available | ||
up-by-one Migrate the DB up by 1 | ||
up-to VERSION Migrate the DB to a specific VERSION | ||
down Roll back the version by 1 | ||
down-to VERSION Roll back to a specific VERSION | ||
redo Re-run the latest migration | ||
reset Roll back all migrations | ||
status Dump the migration status for the current DB | ||
version Print the current version of the database | ||
create NAME [sql|go] Creates new migration file with the current timestamp | ||
fix Apply sequential ordering to migrations | ||
`, | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
migrate(args[0], args[1:]) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(migrateCmd) | ||
} | ||
|
||
func migrate(command string, args []string) { | ||
db, err := goose.OpenDBWithDriver("postgres", viper.GetString("db.uri")) | ||
if err != nil { | ||
logger.Fatalw("failed to open DB", "error", err) | ||
} | ||
|
||
defer func() { | ||
if err := db.Close(); err != nil { | ||
logger.Fatalw("failed to close DB", "error", err) | ||
} | ||
}() | ||
|
||
goose.SetBaseFS(dbm.Migrations) | ||
|
||
if err := goose.Run(command, db, "migrations", args...); err != nil { | ||
logger.Fatalw("migrate command failed", "command", command, "error", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"go.hollow.sh/toolbox/version" | ||
) | ||
|
||
// versionCmd represents the version command | ||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version and exit", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(version.String()) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Package db provides an embedded filesystem containing all the database migrations | ||
package db | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
// Migrations contain an embedded filesystem with all the sql migration files | ||
//go:embed migrations/*.sql | ||
var Migrations embed.FS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update short description