Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it easier to build the image and run the tests #172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM golang:1.21-alpine AS build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes on this file must be reflected on GitHub Workflows. At least, in the release.yml, I think.


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

Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
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) .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work by default (e.g. make build-docker).

What about defining TAG in the Makefile itself? Like:

REF=$(shell git rev-parse --abbrev-ref HEAD)
HASH=$(shell git rev-parse --short HEAD)
TAG="${REF}-${HASH}"


.PHONY: test
test:
go test -v -vet=off -race ./...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
go test -v -vet=off -race ./...
go test -v -count=1 -vet=off -race ./...

I'd suggest adding -count=1 to prevent caching, and thus make results more reliable at almost no cost (as the suite is pretty fast).

Additionally, could you explain why do we need -vet=off, please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it's also on the CI, so perhaps an opportunity to remove it from there? Unless we have a reason to keep it, of course. But I cannot see it and I don't remember any.