Skip to content

Commit

Permalink
Merge pull request #17 from cpanato/updates
Browse files Browse the repository at this point in the history
Introduce makefile to run build/release commands
  • Loading branch information
kaniini authored Mar 1, 2022
2 parents cfdbf45 + 917ffce commit 1bdb6fb
Show file tree
Hide file tree
Showing 10 changed files with 621 additions and 49 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
push:

env:
GO_VERSION: 1.17.x

jobs:
build:
name: build
Expand All @@ -14,21 +17,19 @@ jobs:

- uses: actions/setup-go@f6164bd8c8acb4a71fb2791a8b6c4024ff038dab # v2.1.5
with:
go-version: '1.17.x'
go-version: ${{ env.GO_VERSION }}

- name: build
run: go build -o apko ./cmd/apko/main.go

test:
name: test
runs-on: ubuntu-latest
run: |
make apko
./apko version
steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0

- uses: actions/setup-go@f6164bd8c8acb4a71fb2791a8b6c4024ff038dab # v2.1.5
- uses: goreleaser/goreleaser-action@79d4afbba1b4eff8b9a98e3d2e58c4dbaf094e2b # v2.8.1
with:
go-version: '1.17.x'
version: v1.5.0
install-only: true

- name: test
run: go test ./...
- name: snapshot
run: |
make snapshot
./dist/apko-build_linux_amd64/apko version
2 changes: 1 addition & 1 deletion .github/workflows/go-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: Checkout code
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- name: Test
run: go test ./...
run: make test
4 changes: 2 additions & 2 deletions .github/workflows/mink-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -48,7 +48,7 @@ jobs:
- name: Build and install apko task
run: |
ko apply -BRf config/
make ko-apply
- name: Build examples
run: |
Expand Down
42 changes: 22 additions & 20 deletions .github/workflows/release.yaml
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:
Expand All @@ -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 }}

Expand All @@ -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
12 changes: 5 additions & 7 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ on:
pull_request:

env:
GO_VERSION: 1.17.7
GO_VERSION: 1.17.x

jobs:
golangci:
name: lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 #v2.4.0

- uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 #v2.2.0
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
- uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2.2.0
with:
go-version: ${{ env.GO_VERSION }}

go-version: ${{ env.GO_VERSION }}
- name: golangci-lint
uses: golangci/golangci-lint-action@b517f99ae23d86ecc4c0dec08dcf48d2336abc29 #v2.5.2
uses: golangci/golangci-lint-action@b517f99ae23d86ecc4c0dec08dcf48d2336abc29 # v3.1.0
timeout-minutes: 5
with:
version: v1.44.2
6 changes: 6 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ builds:
- "386"
- amd64
- arm64
flags:
- -trimpath
mod_timestamp: '{{ .CommitTimestamp }}'
ldflags:
- -extldflags "-static"
- "{{ .Env.LDFLAGS }}"

signs:
- id: apko-cosign
Expand Down
12 changes: 12 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@
baseImageOverrides:
# TODO(mattmoor): Talk to kaniini about the best image to use here.
chainguard.dev/apko/cmd/apko: docker.io/alpine:latest

builds:
- id: apko
dir: .
main: ./cmd/apko
env:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- -extldflags "-static"
- "{{ .Env.LDFLAGS }}"
153 changes: 153 additions & 0 deletions Makefile
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
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/Azure/azure-sdk-for-go v46.4.0+incompatible // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.8 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.4 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.5 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.2 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.1 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
Expand All @@ -38,16 +38,17 @@ require (
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
github.com/containerd/stargz-snapshotter/estargz v0.11.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dimchansky/utfbom v1.1.0 // indirect
github.com/docker/cli v20.10.12+incompatible // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v20.10.12+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.14.2 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
Expand All @@ -62,4 +63,5 @@ require (
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gotest.tools/v3 v3.0.3 // indirect
)
Loading

0 comments on commit 1bdb6fb

Please sign in to comment.