forked from kube-burner/kube-burner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build multiarch binaries and containers from makefile (kube-burner#100)
* 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
1 parent
adbb71d
commit 32b256c
Showing
4 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |