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

update/buildx #234

Merged
merged 3 commits into from
Jan 11, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3

- name: tag
id: get_tag
run: echo ::set-output name=git_tag::${GITHUB_REF/refs\/tags\//}
Expand Down Expand Up @@ -87,8 +87,8 @@ jobs:
id: get_tag
run: echo ::set-output name=git_tag::${GITHUB_REF/refs\/tags\//}

- name: setup QEMU
uses: docker/setup-qemu-action@v2
- uses: benjlevesque/short-sha@v2.1
id: short-sha

- name: setup buildx
uses: docker/setup-buildx-action@v2
Expand All @@ -104,6 +104,13 @@ jobs:
with:
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
build-args: |
BRANCH=${{ github.ref-name }}
COMMIT=${{ steps.short-sha.outputs.sha }}
platforms: |
linux/amd64
linux/arm64
push: true
tags: ${{ secrets.DOCKER_ORG }}/pumba:${{ steps.get_tag.outputs.git_tag }}
tags: |
${{ secrets.DOCKER_ORG }}/pumba:${{ steps.get_tag.outputs.git_tag }}
${{ secrets.DOCKER_ORG }}/pumba:latest
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: git-dirty
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.4.0
hooks:
- id: pretty-format-golang
- repo: https://github.com/mattlqx/pre-commit-sign
rev: v1.1.3
hooks:
- id: sign-commit
- repo: https://github.com/syntaqx/git-hooks
rev: v0.0.17
hooks:
- id: forbid-binary
- id: go-test
- id: go-mod-tidy
- repo: local
hooks:
- id: lint
name: lint-check
entry: make lint
language: system
files: \.go
55 changes: 29 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
MODULE = $(shell $(GO) list -m)
DATE ?= $(shell date "+%Y-%m-%d %H:%M %Z")
VERSION ?= $(shell git describe --tags --always --dirty 2> /dev/null || \
cat $(CURDIR)/VERSION 2> /dev/null || echo v0)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
PKGS = $(or $(PKG),$(shell $(GO) list ./...))
TESTPKGS = $(shell $(GO) list -f \
GO := go
DOCKER := docker
MOCK := mockery
BATS := bats
LINT := golangci-lint
GOCOV := gocov
GOCOVXML := gocov-xml
GOUNIT := go-junit-report
GOMOCK := mockery
TIMEOUT := 15

MODULE := $(shell $(GO) list -m)
DATE ?= $(shell date "+%Y-%m-%d %H:%M %Z")
VERSION ?= $(shell git describe --tags --always --dirty 2> /dev/null || cat $(CURDIR)/VERSION 2> /dev/null || echo v0)
COMMIT ?= $(or $(shell git rev-parse --short HEAD 2>/dev/null), $(or $(subst 1,7,$(GITHUB_SHA)), unknown))
BRANCH ?= $(or $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null), $(or $(GITHUB_REF_NAME), master))
PKGS := $(or $(shell $(GO) list ./...), $(PKG))
TESTPKGS := $(shell $(GO) list -f \
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
$(PKGS))
LINT_CONFIG = $(CURDIR)/.golangci.yaml
LDFLAGS_VERSION = -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH) -X \"main.buildTime=$(DATE)\"
BIN = $(CURDIR)/.bin
TARGETOS ?= $(GOOS)
TARGETARCH ?= $(GOARCH)
LINT_CONFIG := $(CURDIR)/.golangci.yaml
LDFLAGS_VERSION := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH) -X \"main.buildTime=$(DATE)\"
BIN := $(CURDIR)/.bin
TARGETOS := $(or $(TARGETOS), linux)
TARGETARCH := $(or $(TARGETARCH), amd64)

# platforms and architectures for release
PLATFORMS = darwin linux windows
ARCHITECTURES = amd64 arm64

GO = go
DOCKER = docker
MOCK = mockery
BATS = bats
LINT = golangci-lint
GOCOV = gocov
GOCOVXML = gocov-xml
GOUNIT = go-junit-report
GOMOCK = mockery

TIMEOUT = 15
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m▶\033[0m")

export CGO_ENABLED=0
export GOPROXY=https://proxy.golang.org
export GOOS=$(TARGETOS)
export GOARCH=$(TARGETARCH)

.PHONY: all
all: setup-tools fmt lint test build
Expand All @@ -43,8 +45,8 @@ dependency: ; $(info $(M) downloading dependencies...) @ ## Build program binary
$Q $(GO) mod download

.PHONY: build
build: dependency | ; $(info $(M) building $(TARGETOS)/$(TARGETARCH) binary...) @ ## Build program binary
$Q env GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) $(GO) build \
build: dependency | ; $(info $(M) building $(GOOS)/$(GOARCH) binary...) @ ## Build program binary
$Q $(GO) build \
-tags release \
-ldflags "$(LDFLAGS_VERSION)" \
-o $(BIN)/$(basename $(MODULE)) ./cmd/main.go
Expand Down Expand Up @@ -153,6 +155,7 @@ version:
debug:
@echo $(LDFLAGS_VERSION)
@echo $(BIN)/$(basename $(MODULE))
@echo $(TARGETOS)/$(TARGETARCH)

# helper function: find module path
define source_of
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.3
0.9.7
18 changes: 14 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# ----- Go Builder Image ------
#
FROM golang:1.19 AS builder
FROM --platform=$BUILDPLATFORM golang:1.19 AS builder

# curl git bash
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -37,19 +37,29 @@ COPY VERSION .

# run lint, test race and calculate coverage
ARG SKIP_TESTS
RUN --mount=type=cache,target=/root/.cache/go-build if [ -z "$SKIP_TESTS" -o "$SKIP_TESTS" = false ]; then make lint test-race test-coverage; fi
RUN --mount=type=cache,target=/root/.cache/go-build if [ -z "$SKIP_TESTS" ] || [ "$SKIP_TESTS" = false ]; then make lint test-coverage; fi
# run test race only on amd64
RUN if ([ -z "$SKIP_TESTS" ] || [ "$SKIP_TESTS" = false ]) && [ "$TARGETARCH" = "amd64" ]; then make test-race; fi

# build pumba binary for TARGETOS/TARGETARCH (default: linux/amd64)
# passed by buildkit
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/root/.cache/go-build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH} make build
# commit short hash is expected, can be discovered only if .git folder is present
ARG COMMIT
# branch name is expected, can be discovered only if .git folder is present
ARG BRANCH
# build date is expected, will be disovered by Makefile
ARG DATE
# version is expected, will be discovered from VERSION file
ARG VERSION
RUN --mount=type=cache,target=/root/.cache/go-build make build TARGETOS=${TARGETOS} TARGETARCH=${TARGETARCH}


#
# ------ Pumba Integration Tests ------
#
FROM bats/bats:1.8.2 as integration-tests
FROM --platform=$TARGETPLATFORM bats/bats:1.8.2 as integration-tests

# install required packages
RUN apk add --no-cache docker iproute2
Expand Down