diff --git a/Dockerfile b/Dockerfile index 85e5ad7..d22dbbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,17 @@ FROM golang:1.21-alpine AS build -LABEL MAINTAINER = 'Friends of Go (it@friendsofgo.tech)' +LABEL MAINTAINER='Friends of Go (it@friendsofgo.tech)' ARG TARGETOS=linux ARG TARGETARCH=amd64 +ARG TAG="" RUN apk add --update git RUN apk add ca-certificates WORKDIR /go/src/github.com/friendsofgo/killgrave COPY . . -RUN go mod tidy && TAG=$(git describe --tags --abbrev=0) \ +RUN go mod tidy \ + && if [ -z "$TAG" ]; then TAG=$(git describe --tags --abbrev=0); fi \ && LDFLAGS=$(echo "-s -w -X github.com/friendsofgo/killgrave/internal/app/cmd._version="docker-$TAG) \ && CGO_ENABLED=0 GOOS="${TARGETOS}" GOARCH="${TARGETARCH}" go build -a -installsuffix cgo -o /go/bin/killgrave -ldflags "$LDFLAGS" cmd/killgrave/main.go diff --git a/Makefile b/Makefile index b773558..6f58600 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,11 @@ .PHONY: build build: - go build -ldflags "-s -w -X 'github.com/friendsofgo/killgrave/internal/app/cmd._version=`git rev-parse --abbrev-ref HEAD`-`git rev-parse --short HEAD`'" -o bin/killgrave cmd/killgrave/main.go \ No newline at end of file + go build -ldflags "-s -w -X 'github.com/friendsofgo/killgrave/internal/app/cmd._version=`git rev-parse --abbrev-ref HEAD`-`git rev-parse --short HEAD`'" -o bin/killgrave cmd/killgrave/main.go + +.PHONY: build-docker +build-docker: + docker build --build-arg TAG=$(TAG) -t killgrave:$(TAG) . + +.PHONY: test +test: + go test -v -vet=off -race ./...