From 4c09beeb30d21d4cf65dbab5331459a5ca7c20c1 Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Sun, 10 Mar 2024 19:11:51 -0500 Subject: [PATCH] Add build and push CI. The CI builds and pushes Linux amd64 images to quay.io tagged using the full commit revision. Signed-off-by: Chris Doherty --- .github/workflows/ci.yml | 20 ++++++++++++++ .github/workflows/release.yml | 21 ++++++++++++++ lint.mk => Lint.mk | 0 Makefile | 52 +++++++++++++++++++++++++++++------ rules.mk => Rules.mk | 0 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml rename lint.mk => Lint.mk (100%) rename rules.mk => Rules.mk (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ccf27cc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: Actions +on: + push: + branches: + - "*" + tags-ignore: + - "v*" + pull_request: {} + workflow_dispatch: {} +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + platform: [amd64] + steps: + - uses: actions/checkout@v4 + - name: Build linux/${{ matrix.platform }} + run: make images -j$(nproc) GOOS=linux GOARCH=${{ matrix.platform }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..020c6f9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,21 @@ +name: Release +on: + push: + branches: + - "main" + workflow_dispatch: {} +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + platform: [amd64] + steps: + - uses: actions/checkout@v4 + + - name: Build linux/${{ matrix.platform }} + run: make images -j $(nproc) GOOS=linux GOARCH=${{ matrix.platform }} + + - name: Push linux/${{ matrix.platform }} + run: make push -j $(nprox) diff --git a/lint.mk b/Lint.mk similarity index 100% rename from lint.mk rename to Lint.mk diff --git a/Makefile b/Makefile index b4ab822..284d6b2 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,52 @@ -BINS = archive2disk cexec grub2disk kexec oci2disk qemuimg2disk rootio slurp syslinux writefile +# Use bash +SHELL := bash +.SHELLFLAGS := -o pipefail -euc +.ONESHELL: -include rules.mk +# Second expansion is used by the image targets to depend on their respective binaries. It is +# necessary because automatic variables are not set on first expansion. +# See https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html. +.SECONDEXPANSION: -all: $(BINS) +# Define the list of actions that can be built. +ACTIONS := archive2disk cexec grub2disk kexec oci2disk qemuimg2disk rootio slurp syslinux writefile -.PHONY: $(BINS) -$(BINS): +# Define the commit for tagging images. +GIT_COMMIT := $(shell git rev-parse HEAD) + +# Define Docker registry details. +DOCKER_REPOSITORY := quay.io/tinkerbell/actions + +include Rules.mk + +.PHONY: help +help: ## Print this help + @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[%\/0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @echo + @echo Individual actions can be built with their name. For example, \`make archive2disk\`. + + +.PHONY: $(ACTIONS) +$(ACTIONS): ## Build a specific action image. docker buildx build --platform linux/amd64 --load -t $@:latest -f ./$@/Dockerfile . +.PHONY: images +images: ## Build all action images. +images: $(ACTIONS) + +.PHONY: push +push: ## Push all action images. +push: $(addprefix push-,$(ACTIONS)) + +.PHONY: push-% +push-%: ## Push a specific action image to the registry. This recipe assumes you are already authenticated with the registry. + IMAGE_NAME=$(DOCKER_REPOSITORY)/$*:$(GIT_COMMIT) + docker tag $*:latest $$IMAGE_NAME + docker push $$IMAGE_NAME + +formatters: ## Run all formatters. formatters: $(toolBins) git ls-files '*.go' | xargs -I% sh -c 'sed -i "/^import (/,/^)/ { /^\s*$$/ d }" % && bin/gofumpt -w %' git ls-files '*.go' | xargs -I% bin/goimports -w % -tidy-all: - for d in $(BINS); do (cd $$d; go mod tidy); done - -include lint.mk +include Lint.mk diff --git a/rules.mk b/Rules.mk similarity index 100% rename from rules.mk rename to Rules.mk