Skip to content

Commit

Permalink
Clean up build stuff
Browse files Browse the repository at this point in the history
1. Uses modern go in Dockerfile
2. Fix `make build` pre-reqs
3. Remove interim BUILDFLAGS handling

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Feb 4, 2024
1 parent f67b5f6 commit 21f901d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
@@ -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
19 changes: 6 additions & 13 deletions Dockerfile
@@ -1,20 +1,13 @@
ARG GO_VERSION=1.18
ARG GO_IMAGE=golang:${GO_VERSION}
ARG GO_VERSION=1.21

FROM --platform=$BUILDPLATFORM $GO_IMAGE AS build
FROM 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
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"]
39 changes: 33 additions & 6 deletions Makefile
Expand Up @@ -3,6 +3,36 @@ 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

vars:
@go env

.PHONY:
build: bin/go-md2man

Expand All @@ -14,12 +44,9 @@ 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
@mkdir -p bin
CGO_ENABLED=0 go build $(BUILD_FLAGS) -o $@

.PHONY: mod
mod:
Expand Down

0 comments on commit 21f901d

Please sign in to comment.