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

Clean up build stuff #77

Merged
merged 4 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: CI

on:
push:
Expand All @@ -11,7 +11,7 @@ jobs:
name: Build
strategy:
matrix:
go-version: [1.13.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x]
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x]
platform: [ubuntu-20.04]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -24,15 +24,15 @@ jobs:
uses: actions/checkout@v4

- name: Build
run: go build -v ./...
run: make build

- name: Test
run: go test -v ./...
run: make test

lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: golangci/golangci-lint-action@v3.7.0
with:
version: v1.51
version: v1.55
20 changes: 7 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
ARG GO_VERSION=1.18
ARG GO_IMAGE=golang:${GO_VERSION}
ARG GO_VERSION=1.21

FROM --platform=$BUILDPLATFORM $GO_IMAGE AS build
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS build
COPY . /go/src/github.com/cpuguy83/go-md2man
WORKDIR /go/src/github.com/cpuguy83/go-md2man
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG TARGETOS TARGETARCH TARGETVARIANT
RUN \
export GOOS="${TARGETOS}"; \
export GOARCH="${TARGETARCH}"; \
if [ "${TARGETARCH}" = "arm" ] && [ "${TARGETVARIANT}" ]; then \
export GOARM="${TARGETVARIANT#v}"; \
fi; \
CGO_ENABLED=0 go build
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
make build

FROM scratch
COPY --from=build /go/src/github.com/cpuguy83/go-md2man/go-md2man /go-md2man
COPY --from=build /go/src/github.com/cpuguy83/go-md2man/bin/go-md2man /go-md2man
ENTRYPOINT ["/go-md2man"]
46 changes: 30 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
GO111MODULE ?= on
LINTER_BIN ?= golangci-lint

export GO111MODULE

GOOS ?= $(if $(TARGETOS),$(TARGETOS),)
GOARCH ?= $(if $(TARGETARCH),$(TARGETARCH),)

ifeq ($(TARGETARCH),amd64)
GOAMD64 ?= $(TARGETVARIANT)
endif

ifeq ($(TARGETARCH),arm)
GOARM ?= $(TARGETVARIANT:v%=%)
endif

ifneq ($(GOOS),)
export GOOS
endif

ifneq ($(GOARCH),)
export GOARCH
endif

ifneq ($(GOAMD64),)
export GOAMD64
endif

ifneq ($(GOARM),)
export GOARM
endif

.PHONY:
build: bin/go-md2man

Expand All @@ -14,22 +40,10 @@ clean:
test:
@go test $(TEST_FLAGS) ./...

bin/go-md2man: actual_build_flags := $(BUILD_FLAGS) -o bin/go-md2man
bin/go-md2man: bin
@CGO_ENABLED=0 go build $(actual_build_flags)

bin:
@mkdir ./bin
bin/go-md2man: go.mod go.sum md2man/* *.go
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't comment on the lines above, but if we're cleaning up;

  • LINTER_BIN looks unused
  • perhaps change GO111MODULE default to auto

Copy link
Owner Author

Choose a reason for hiding this comment

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

No this needs go modules. We need to make sure its own regardless of if we are in gopath or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm... looks like it's ignoring the vendor directory.

rm -rf bin && docker run --rm -e GO111MODULE=auto -e CGO_ENABLED=0 -v $(pwd):/app -w /app golang:1.17 sh -c 'go build -o bin/go-md2man && bin/go-md2man --foobar'
go: downloading github.com/russross/blackfriday/v2 v2.1.0
flag provided but not defined: -foobar

rm -rf bin && docker run --rm -e GO111MODULE=on -e CGO_ENABLED=0 -v $(pwd):/app -w /app golang:1.17 sh -c 'go build -o bin/go-md2man && bin/go-md2man --foobar'
go: downloading github.com/russross/blackfriday/v2 v2.1.0
flag provided but not defined: -foobar

rm -rf bin && docker run --rm -e GO111MODULE=auto -e CGO_ENABLED=0 -v $(pwd):/go/src/github.com/cpuguy83/go-md2man -w /go/src/github.com/cpuguy83/go-md2man golang:1.17 bash -c 'go build -o bin/go-md2man && bin/go-md2man --foobar'
go: downloading github.com/russross/blackfriday/v2 v2.1.0
flag provided but not defined: -foobar

rm -rf bin && docker run --rm -e GO111MODULE=on -e CGO_ENABLED=0 -v $(pwd):/go/src/github.com/cpuguy83/go-md2man -w /go/src/github.com/cpuguy83/go-md2man golang:1.17 bash -c 'go build -o bin/go-md2man && bin/go-md2man --foobar'
go: downloading github.com/russross/blackfriday/v2 v2.1.0
flag provided but not defined: -foobar

So looks like all permutations ignore vendor and will download the module. Disabling networking shows that's indeed the case;

rm -rf bin && docker run --rm -e GO111MODULE=on --network=none -e CGO_ENABLED=0 -v $(pwd):/go/src/github.com/cpuguy83/go-md2man -w /go/src/github.com/cpuguy83/go-md2man golang:1.17 bash -c 'go build -o bin/go-md2man && bin/go-md2man --foobar'
go: github.com/russross/blackfriday/v2@v2.1.0: Get "https://proxy.golang.org/github.com/russross/blackfriday/v2/@v/v2.1.0.mod": dial tcp: lookup proxy.golang.org on 192.168.65.5:53: dial udp 192.168.65.5:53: connect: network is unreachable
go: downloading github.com/russross/blackfriday/v2 v2.1.0
go: github.com/russross/blackfriday/v2@v2.1.0: Get "https://proxy.golang.org/github.com/russross/blackfriday/v2/@v/v2.1.0.mod": dial tcp: lookup proxy.golang.org on 192.168.65.5:53: dial udp 192.168.65.5:53: connect: network is unreachable

The only option that works is to use -mod=vendor:

rm -rf bin && docker run --rm -e GO111MODULE=on --network=none -e CGO_ENABLED=0 -v $(pwd):/go/src/github.com/cpuguy83/go-md2man -w /go/src/github.com/cpuguy83/go-md2man golang:1.17 bash -c 'go build -mod=vendor -o bin/go-md2man && bin/go-md2man --foobar'

flag provided but not defined: -foobar
Usage of bin/go-md2man:

Copy link
Owner Author

Choose a reason for hiding this comment

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

Right yes, vendor is leftover from go mod transition...

Copy link
Owner Author

Choose a reason for hiding this comment

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

Removed vendor dir.

@mkdir -p bin
CGO_ENABLED=0 go build $(BUILD_FLAGS) -o $@

.PHONY: mod
mod:
@go mod tidy

.PHONY: check-mod
check-mod: # verifies that module changes for go.mod and go.sum are checked in
@hack/ci/check_mods.sh

.PHONY: vendor
vendor: mod
@go mod vendor -v

9 changes: 0 additions & 9 deletions hack/ci/check_mods.sh

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/russross/blackfriday/v2/.gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions vendor/github.com/russross/blackfriday/v2/.travis.yml

This file was deleted.

29 changes: 0 additions & 29 deletions vendor/github.com/russross/blackfriday/v2/LICENSE.txt

This file was deleted.