Skip to content

Commit

Permalink
Build multiarch binaries and containers from makefile (kube-burner#100)
Browse files Browse the repository at this point in the history
* Build multiarch binaries and containers from makefile

Signed-off-by: Raul Sevilla <[email protected]>

* Fix BIN_NAME and improve help

Signed-off-by: Raul Sevilla <[email protected]>

* Build containers action

Signed-off-by: Raul Sevilla <[email protected]>

* Remove build-container job

Signed-off-by: Raul Sevilla <[email protected]>
  • Loading branch information
rsevilla87 authored Jul 15, 2021
1 parent adbb71d commit 32b256c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 35 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Containers

on:
push:
branches:
- master
tags:
- "*" # triggers only if push new tag version

jobs:
containers:
name: Build container images
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- arm64
- amd64
- ppc64le

steps:

- name: Install dependencies required for multi-arch builds
run: sudo apt-get install qemu-user-static podman fuse-overlayfs

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up Go 1.16
uses: actions/setup-go@v2
with:
go-version: 1.16
id: go

- name: Login in quay
run: podman login quay.io -u ${QUAY_USER} -p ${QUAY_TOKEN}
env:
QUAY_USER: ${{ secrets.QUAY_USER }}
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}

- name: Build kube-burner binary
run: make build
env:
ARCH: ${{ matrix.arch }}

- name: Build container image
run: make images
env:
ARCH: ${{ matrix.arch }}

- name: Push container image
run: make push
env:
ARCH: ${{ matrix.arch }}
14 changes: 3 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
- name: Build
run: make build

- name: Build container images
run: make images

- name: Install
run: sudo make install

Expand Down Expand Up @@ -98,14 +101,3 @@ jobs:
#working-directory: # optional
# the token is used for fetching patch of a pull request to show only new issues
#github-token: # default is ${{ github.token }}

build-container:
name: Build container image
runs-on: ubuntu-latest
steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- run: make images

11 changes: 3 additions & 8 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
FROM registry.fedoraproject.org/fedora-minimal:latest as builder

RUN microdnf install -y --nodocs golang make git && microdnf clean all
COPY . /root/kube-burner
RUN make clean -C /root/kube-burner && make build -C /root/kube-burner

FROM registry.fedoraproject.org/fedora-minimal:latest

COPY --from=builder /root/kube-burner/bin/kube-burner /bin/kube-burner
LABEL maintainer="Raul Sevilla <[email protected]"
COPY kube-burner /bin/kube-burner
LABEL io.k8s.display-name="kube-burner" \
maintainer="Raul Sevilla <[email protected]"
ENTRYPOINT ["/bin/kube-burner"]
47 changes: 31 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@

.PHONY: build clean test help
.PHONY: build clean test help images push


BIN_DIR = bin
ARCH ?= amd64
BIN_NAME = kube-burner
CGO=0
BIN_DIR = bin
BIN_PATH = $(BIN_DIR)/$(ARCH)/$(BIN_NAME)
CGO = 0

GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_BRANCH = $(shell git rev-parse --symbolic-full-name --abbrev-ref HEAD)
VERSION = $(shell git rev-parse --symbolic-full-name --abbrev-ref HEAD)
SOURCES := $(shell find . -type f -name "*.go")
BUILD_DATE = $(shell date '+%Y-%m-%d-%H:%M:%S')
KUBE_BURNER_VERSION= github.com/cloud-bulldozer/kube-burner/pkg/version

# Containers
ifeq (, $(shell command -v docker))
ENGINE := podman
else
ENGINE := docker
endif

all: build
REGISTRY = quay.io
ORG = cloud-bulldozer
CONTAINER_NAME = $(REGISTRY)/$(ORG)/kube-burner:$(VERSION)-$(ARCH)

all: lint build images push

help:
@echo "Commands for $(BIN_NAME):"
@echo "Commands for $(BIN_PATH):"
@echo
@echo 'Usage:'
@echo ' make build Compile the project.'
@echo ' make clean Clean the directory tree.'
@echo
@echo ' make clean Clean the compiled binaries'
@echo ' [ARCH=arch] make build Compile the project for arch, default amd64'
@echo ' [ARCH=arch] make install Installs kube-burner binary in the system, default amd64'
@echo ' [ARCH=arch] make images Build images for arch, default amd64'
@echo ' [ARCH=arch] make push Push images for arch, default amd64'
@echo ' make help Show this message'

build: $(BIN_DIR)/$(BIN_NAME)
build: $(BIN_PATH)

$(BIN_DIR)/$(BIN_NAME): $(SOURCES)
@echo "Building $(BIN_NAME)"
$(BIN_PATH): $(SOURCES)
@echo -e "\033[2mBuilding $(BIN_PATH)\033[0m\n"
@echo "GOPATH=$(GOPATH)"
CGO_ENABLED=$(CGO) go build -v -mod vendor -ldflags "-X $(KUBE_BURNER_VERSION).GitCommit=$(GIT_COMMIT) -X $(KUBE_BURNER_VERSION).BuildDate=$(BUILD_DATE) -X $(KUBE_BURNER_VERSION).Version=$(GIT_BRANCH)" -o $(BIN_DIR)/$(BIN_NAME) ./cmd/kube-burner
GOARCH=$(ARCH) CGO_ENABLED=$(CGO) go build -v -mod vendor -ldflags "-X $(KUBE_BURNER_VERSION).GitCommit=$(GIT_COMMIT) -X $(KUBE_BURNER_VERSION).BuildDate=$(BUILD_DATE) -X $(KUBE_BURNER_VERSION).Version=$(VERSION)" -o $(BIN_PATH) ./cmd/kube-burner

lint:
golangci-lint run

clean:
test ! -e bin/$(BIN_NAME) || rm $(BIN_DIR)/$(BIN_NAME)
test ! -e $(BIN_DIR) || rm -Rf $(BIN_PATH)

vendor:
go mod vendor

install:
cp $(BIN_DIR)/$(BIN_NAME) /usr/bin/$(BIN_NAME)
cp $(BIN_PATH) /usr/bin/$(BIN_NAME)

images:
$(ENGINE) build -f Containerfile . -t kube-burner:latest
@echo "\n\033[2mBuilding container $(CONTAINER_NAME)\033[0m\n"
$(ENGINE) build --arch=$(ARCH) -f Containerfile $(BIN_DIR)/$(ARCH)/ -t $(CONTAINER_NAME)

push:
@echo "\033[2mPushing container $(CONTAINER_NAME)\033[0m\n"
$(ENGINE) push $(CONTAINER_NAME)

0 comments on commit 32b256c

Please sign in to comment.