From ef2a21441b4d44f8039fba3b789cfa1d61a3c6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Omar=20Vergara=20P=C3=A9rez?= Date: Tue, 27 Jul 2021 00:13:19 -0500 Subject: [PATCH 1/3] fix(cmd): add a better error logs --- cli/cmd/root.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 7b51962..b18235e 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -18,8 +18,8 @@ limitations under the License. package cmd import ( - "bytes" "fmt" + "log" "os" "os/exec" "path/filepath" @@ -38,12 +38,13 @@ func NewRootCmd() *cobra.Command { Long: `Seeder is a ClI tool and Golang library that helps to seeds databases using golang code. ORM or SQL driver agnostic.`, RunE: func(cmd *cobra.Command, args []string) error { - var out bytes.Buffer - c := exec.Command("go", "run", fmt.Sprint(path, "/", "main.go")) - c.Stdout = &out + + c.Stdout = os.Stdout + c.Stderr = os.Stderr if err := c.Run(); err != nil { + log.Printf("error %s", err) return err } From 409f3d3a896631bc074361682d340d13233148e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Omar=20Vergara=20P=C3=A9rez?= Date: Tue, 27 Jul 2021 00:19:22 -0500 Subject: [PATCH 2/3] fix(dockerfile): fix docker image --- Dockerfile | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5879521..dd94484 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,12 @@ RUN apt-get update \ && apt-get -y install netcat curl \ && apt-get clean -COPY go.* ./ +COPY go.* Makefile ./ RUN go mod download + +COPY scripts ./scripts +RUN make install-migrate + COPY . . ARG TARGETOS @@ -16,11 +20,17 @@ ARG TARGETARCH RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -o seeder ./cli -RUN make install-migrate - FROM alpine:3.14 AS bin -RUN apk add --no-cache ca-certificates +RUN apk add --no-cache ca-certificates git make musl-dev go + +# Configure Go +ENV GOROOT /usr/lib/go +ENV GOPATH /go +ENV PATH /go/bin:$PATH + +RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin +WORKDIR /seeder LABEL org.opencontainers.image.documentation="https://github.com/danvergara/seeder" \ org.opencontainers.image.source="https://github.com/danvergara/seeder" \ From ce9ac12047bd28eb420dda75603e39c81d791ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Omar=20Vergara=20P=C3=A9rez?= Date: Tue, 27 Jul 2021 00:19:47 -0500 Subject: [PATCH 3/3] docs(readme): add instructions on how to used the docker image --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cec6004..a6a00c8 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,6 @@ $ go get github.com/danvergara/seeder ## Help - - ``` Seeder is a ClI tool and Golang library that helps to seeds databases using golang code. ORM or SQL driver agnostic. @@ -224,6 +222,18 @@ You can skip the --path flag is yout main is located at `db/main.go`. The recomm    └── users.go ``` +### Docker Usage + +```sh +$ docker run -v "$(pwd):/seeder" seeder --path path/to/main.go +``` + +If you neeed set to up environment variables to connect with the database: + +```sh +$ docker run -v "$(pwd):/seeder" --network host -e DB_HOST='localhost' -e DB_USER='postgres' -e DB_PASSWORD='password' -e DB_NAME='users' -e DB_PORT='5432' -e DB_DRIVER='postgres' seeder --path path/to/main.go +``` + ## Contribute - Fork this repository