Skip to content

Commit

Permalink
docker image (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzakhany authored Sep 15, 2023
1 parent 1c9c481 commit e19c314
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish_docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish Docker image
on:
push:
tags: ["v*"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
mirzakhani/dbctl
tags: |
type=semver,pattern={{major}}.{{minor}}.{{patch}}-{{sha}}
type=latest
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Start by building the application.
FROM golang:1.21 as build

WORKDIR /go/src/app
COPY . .

RUN make build

# Copy the binary into a distroless container.
FROM gcr.io/distroless/static-debian11
COPY --from=build /go/src/app/dbctl /
CMD ["/dbctl"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ vendor: ## Reset the main module's vendor directory to include all packages.
build: ## Build service binary.
$(GOCMD) build -mod vendor $(LDFLAGS) -o dbctl $(GO_MAIN_SRC)

.PHONY: build_docker
build_docker: ## Build docker image.
docker build -t dbctl:$(VERSION) -t dbctl:latest .

.PHONY: install
install: ## build and install the dbctl
$(GOCMD) install -mod vendor $(LDFLAGS) $(GO_MAIN_SRC)
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ go install github.com/mirzakhany/dbctl@latest

## How to use

## Using docker

```shell
docker run -lt --rm -v /var/run/docker.sock:/var/run/docker.sock dbctl:latest /dbctl ls
```

### Start a postgres instance
```shell
dbctl start pg
Expand All @@ -21,14 +27,19 @@ this command will start a postgis instance using docker engine on port `15432`,

Flags:
```shell
Flags:
-f, --fixtures string Path to fixture files, its can be a file or directory.files in directory will be sorted by name before applying.
-h, --help help for pg
-h, --help help for postgres
-m, --migrations string Path to migration files, will be applied if provided
-n, --name string Database name (default "postgres")
--pass string Database password (default "postgres")
-p, --port uint32 postgres default port (default 15432)
-u, --user string Database username (default "postgres")
-v, --version string Database version, default for native 14.3.0 and 14.3.2 for docker engine
-v, --version string Database version, default 14.3.2

Global Flags:
-d, --detach Detached mode: Run database in the background
--ui Run ui component if available for chosen database
```
an example to run migrations and apply fixtures with be like this:
Expand Down
2 changes: 1 addition & 1 deletion internal/container/docker_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func getDockerAddr() (*dockerAddr, error) {
protocol: "npipe",
host: "npipe:////./pipe/docker_engine",
}, nil
} else if strings.Contains(runtime.GOOS, "unix") || strings.Contains(runtime.GOOS, "darwin") {
} else if strings.Contains(runtime.GOOS, "unix") || strings.Contains(runtime.GOOS, "darwin") || strings.Contains(runtime.GOOS, "linux") {
return &dockerAddr{
addr: "/var/run/docker.sock",
protocol: "unix",
Expand Down

0 comments on commit e19c314

Please sign in to comment.