Skip to content

Commit

Permalink
Merge pull request #10 from taiyoh/fix/dockerfile-for-dockerhub
Browse files Browse the repository at this point in the history
refine Dockerfile for dockerhub
  • Loading branch information
taiyoh authored Mar 9, 2020
2 parents 8efd601 + 2528d6f commit 6f1fd0e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM scratch
FROM golang:1.13.8-buster AS toyhose-builder

ADD . /app
WORKDIR /app

ARG version
RUN make docker

FROM scratch

ADD ./pkg/${version}/toyhose_linux_amd64/toyhose .
COPY --from=toyhose-builder /bin/toyhose ./toyhose

CMD [ "./toyhose" ]
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ GIT_VERSION=$(shell git describe --tags)
CURRENT_REVISION=$(shell git rev-parse --short HEAD)
LDFLAGS="-s -w -X main.version=$(GIT_VERSION) -X main.commit=$(CURRENT_REVISION)"

.PHONY: test install build release docker
.PHONY: build release docker clean

install:
cd cmd/toyhose && go install
clean:
rm -rf pkg/$(GIT_VERSION)/ && mkdir -p pkg/$(GIT_VERSION)/dist

test:
docker-compose up -d
go test -v -race -timeout 30s
docker-compose down
pkg/$(GIT_VERSION)/toyhose_darwin_amd64/toyhose:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o pkg/$(GIT_VERSION)/toyhose_darwin_amd64/toyhose -ldflags=$(LDFLAGS) cmd/toyhose/main.go

build:
rm -rf pkg/$(GIT_VERSION)/ && mkdir -p pkg/$(GIT_VERSION)/dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose -ldflags=$(LDFLAGS) cmd/toyhose/main.go
cd pkg/$(GIT_VERSION)/toyhose_linux_amd64 && tar cvzf toyhose_$(GIT_VERSION)_linux_amd64.tar.gz toyhose && mv toyhose_$(GIT_VERSION)_linux_amd64.tar.gz ../dist
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o pkg/$(GIT_VERSION)/toyhose_darwin_amd64/toyhose -ldflags=$(LDFLAGS) cmd/toyhose/main.go
pkg/$(GIT_VERSION)/toyhose_darwin_amd64/toyhose_$(GIT_VERSION)_darwin_amd64.zip: pkg/$(GIT_VERSION)/toyhose_darwin_amd64/toyhose
cd pkg/$(GIT_VERSION)/toyhose_darwin_amd64 && zip toyhose_$(GIT_VERSION)_darwin_amd64.zip * && mv toyhose_$(GIT_VERSION)_darwin_amd64.zip ../dist

pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose -ldflags=$(LDFLAGS) cmd/toyhose/main.go

pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose_$(GIT_VERSION)_linux_amd64.tar.gz: pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose
cd pkg/$(GIT_VERSION)/toyhose_linux_amd64 && tar cvzf toyhose_$(GIT_VERSION)_linux_amd64.tar.gz toyhose && mv toyhose_$(GIT_VERSION)_linux_amd64.tar.gz ../dist

build: clean pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose_$(GIT_VERSION)_linux_amd64.tar.gz pkg/$(GIT_VERSION)/toyhose_darwin_amd64/toyhose_$(GIT_VERSION)_darwin_amd64.zip

release:
ghr -n $(GIT_VERSION) $(GIT_VERSION) pkg/$(GIT_VERSION)/dist

docker: build
docker build -t taiyoh/toyhose:$(GIT_VERSION) --build-arg version=$(GIT_VERSION) .
docker: clean pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose
mv pkg/$(GIT_VERSION)/toyhose_linux_amd64/toyhose /bin/toyhose
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/taiyoh/toyhose
go 1.13

require (
github.com/aws/aws-sdk-go v1.29.10
github.com/aws/aws-sdk-go v1.29.19
github.com/google/uuid v1.1.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/rs/zerolog v1.18.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aws/aws-sdk-go v1.29.10 h1:QJOQq1xNmdrY5mXUmC8CHXzZPve8134Bx/Ux0o6s38s=
github.com/aws/aws-sdk-go v1.29.10/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
github.com/aws/aws-sdk-go v1.29.19 h1:+jifYixffn6kzWygtGWFWQMv0tDGyISZHNwugF9V2sE=
github.com/aws/aws-sdk-go v1.29.19/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit 6f1fd0e

Please sign in to comment.