diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4549da4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +**/* +!.git/ +!*.go +!GNUmakefile +!common.mk +!Dockerfile +!.dockerignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9708ce4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.10 AS goircd-builder +ARG PACKAGE=github.com/bbusse/goircd +ENV PACKAGE=$PACKAGE + +WORKDIR /go/src/$PACKAGE/ + +ADD . /go/src/$PACKAGE/ + +RUN export CGO_ENABLED=0 \ + && go get $PACKAGE \ + && make -f GNUmakefile goircd \ + && mv goircd /go/bin/goircd + +FROM alpine AS goircd +COPY --from=goircd-builder /go/bin/goircd /bin/goircd +ENTRYPOINT ["sh","-c"] +CMD ["exec goircd"] \ No newline at end of file diff --git a/GNUmakefile b/GNUmakefile index 04d452d..91a9baa 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,3 +1,4 @@ VERSION = $(shell git describe --tags) +PACKAGE ?= quay.io/goircd/goircd include common.mk diff --git a/common.mk b/common.mk index 888e048..ed5b175 100644 --- a/common.mk +++ b/common.mk @@ -2,3 +2,17 @@ LDFLAGS = -X main.version=$(VERSION) goircd: *.go go build -ldflags "$(LDFLAGS)" + +docker-image: *.go Dockerfile .dockerignore + docker build -t $(shell basename $(PACKAGE)):$(VERSION) . + +docker-image-push: docker-image-push-latest docker-image-push-version + @true + +docker-image-push-version: docker-image-push-latest docker-image-push-version + docker tag $(shell basename $(PACKAGE)):$(VERSION) $(PACKAGE):$(VERSION) + docker push $(PACKAGE):$(VERSION) + +docker-image-push-latest: docker-image + docker tag $(shell basename $(PACKAGE)):$(VERSION) $(PACKAGE):latest + docker push $(PACKAGE):latest