Skip to content

Commit

Permalink
simplify more
Browse files Browse the repository at this point in the history
  • Loading branch information
mjudeikis committed Nov 26, 2024
1 parent fffa0f1 commit fa71417
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 124 deletions.
50 changes: 2 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ main ]
branches: [ master ]
tags:
- "*"
pull_request:
Expand All @@ -21,7 +21,7 @@ jobs:
with:
go-version: 1.23
- name: Build
run: make
run: make build

docs:
runs-on: ubuntu-latest
Expand All @@ -37,41 +37,6 @@ jobs:
# make gen-docs
# git diff --exit-code

linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Build kg and kgctl for all Linux Architectures
run: make all-build

darwin:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Build kgctl for Darwin amd64
run: make OS=darwin ARCH=amd64
- name: Build kgctl for Darwin arm64
run: make OS=darwin ARCH=arm64

windows:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Build kgctl for Windows
run: make OS=windows

unit:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -105,14 +70,3 @@ jobs:
- name: Lint Code
run: make lint

container:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
- name: Container
run: make container

79 changes: 3 additions & 76 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RELEASE_BINS := $(addprefix bin/release/kgctl-, $(addprefix linux-, $(ALL_ARCH))
PROJECT := kilo
PKG := github.com/squat/$(PROJECT)
REGISTRY ?= index.docker.io
IMAGE ?= squat/$(PROJECT)
IMAGE ?= castai/$(PROJECT)
FULLY_QUALIFIED_IMAGE := $(REGISTRY)/$(IMAGE)

TAG := $(shell git describe --abbrev=0 --tags HEAD 2>/dev/null)
Expand Down Expand Up @@ -217,81 +217,8 @@ website/build/index.html: website/docs/README.md docs/api.md
yarn --cwd website install
yarn --cwd website build

container: .container-$(ARCH)-$(VERSION) container-name
.container-$(ARCH)-$(VERSION): bin/linux/$(ARCH)/kg bin/linux/$(ARCH)/kgctl Dockerfile
@i=0; for a in $(ALL_ARCH); do [ "$$a" = $(ARCH) ] && break; i=$$((i+1)); done; \
ia=""; iv=""; \
j=0; for a in $(DOCKER_ARCH); do \
[ "$$i" -eq "$$j" ] && ia=$$(echo "$$a" | awk '{print $$1}') && iv=$$(echo "$$a" | awk '{print $$2}') && break; j=$$((j+1)); \
done; \
SHA=$$(docker manifest inspect $(BASE_IMAGE) | jq '.manifests[] | select(.platform.architecture == "'$$ia'") | if .platform | has("variant") then select(.platform.variant == "'$$iv'") else . end | .digest' -r); \
docker build -t $(IMAGE):$(ARCH)-$(VERSION) --build-arg FROM=$(BASE_IMAGE)@$$SHA --build-arg GOARCH=$(ARCH) .
@docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@

container-latest: .container-$(ARCH)-$(VERSION)
@docker tag $(IMAGE):$(ARCH)-$(VERSION) $(FULLY_QUALIFIED_IMAGE):$(ARCH)-latest
@echo "container: $(IMAGE):$(ARCH)-latest"

container-name:
@echo "container: $(IMAGE):$(ARCH)-$(VERSION)"

manifest: .manifest-$(VERSION) manifest-name
.manifest-$(VERSION): Dockerfile $(addprefix push-, $(ALL_ARCH))
@docker manifest create --amend $(FULLY_QUALIFIED_IMAGE):$(VERSION) $(addsuffix -$(VERSION), $(addprefix $(FULLY_QUALIFIED_IMAGE):, $(ALL_ARCH)))
@$(MAKE) --no-print-directory manifest-annotate-$(VERSION)
@docker manifest push $(FULLY_QUALIFIED_IMAGE):$(VERSION) > $@

manifest-latest: Dockerfile $(addprefix push-latest-, $(ALL_ARCH))
@docker manifest rm $(FULLY_QUALIFIED_IMAGE):latest || echo no old manifest
@docker manifest create --amend $(FULLY_QUALIFIED_IMAGE):latest $(addsuffix -latest, $(addprefix $(FULLY_QUALIFIED_IMAGE):, $(ALL_ARCH)))
@$(MAKE) --no-print-directory manifest-annotate-latest
@docker manifest push $(FULLY_QUALIFIED_IMAGE):latest
@echo "manifest: $(IMAGE):latest"

manifest-annotate: manifest-annotate-$(VERSION)

manifest-annotate-%:
@i=0; \
for a in $(ALL_ARCH); do \
annotate=; \
j=0; for da in $(DOCKER_ARCH); do \
if [ "$$j" -eq "$$i" ] && [ -n "$$da" ]; then \
annotate="docker manifest annotate $(FULLY_QUALIFIED_IMAGE):$* $(FULLY_QUALIFIED_IMAGE):$$a-$* --os linux --arch"; \
k=0; for ea in $$da; do \
[ "$$k" = 0 ] && annotate="$$annotate $$ea"; \
[ "$$k" != 0 ] && annotate="$$annotate --variant $$ea"; \
k=$$((k+1)); \
done; \
$$annotate; \
fi; \
j=$$((j+1)); \
done; \
i=$$((i+1)); \
done

manifest-name:
@echo "manifest: $(IMAGE):$(VERSION)"

push: .push-$(ARCH)-$(VERSION) push-name
.push-$(ARCH)-$(VERSION): .container-$(ARCH)-$(VERSION)
ifneq ($(REGISTRY),index.docker.io)
@docker tag $(IMAGE):$(ARCH)-$(VERSION) $(FULLY_QUALIFIED_IMAGE):$(ARCH)-$(VERSION)
endif
@docker push $(FULLY_QUALIFIED_IMAGE):$(ARCH)-$(VERSION)
@docker images -q $(IMAGE):$(ARCH)-$(VERSION) > $@

push-latest: container-latest
@docker push $(FULLY_QUALIFIED_IMAGE):$(ARCH)-latest
@echo "pushed: $(IMAGE):$(ARCH)-latest"

push-name:
@echo "pushed: $(IMAGE):$(ARCH)-$(VERSION)"

release: $(RELEASE_BINS)
$(RELEASE_BINS):
@make OS=$(word 2,$(subst -, ,$(@F))) ARCH=$(word 3,$(subst -, ,$(@F)))
mkdir -p $(@D)
cp bin/$(word 2,$(subst -, ,$(@F)))/$(word 3,$(subst -, ,$(@F)))/kgctl $@
container:
docker build -t $(FULLY_QUALIFIED_IMAGE):latest -f Dockerfile .

clean: container-clean bin-clean
rm -rf .cache
Expand Down

0 comments on commit fa71417

Please sign in to comment.