-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from cpanato/updates
Introduce makefile to run build/release commands
- Loading branch information
Showing
10 changed files
with
621 additions
and
49 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
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ jobs: | |
with: | ||
go-version: '1.17.x' | ||
|
||
- uses: imjasonh/[email protected] | ||
- uses: imjasonh/setup-ko@2c3450ca27f6e6f2b02e72a40f2163c281a1f675 # v0.4 | ||
with: | ||
version: v0.10.0 | ||
|
||
|
@@ -48,7 +48,7 @@ jobs: | |
- name: Build and install apko task | ||
run: | | ||
ko apply -BRf config/ | ||
make ko-apply | ||
- name: Build examples | ||
run: | | ||
|
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,9 +1,13 @@ | ||
|
||
name: Create Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 | ||
|
||
name: Create Release | ||
env: | ||
GO_VERSION: 1.17.x | ||
|
||
jobs: | ||
cli: | ||
|
@@ -16,15 +20,17 @@ jobs: | |
contents: write | ||
|
||
steps: | ||
- uses: actions/setup-go@f6164bd8c8acb4a71fb2791a8b6c4024ff038dab | ||
- uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2.2.0 | ||
with: | ||
go-version: 1.17.x | ||
- uses: actions/checkout@v2 | ||
- uses: sigstore/cosign-installer@main | ||
- uses: goreleaser/goreleaser-action@v2 | ||
go-version: ${{ env.GO_VERSION }} | ||
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 | ||
- uses: sigstore/cosign-installer@179e0f15e70e22ca2e7254fc12d68a9fbab35614 # v2.0.1 | ||
- uses: goreleaser/goreleaser-action@79d4afbba1b4eff8b9a98e3d2e58c4dbaf094e2b # v2.8.1 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
version: v1.5.0 | ||
install-only: true | ||
- name: Release | ||
run: make release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
|
@@ -40,26 +46,22 @@ jobs: | |
|
||
env: | ||
KO_DOCKER_REPO: ghcr.io/${{ github.repository }} | ||
KOFLAGS: --platform=all --bare | ||
COSIGN_EXPERIMENTAL: "true" | ||
|
||
steps: | ||
- uses: actions/setup-go@f6164bd8c8acb4a71fb2791a8b6c4024ff038dab | ||
- uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2.2.0 | ||
with: | ||
go-version: 1.17.x | ||
- uses: imjasonh/[email protected] | ||
go-version: ${{ env.GO_VERSION }} | ||
- uses: imjasonh/setup-ko@2c3450ca27f6e6f2b02e72a40f2163c281a1f675 # v0.4 | ||
with: | ||
version: v0.10.0 | ||
- uses: sigstore/cosign-installer@main | ||
- uses: docker/login-action@v1 | ||
- uses: sigstore/cosign-installer@179e0f15e70e22ca2e7254fc12d68a9fbab35614 # v2.0.1 | ||
- uses: docker/login-action@6af3c118c8376c675363897acf1757f7a9be6583 # v1.13.0 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ github.token }} | ||
- uses: actions/checkout@v2 | ||
- name: Publish apko image | ||
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 | ||
- name: Publish/Sign apko image | ||
run: | | ||
DIGEST=$(ko build ${KOFLAGS} --tags $(basename "${{ github.ref }}" ) ./cmd/apko) | ||
# TODO: Add attributes with version, sha, etc. | ||
cosign sign ${DIGEST} | ||
make sign-image |
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
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 |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
GOFILES ?= $(shell find . -type f -name '*.go' -not -path "./vendor/*") | ||
|
||
RUNTIME_IMAGE ?= gcr.io/distroless/static | ||
# Set version variables for LDFLAGS | ||
GIT_TAG ?= dirty-tag | ||
GIT_VERSION ?= $(shell git describe --tags --always --dirty) | ||
GIT_HASH ?= $(shell git rev-parse HEAD) | ||
DATE_FMT = +'%Y-%m-%dT%H:%M:%SZ' | ||
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) | ||
ifdef SOURCE_DATE_EPOCH | ||
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)") | ||
else | ||
BUILD_DATE ?= $(shell date "$(DATE_FMT)") | ||
endif | ||
GIT_TREESTATE = "clean" | ||
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi) | ||
ifeq ($(DIFF), 1) | ||
GIT_TREESTATE = "dirty" | ||
endif | ||
|
||
SRCS = $(shell find cmd -iname "*.go") $(shell find pkg -iname "*.go") | ||
|
||
PKG ?= sigs.k8s.io/release-utils/version | ||
LDFLAGS=-buildid= -X $(PKG).gitVersion=$(GIT_VERSION) \ | ||
-X $(PKG).gitCommit=$(GIT_HASH) \ | ||
-X $(PKG).gitTreeState=$(GIT_TREESTATE) \ | ||
-X $(PKG).buildDate=$(BUILD_DATE) | ||
|
||
KO_DOCKER_REPO ?= ghcr.io/chainguard-dev/apko | ||
DIGEST ?= | ||
|
||
########## | ||
# ko build | ||
########## | ||
|
||
.PHONY: ko | ||
ko: ## Build images using ko | ||
$(eval DIGEST := $(shell LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \ | ||
ko build --bare \ | ||
--platform=all --tags $(GIT_VERSION) --tags $(GIT_HASH) \ | ||
chainguard.dev/apko/cmd/apko)) | ||
@echo Image Digest $(DIGEST) | ||
|
||
.PHONY: ko-local | ||
ko-local: ## Build images locally using ko | ||
LDFLAGS="$(LDFLAGS)" GIT_HASH=$(GIT_HASH) GIT_VERSION=$(GIT_VERSION) \ | ||
ko build --bare \ | ||
--tags $(GIT_VERSION) --tags $(GIT_HASH) --local \ | ||
chainguard.dev/apko/cmd/apko | ||
|
||
.PHONY: ko-apply | ||
ko-apply: ## Build the image and apply the manifests | ||
LDFLAGS="$(LDFLAGS)" \ | ||
ko apply --base-import-paths \ | ||
--recursive --filename config/ | ||
|
||
########## | ||
# Build | ||
########## | ||
|
||
.PHONY: apko | ||
apko: $(SRCS) | ||
CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o $@ ./cmd/apko | ||
|
||
.PHONY: install | ||
install: $(SRCS) | ||
CGO_ENABLED=0 go install -trimpath -ldflags "$(LDFLAGS)" ./cmd/apko | ||
|
||
##################### | ||
# lint / test section | ||
##################### | ||
|
||
GOLANGCI_LINT_DIR = $(shell pwd)/bin | ||
GOLANGCI_LINT_BIN = $(GOLANGCI_LINT_DIR)/golangci-lint | ||
|
||
.PHONY: golangci-lint | ||
golangci-lint: | ||
rm -f $(GOLANGCI_LINT_BIN) || : | ||
set -e ;\ | ||
GOBIN=$(GOLANGCI_LINT_DIR) go install github.com/golangci/golangci-lint/cmd/[email protected] ;\ | ||
|
||
.PHONY: fmt | ||
fmt: ## Format all go files | ||
@ $(MAKE) --no-print-directory log-$@ | ||
goimports -w $(GOFILES) | ||
|
||
.PHONY: checkfmt | ||
checkfmt: SHELL := /usr/bin/env bash | ||
checkfmt: ## Check formatting of all go files | ||
@ $(MAKE) --no-print-directory log-$@ | ||
$(shell test -z "$(shell gofmt -l $(GOFILES) | tee /dev/stderr)") | ||
$(shell test -z "$(shell goimports -l $(GOFILES) | tee /dev/stderr)") | ||
|
||
log-%: | ||
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \ | ||
awk \ | ||
'BEGIN { \ | ||
FS = ":.*?## " \ | ||
}; \ | ||
{ \ | ||
printf "\033[36m==> %s\033[0m\n", $$2 \ | ||
}' | ||
|
||
.PHONY: lint | ||
lint: checkfmt golangci-lint ## Run linters and checks like golangci-lint | ||
$(GOLANGCI_LINT_BIN) run -n | ||
|
||
.PHONY: test | ||
test: ## Run go test | ||
go test ./... | ||
|
||
.PHONY: clean | ||
clean: ## Clean the workspace | ||
rm -rf apko | ||
rm -rf bin/ | ||
rm -rf dist/ | ||
|
||
####################### | ||
# Release / goreleaser | ||
####################### | ||
|
||
.PHONY: snapshot | ||
snapshot: ## Run Goreleaser in snapshot mode | ||
LDFLAGS="$(LDFLAGS)" goreleaser release --rm-dist --snapshot --skip-sign --skip-publish | ||
|
||
.PHONY: release | ||
release: ## Run Goreleaser in release mode | ||
LDFLAGS="$(LDFLAGS)" goreleaser release --rm-dist | ||
|
||
|
||
####################### | ||
# Sign images | ||
####################### | ||
.PHONY: sign-image | ||
sign-image: ko ## Sign images built using ko | ||
cosign sign $(DIGEST) | ||
|
||
################## | ||
# help | ||
################## | ||
|
||
help: ## Display help | ||
@awk -F ':|##' \ | ||
'/^[^\t].+?:.*?##/ {\ | ||
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \ | ||
}' $(MAKEFILE_LIST) | sort |
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
Oops, something went wrong.