diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f3b6411 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/.git diff --git a/Dockerfile b/Dockerfile index 955ef30..d82a540 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ -FROM mysql:8.0.20 +FROM golang:1.14.0-buster as builder +WORKDIR /go +COPY ./ . +RUN export GOPATH= && go mod download && go build -o /go/ -v -ldflags '-s -w' ./cmd/kamimai -ENV MYSQL_USER kamimai -ENV MYSQL_PASSWORD kamimai -ENV MYSQL_DATABASE kamimai -ENV MYSQL_ROOT_PASSWORD root -ENV MYSQL_HOST 127.0.0.1 -ENV MYSQL_PORT 3306 +FROM gcr.io/distroless/base +COPY --from=builder go/kamimai . +ENTRYPOINT ["/kamimai"] +CMD ["--help"] diff --git a/Makefile b/Makefile index e83d5d5..27b2604 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ build: gox @mkdir -p $(ARTIFACTS_DIR)/$(VERSION) && cd $(ARTIFACTS_DIR)/$(VERSION); \ gox $(LDFLAGS) $(TARGETS) +build-docker-image: + docker build -t kamimai:$(VERSION) --no-cache --rm --compress . + release: ghr verify-github-token build @ghr -c $(COMMITISH) -u $(PROJECT_USERNAME) -r $(PROJECT_REPONAME) -t $$GITHUB_TOKEN \ --replace $(VERSION) $(ARTIFACTS_DIR)/$(VERSION) diff --git a/README.md b/README.md index 40b8a81..d9192ef 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,7 @@ func main() { ### Setup ```sh -docker build -t $ImageName . -docker run --name $ContainerName -d -it --rm -p 3306:3306 $ImageName +docker-compose up -d # kamimai の実行 MYSQL_HOST=127.0.0.1 MYSQL_USER=kamimai MYSQL_PASSWORD=kamimai go run ./cmd/kamimai --dry-run --env=development --path=./examples/mysql create test diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..514050a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '2' +services: + mysql: + image: mysql:8.0.20 + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: "yes" + MYSQL_USER: kamimai + MYSQL_PASSWORD: kamimai + MYSQL_DATABASE: kamimai + MYSQL_ROOT_PASSWORD: root + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + ports: + - "3306:3306"