Skip to content

Commit

Permalink
Merge pull request #17 from danvergara/docker-readme
Browse files Browse the repository at this point in the history
Docker readme
  • Loading branch information
danvergara authored Jul 27, 2021
2 parents 6718e43 + ce9ac12 commit 0a5961b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
18 changes: 14 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@ 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
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" \
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ limitations under the License.
package cmd

import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
Expand All @@ -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
}

Expand Down

0 comments on commit 0a5961b

Please sign in to comment.