From 5e2bc5f8724642ff5335bb4c0b93a471ecb26162 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:19:21 -0400 Subject: [PATCH 1/8] Switch to container-builder buildx platform Continue using buildx with a new container builder name "container-builder". --- make/docker.makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/make/docker.makefile b/make/docker.makefile index fc07142..dc77c21 100644 --- a/make/docker.makefile +++ b/make/docker.makefile @@ -5,16 +5,16 @@ docker-init: .PHONY: buildx-context buildx-context: - docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64 + docker buildx create --name container-builder --use --platform linux/amd64,linux/arm64 .PHONY: buildx-clear buildx-clear: - docker buildx rm arm64 + docker buildx rm container-builder .PHONY: build build: docker buildx build --load . -t $(IMAGE) - @docker buildx build --load . -t $(IMAGE_LATEST) + @docker buildx build --load . -t $(IMAGE_LATEST) .PHONY: push push: From 40a217b585f0ea9727ae7e3df3f9b0f7f1f6d5ea Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:22:48 -0400 Subject: [PATCH 2/8] Use buildx to create multi-arch images clear and set the buildx context on push. Then use --push with buildx build to push the multi-arch images immediately after creating them. This gets around the need to store them locally (which won't work for something like an M1 mac). --- make/docker.makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/make/docker.makefile b/make/docker.makefile index dc77c21..2c40944 100644 --- a/make/docker.makefile +++ b/make/docker.makefile @@ -18,5 +18,7 @@ build: .PHONY: push push: - docker buildx build --platform linux/amd64 --push . -t $(IMAGE) - @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) + -make buildx-clear + @make buildx-context + docker buildx build --platform linux/amd64,linux/arm64 --push . -t $(IMAGE) + @docker buildx build --platform linux/amd64,linux/arm64 --push . -t $(IMAGE_LATEST) From 3563c5c2aa0100574f505b7dda324b5a52ea34cf Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:23:53 -0400 Subject: [PATCH 3/8] Add make docker-release Add docker-release command which updates the image tag in the docker-compose.yaml and runs a `make push`. --- make/docker.makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/make/docker.makefile b/make/docker.makefile index 2c40944..23e4a52 100644 --- a/make/docker.makefile +++ b/make/docker.makefile @@ -22,3 +22,8 @@ push: @make buildx-context docker buildx build --platform linux/amd64,linux/arm64 --push . -t $(IMAGE) @docker buildx build --platform linux/amd64,linux/arm64 --push . -t $(IMAGE_LATEST) + +.PHONY: docker-release +docker-release: + @yq e ".services.minecraft.image = \"$(IMAGE)\"" -i docker-compose.yaml + @make push From a6053ed3f04109b80859716cdc4c945626ed4bcb Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:25:18 -0400 Subject: [PATCH 4/8] Add make git-release Add command which makes an automated release from the VERSION file. Commits and tags everything not staged in the repo. --- Makefile | 1 + make/git.makefile | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 make/git.makefile diff --git a/Makefile b/Makefile index 4eb7ed6..9e0bcbf 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ include .gitlab/make/docker.makefile include .gitlab/make/helm.makefile include .gitlab/make/kaniko.makefile include .gitlab/make/truenas.makefile +include .gitlab/make/git.makefile .PHONY: warning warning: diff --git a/make/git.makefile b/make/git.makefile new file mode 100644 index 0000000..f80a243 --- /dev/null +++ b/make/git.makefile @@ -0,0 +1,5 @@ +.PHONY: git-release +git-release: + @git add . + @git commit -m "Automated release for version $(VERSION)" + @git tag $(VERSION) From 9d0c9c63880561fccd3368ba32d7157d197f20e7 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:45:57 -0400 Subject: [PATCH 5/8] Update README with "common" remote Add instructions for adding subtree using a remote called "common". You need the remote to properly contribute back upstream from a child project. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8aa1cbe..aa433cb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ ```bash # Add the subtree as a remote -git subtree add --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash +git remote add common git@gitlab.ducoterra.net:services/common.git +git subtree add --prefix .gitlab common main # Now you can run the following to update make make-update From d86b5052a8c5947bbd7bb6ca47128bc0d54b571c Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:46:53 -0400 Subject: [PATCH 6/8] Add PROJECT_NAME and VERSION Add PROJECT_NAME and VERSION variables to Makefile. --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4eb7ed6..d504165 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ SHELL := /bin/bash -IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) +PROJECT_NAME ?= $(shell git config --local remote.origin.url|sed -n 's#.*/\([^.]*\)\.git#\1#p') +VERSION ?= $(shell cat VERSION) +IMAGE ?= $(shell cat IMAGE):$(VERSION) IMAGE_LATEST ?= $(shell cat IMAGE):latest PWD ?= $(shell pwd) STASH ?= "common-update-stash" From 3c91292feac91a14185bd2fca8b5981412d2903b Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:47:29 -0400 Subject: [PATCH 7/8] Make user stash their own damn changes Stashing is so annoying to deal with in a scripted way. Just force the user to stash their own changes. Only subtree pull if it's possible. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d504165..6e1f49f 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,7 @@ make-stash-drop: .PHONY: make-update make-update: - @git stash save $(STASH) - -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main - @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash pop; fi + @git subtree pull --prefix .gitlab --message "Merge update from Common" -q common main .PHONY: make-push make-push: warning From c3e6d733c669cfa97f383ee00fd1479f1f65371f Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:48:15 -0400 Subject: [PATCH 8/8] Switch to "subtree split" push strategy Split the subtree into a new branch before pushing to common. This creates a new branch automatically and ensures no weird histories get committed to common. --- Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 6e1f49f..20a9590 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,5 @@ make-update: .PHONY: make-push make-push: warning @make make-update - @git remote add common git@gitlab.ducoterra.net:services/common.git - @git subtree push --prefix .gitlab common main - @git remote remove common - @make make-update + @git subtree split --branch common/$(PROJECT_NAME) --prefix .gitlab + @git push common common/$(PROJECT_NAME):common/$(PROJECT_NAME)