From f18752299dcd122df7f9dabb30398a55fef302b0 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sat, 30 Oct 2021 22:28:20 -0400 Subject: [PATCH 01/28] init --- Makefile | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0792771 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +SHELL := /bin/bash + +IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) +IMAGE_LATEST ?= $(shell cat IMAGE):latest +PWD ?= $(shell pwd) + +.PHONY: buildx-context +buildx-context: + docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64 + +.PHONY: buildx-clear +buildx-clear: + docker buildx rm arm64 + +.PHONY: build +build: + docker buildx build --load . -t $(IMAGE) + @docker buildx build --load . -t $(IMAGE_LATEST) + +.PHONY: push +push: + docker buildx build --platform linux/amd64 --push . -t $(IMAGE) + @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) + +.PHONY: run +run: + docker run -it -v $(PWD):/mc_data $(IMAGE) bash From 8a52a21a398f3bb2840e76e26f065a7963c79efa Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sun, 31 Oct 2021 15:03:59 -0400 Subject: [PATCH 02/28] Switch to multi-makefile strategy Instead of putting everything in one makefile switch to a folder called "make" with multiple makefiles. Move the original makefile to "docker.makefile" and add kaniko and truenas to fill in later. --- Makefile | 24 +++--------------------- make/docker.makefile | 26 ++++++++++++++++++++++++++ make/kaniko.makefile | 0 make/truenas.makefile | 0 4 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 make/docker.makefile create mode 100644 make/kaniko.makefile create mode 100644 make/truenas.makefile diff --git a/Makefile b/Makefile index 0792771..4bcb9cd 100644 --- a/Makefile +++ b/Makefile @@ -4,24 +4,6 @@ IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) IMAGE_LATEST ?= $(shell cat IMAGE):latest PWD ?= $(shell pwd) -.PHONY: buildx-context -buildx-context: - docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64 - -.PHONY: buildx-clear -buildx-clear: - docker buildx rm arm64 - -.PHONY: build -build: - docker buildx build --load . -t $(IMAGE) - @docker buildx build --load . -t $(IMAGE_LATEST) - -.PHONY: push -push: - docker buildx build --platform linux/amd64 --push . -t $(IMAGE) - @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) - -.PHONY: run -run: - docker run -it -v $(PWD):/mc_data $(IMAGE) bash +include make/docker.makefile +include make/kaniko.makefile +include make/truenas.makefile diff --git a/make/docker.makefile b/make/docker.makefile new file mode 100644 index 0000000..4af850f --- /dev/null +++ b/make/docker.makefile @@ -0,0 +1,26 @@ +.PHONY: docker-init +docker-init: + @touch VERSION + @touch IMAGE + +.PHONY: buildx-context +buildx-context: + docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64 + +.PHONY: buildx-clear +buildx-clear: + docker buildx rm arm64 + +.PHONY: build +build: + docker buildx build --load . -t $(IMAGE) + @docker buildx build --load . -t $(IMAGE_LATEST) + +.PHONY: push +push: + docker buildx build --platform linux/amd64 --push . -t $(IMAGE) + @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) + +.PHONY: run +run: + docker run -it -v $(PWD):/mc_data $(IMAGE) bash diff --git a/make/kaniko.makefile b/make/kaniko.makefile new file mode 100644 index 0000000..e69de29 diff --git a/make/truenas.makefile b/make/truenas.makefile new file mode 100644 index 0000000..e69de29 From 4146777f85d88627895d5cba013776e6696eca83 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sun, 31 Oct 2021 20:21:08 -0400 Subject: [PATCH 03/28] Add helm.makefile Add helm.makefile with a helm-release command to make a helm release. --- make/helm.makefile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 make/helm.makefile diff --git a/make/helm.makefile b/make/helm.makefile new file mode 100644 index 0000000..f603af4 --- /dev/null +++ b/make/helm.makefile @@ -0,0 +1,4 @@ +.PHONY: helm-release +helm-release: + @yq e ".version = \"$(shell cat VERSION)\"" -i helm/Chart.yaml + @yq e ".appVersion = \"$(shell cat VERSION)\"" -i helm/Chart.yaml From 3e8ca713580da108c8b44279542f7cfe4e754f4c Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sun, 31 Oct 2021 20:22:20 -0400 Subject: [PATCH 04/28] Add chart-release to truenas.makefile Add chart-release to add a subtree chart to the charts releases in the charts repo. --- make/truenas.makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/make/truenas.makefile b/make/truenas.makefile index e69de29..c6fb58c 100644 --- a/make/truenas.makefile +++ b/make/truenas.makefile @@ -0,0 +1,3 @@ +.PHONY: chart-release +chart-release: + @rsync -av $(CHART)/helm/ charts/$(CHART)/$(shell cat $(CHART)/VERSION)/ From 74a4a4e77f5fa40b486ae9b94a91e53b3ace5d65 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sun, 31 Oct 2021 20:33:47 -0400 Subject: [PATCH 05/28] Transition to .gitlab prefix Expect repo to be subtree'd as ".gitlab" --- Makefile | 7 ++++--- README.md | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/Makefile b/Makefile index 4bcb9cd..1575e0d 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) IMAGE_LATEST ?= $(shell cat IMAGE):latest PWD ?= $(shell pwd) -include make/docker.makefile -include make/kaniko.makefile -include make/truenas.makefile +include .gitlab/make/docker.makefile +include .gitlab/make/helm.makefile +include .gitlab/make/kaniko.makefile +include .gitlab/make/truenas.makefile diff --git a/README.md b/README.md new file mode 100644 index 0000000..1d084b1 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Adding the "common" subtree as your .gitlab folder + +```bash +# Add the subtree as a remote +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 +git subtree pull --prefix .gitlab common main +``` From ba12c923ba6644e8aadcc18b33feaacf61a8fb43 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sun, 31 Oct 2021 20:59:29 -0400 Subject: [PATCH 06/28] Remove docker-run Docker-run was only useful in very specific projects. Projects should either define their own "run" in their Makefile, add a docker-compose.yaml, or specify instructions in the README. --- make/docker.makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/make/docker.makefile b/make/docker.makefile index 4af850f..fc07142 100644 --- a/make/docker.makefile +++ b/make/docker.makefile @@ -20,7 +20,3 @@ build: push: docker buildx build --platform linux/amd64 --push . -t $(IMAGE) @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) - -.PHONY: run -run: - docker run -it -v $(PWD):/mc_data $(IMAGE) bash From da69418b0d0b2972dd8dd9d04b7e89a8b0b329b5 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Sun, 31 Oct 2021 22:56:47 -0400 Subject: [PATCH 07/28] Switch to url-based subtree with `make-update` Add new `make-update` make command to update the .gitlab subtree. --- Makefile | 6 ++++++ README.md | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1575e0d..d431a5e 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,9 @@ include .gitlab/make/docker.makefile include .gitlab/make/helm.makefile include .gitlab/make/kaniko.makefile include .gitlab/make/truenas.makefile + +.PHONY: make-update +make-update: + @git stash + @git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash + @git stash pop diff --git a/README.md b/README.md index 1d084b1..8aa1cbe 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ ```bash # Add the subtree as a remote -git remote add common git@gitlab.ducoterra.net:services/common.git -git subtree add --prefix .gitlab common main +git subtree add --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash # Now you can run the following to update -git subtree pull --prefix .gitlab common main +make make-update ``` From 66b4fdb902561f7e56b772a47662fe7337a35a2a Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 09:13:15 -0400 Subject: [PATCH 08/28] Ignore subtree pull failures Rather than potentially leaving the developer in a state where `git stash pop` wasn't run, ignore failures in git subtree and let the developer fix issues and re-run the command. This makes `make-update` more idempotent. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d431a5e..465cd3a 100644 --- a/Makefile +++ b/Makefile @@ -12,5 +12,5 @@ include .gitlab/make/truenas.makefile .PHONY: make-update make-update: @git stash - @git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash + -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash @git stash pop From 2f767593ef71ae7332321316aba45fc968d17d85 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 09:16:02 -0400 Subject: [PATCH 09/28] Add make-push command Add command to update the subtree from a child repo. This pushes to the main branch of the common repo with only the relevant commits. --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 465cd3a..cb8e27c 100644 --- a/Makefile +++ b/Makefile @@ -14,3 +14,10 @@ make-update: @git stash -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash @git stash pop + +.PHONY: make-push +make-push: + @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 From 6239af7f744aeca23db083fa122ef2679e16420e Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 09:21:43 -0400 Subject: [PATCH 10/28] Ignore git stash pop failures In the event the stash is empty, don't run stash pop. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cb8e27c..99b0031 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ include .gitlab/make/truenas.makefile make-update: @git stash -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash - @git stash pop + @if [-z "$(shell git stash list)"; then git stash pop; fi; .PHONY: make-push make-push: From afed93f58ab5fc8c7cdb649273885aac94c87a02 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 09:38:00 -0400 Subject: [PATCH 11/28] Add warning to make-update and make-push Add warning before make-update and make-push to alert developers that running the commands might be destructive. Allow cancelling the command up to 3 seconds before continuing. Also explain that merge conflicts warrant a re-run of the command. --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 99b0031..7cbfd02 100644 --- a/Makefile +++ b/Makefile @@ -9,14 +9,20 @@ include .gitlab/make/helm.makefile include .gitlab/make/kaniko.makefile include .gitlab/make/truenas.makefile +.PHONY: warning +warning: + @printf "Running a potentially destructive command. If a conflict occurs, fix the conflict and re-run the command.\n" + @printf "Cancel with ctrl + c within 3 seconds." + @sleep 3 + .PHONY: make-update -make-update: +make-update: warning @git stash -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash @if [-z "$(shell git stash list)"; then git stash pop; fi; .PHONY: make-push -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 From f81d846f310d3dbad1d8d8cd31b072bad540105c Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 09:56:37 -0400 Subject: [PATCH 12/28] Only pop stash if changes Only pop the stash if the most recent stash commit matches the STASH name. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7cbfd02..18e611b 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SHELL := /bin/bash IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) IMAGE_LATEST ?= $(shell cat IMAGE):latest PWD ?= $(shell pwd) +STASH ?= "common-update-stash" include .gitlab/make/docker.makefile include .gitlab/make/helm.makefile @@ -17,9 +18,9 @@ warning: .PHONY: make-update make-update: warning - @git stash + @git stash save $(STASH) -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash - @if [-z "$(shell git stash list)"; then git stash pop; fi; + @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash pop; fi .PHONY: make-push make-push: warning From 0f6eeb776eed393165e496673e645682834a08d8 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 10:01:12 -0400 Subject: [PATCH 13/28] Add make-stash-drop command Sometimes you can get stuck in a loop where git stash pop preserves the stash commit. Dropping that commit if it's a STASH commit after an update is totally fine. --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 18e611b..02f380c 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,10 @@ warning: @printf "Cancel with ctrl + c within 3 seconds." @sleep 3 +.PHONY: make-stash-drop +make-stash-drop: + @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash drop; fi + .PHONY: make-update make-update: warning @git stash save $(STASH) From 22a952dd53cc97522d5f0d7826c028acf03413a8 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 10:02:35 -0400 Subject: [PATCH 14/28] Remove warning from make-update make-update isn't as destructive as it once was. It should be safe to run as long as the developer is fixes any weird merge conflicts after stash pop. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 02f380c..320f9d4 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ make-stash-drop: @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash drop; fi .PHONY: make-update -make-update: warning +make-update: @git stash save $(STASH) -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash pop; fi From b07a2c095b55d758ed5fa89b53d7c559b3e8fc9c Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 10:05:43 -0400 Subject: [PATCH 15/28] Run update after make-push To close things out we should re-run make-update to ensure changes are pulled back into the repo we updated from. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 320f9d4..61a7dbb 100644 --- a/Makefile +++ b/Makefile @@ -32,3 +32,4 @@ make-push: warning @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 From 9eed50962cbd9bec25da3a82908d0d691eacb759 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Mon, 1 Nov 2021 20:32:27 -0400 Subject: [PATCH 16/28] Don't squash on pull Don't squash updates on pull --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 61a7dbb..4eb7ed6 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,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 --squash + -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 .PHONY: make-push From d181d452e866acba9241707373db23b7e98cafee Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:05:01 -0400 Subject: [PATCH 17/28] Overhaul for get-server v. 2.0.0 Since get-server downloads its own jarfile this commit overhauls a lot of the minecraft deploy to match the new strategy. It also updates the README and adds makefile targets for a few new commands. --- .gitignore | 3 ++- Makefile | 28 +++++-------------- README.md | 55 ++++++++++---------------------------- helm/templates/deploy.yaml | 7 ----- helm/values.yaml | 2 +- 5 files changed, 24 insertions(+), 71 deletions(-) diff --git a/.gitignore b/.gitignore index adbb97d..fe29ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data/ \ No newline at end of file +data/ +world/ diff --git a/Makefile b/Makefile index 0792771..996a6d2 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,13 @@ SHELL := /bin/bash -IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) -IMAGE_LATEST ?= $(shell cat IMAGE):latest -PWD ?= $(shell pwd) +include .gitlab/Makefile -.PHONY: buildx-context -buildx-context: - docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64 - -.PHONY: buildx-clear -buildx-clear: - docker buildx rm arm64 - -.PHONY: build -build: - docker buildx build --load . -t $(IMAGE) - @docker buildx build --load . -t $(IMAGE_LATEST) - -.PHONY: push -push: - docker buildx build --platform linux/amd64 --push . -t $(IMAGE) - @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) +.PHONY: get-server +get-server: + @mkdir -p world + @echo 'eula=true' > world/eula.txt + @docker run -it -e SERVER_VERSION=1.17.1 -v $(PWD)/world:/downloads ducoterra/get-minecraft:latest .PHONY: run run: - docker run -it -v $(PWD):/mc_data $(IMAGE) bash + docker-compose run --service-ports minecraft diff --git a/README.md b/README.md index 7249982..81bb2a4 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,34 @@ # Minecraft -## Getting server.jar - -![Click Installations](img/main.png) -![Select the Options Menu](img/menu.png) -![Click Edit](img/edit.png) -![Click Download Server](img/server.png) - ## Running Locally ```bash -docker-compose build minecraft -docker-compose up minecraft +# download the most recent version of minecraft +make get-server + +# Run the server +docker-compose up ``` ## Uploading to Docker Hub -In docker-compose.yaml, update the image tag to: +1. Update the version in the VERSION file. +2. Build and push the new version -```yaml -... -services: - minecraft: - build: . - image: /minecraft:-1 - ports: -... -``` - -then run - -```bash -docker-compose push -``` + ```bash + make build + make push + ``` ## Running in kubernetes -In k8s/deploy.yaml, edit the deploy - -```yaml -... - spec: - containers: - - name: minecraft - image: - ports: -... -``` - -Then run the following +Requires helm v3. Edit values.yaml and run the following: ```bash -kubectl apply -f k8s/pvc -kubectl apply -f k8s +helm upgrade --install minecraft ``` -Your minecraft server will be available on port 25565 +Your minecraft server will be available on port 25565 by default. ## Create a Backup diff --git a/helm/templates/deploy.yaml b/helm/templates/deploy.yaml index e6a0c7e..a5872ad 100644 --- a/helm/templates/deploy.yaml +++ b/helm/templates/deploy.yaml @@ -23,13 +23,6 @@ spec: volumeMounts: - mountPath: /downloads name: data - - name: download-server - image: {{ .Values.get_server.image }} - imagePullPolicy: Always - command: ["bash", "-c", "curl -o server.jar $(cat SERVER_VERSION)"] - volumeMounts: - - mountPath: /downloads - name: data containers: - name: {{ .Release.Name }} image: {{ .Values.image }} diff --git a/helm/values.yaml b/helm/values.yaml index 01943f6..bb1d9ab 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -1,6 +1,6 @@ image: ducoterra/minecraft:latest get_server: - image: ducoterra/get-minecraft:latest + image: ducoterra/get-minecraft:2.0.0 server_version: "1.17.1" port: 20101 max_cpu: 4 From 65b3a84e963126be6d8cdcc2df5b4f6ac48c8a3b Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:07:50 -0400 Subject: [PATCH 18/28] make subtree "split" overhaul In order to create cleaner histories we should be using subtree split and push in order to preview the changes as an MR before pushing to main. --- .gitlab/Makefile | 36 +++++++++++++++++++++++++++++++++++ .gitlab/README.md | 9 +++++++++ .gitlab/make/docker.makefile | 29 ++++++++++++++++++++++++++++ .gitlab/make/git.makefile | 5 +++++ .gitlab/make/helm.makefile | 4 ++++ .gitlab/make/kaniko.makefile | 0 .gitlab/make/truenas.makefile | 3 +++ 7 files changed, 86 insertions(+) create mode 100644 .gitlab/Makefile create mode 100644 .gitlab/README.md create mode 100644 .gitlab/make/docker.makefile create mode 100644 .gitlab/make/git.makefile create mode 100644 .gitlab/make/helm.makefile create mode 100644 .gitlab/make/kaniko.makefile create mode 100644 .gitlab/make/truenas.makefile diff --git a/.gitlab/Makefile b/.gitlab/Makefile new file mode 100644 index 0000000..75a6988 --- /dev/null +++ b/.gitlab/Makefile @@ -0,0 +1,36 @@ +SHELL := /bin/bash + +VERSION ?= $(shell cat VERSION) +IMAGE ?= $(shell cat IMAGE):$(VERSION) +IMAGE_LATEST ?= $(shell cat IMAGE):latest +PWD ?= $(shell pwd) +STASH ?= "common-update-stash" + +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: + @printf "Running a potentially destructive command. If a conflict occurs, fix the conflict and re-run the command.\n" + @printf "Cancel with ctrl + c within 3 seconds." + @sleep 3 + +.PHONY: make-stash-drop +make-stash-drop: + @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash drop; fi + +.PHONY: make-update +make-update: + -git remote add common git@gitlab.ducoterra.net:services/common.git + -git subtree pull --prefix .gitlab --message "Merge update from Common" -q git@gitlab.ducoterra.net:services/common.git main + +.PHONY: make-push +make-push: warning + @make make-update + @git remote add common git@gitlab.ducoterra.net:services/common.git + @git subtree split --branch common-minecraft --prefix .gitlab + @git subtree push --prefix .gitlab common main + @git remote remove common diff --git a/.gitlab/README.md b/.gitlab/README.md new file mode 100644 index 0000000..8aa1cbe --- /dev/null +++ b/.gitlab/README.md @@ -0,0 +1,9 @@ +# Adding the "common" subtree as your .gitlab folder + +```bash +# Add the subtree as a remote +git subtree add --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash + +# Now you can run the following to update +make make-update +``` diff --git a/.gitlab/make/docker.makefile b/.gitlab/make/docker.makefile new file mode 100644 index 0000000..23e4a52 --- /dev/null +++ b/.gitlab/make/docker.makefile @@ -0,0 +1,29 @@ +.PHONY: docker-init +docker-init: + @touch VERSION + @touch IMAGE + +.PHONY: buildx-context +buildx-context: + docker buildx create --name container-builder --use --platform linux/amd64,linux/arm64 + +.PHONY: buildx-clear +buildx-clear: + docker buildx rm container-builder + +.PHONY: build +build: + docker buildx build --load . -t $(IMAGE) + @docker buildx build --load . -t $(IMAGE_LATEST) + +.PHONY: push +push: + -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) + +.PHONY: docker-release +docker-release: + @yq e ".services.minecraft.image = \"$(IMAGE)\"" -i docker-compose.yaml + @make push diff --git a/.gitlab/make/git.makefile b/.gitlab/make/git.makefile new file mode 100644 index 0000000..f80a243 --- /dev/null +++ b/.gitlab/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) diff --git a/.gitlab/make/helm.makefile b/.gitlab/make/helm.makefile new file mode 100644 index 0000000..f603af4 --- /dev/null +++ b/.gitlab/make/helm.makefile @@ -0,0 +1,4 @@ +.PHONY: helm-release +helm-release: + @yq e ".version = \"$(shell cat VERSION)\"" -i helm/Chart.yaml + @yq e ".appVersion = \"$(shell cat VERSION)\"" -i helm/Chart.yaml diff --git a/.gitlab/make/kaniko.makefile b/.gitlab/make/kaniko.makefile new file mode 100644 index 0000000..e69de29 diff --git a/.gitlab/make/truenas.makefile b/.gitlab/make/truenas.makefile new file mode 100644 index 0000000..c6fb58c --- /dev/null +++ b/.gitlab/make/truenas.makefile @@ -0,0 +1,3 @@ +.PHONY: chart-release +chart-release: + @rsync -av $(CHART)/helm/ charts/$(CHART)/$(shell cat $(CHART)/VERSION)/ From a5aa0cacbe9d4b28864c16c03e93c02df41ac967 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:08:38 -0400 Subject: [PATCH 19/28] Automated release for version 1.0.2 --- VERSION | 2 +- docker-compose.yaml | 13 +++++++++++++ helm/Chart.yaml | 7 ++----- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 docker-compose.yaml diff --git a/VERSION b/VERSION index 3eefcb9..6d7de6e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.2 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..527768a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,13 @@ +version: '3' +services: + minecraft: + image: ducoterra/minecraft:1.0.2 + stdin_open: true + tty: true + volumes: + - ./world:/mc_data + ports: + - 25565:25565 + environment: + - MAX_RAM=1 + - MIN_RAM=1 diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 6e2f7cd..f83145a 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -1,7 +1,6 @@ apiVersion: v2 name: minecraft description: A Minecraft server for kubernetes - # A chart can be either an 'application' or a 'library' chart. # # Application charts are a collection of templates that can be packaged into versioned archives @@ -11,13 +10,11 @@ description: A Minecraft server for kubernetes # a dependency of application charts to inject those utilities and functions into the rendering # pipeline. Library charts do not define any templates and therefore cannot be deployed. type: application - # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.1.0 - +version: 1.0.2 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: 1.0.0 +appVersion: 1.0.2 From 5e2bc5f8724642ff5335bb4c0b93a471ecb26162 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 10:19:21 -0400 Subject: [PATCH 20/28] 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 21/28] 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 22/28] 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 23/28] 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 24/28] 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 25/28] 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 26/28] 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 27/28] 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) From 422f4d49bd437ae15d2a34303be12cecf99d5860 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:59:08 -0400 Subject: [PATCH 28/28] remove .gitlab subtree --- .gitlab/Makefile | 36 ----------------------------------- .gitlab/README.md | 9 --------- .gitlab/make/docker.makefile | 29 ---------------------------- .gitlab/make/git.makefile | 5 ----- .gitlab/make/helm.makefile | 4 ---- .gitlab/make/kaniko.makefile | 0 .gitlab/make/truenas.makefile | 3 --- 7 files changed, 86 deletions(-) delete mode 100644 .gitlab/Makefile delete mode 100644 .gitlab/README.md delete mode 100644 .gitlab/make/docker.makefile delete mode 100644 .gitlab/make/git.makefile delete mode 100644 .gitlab/make/helm.makefile delete mode 100644 .gitlab/make/kaniko.makefile delete mode 100644 .gitlab/make/truenas.makefile diff --git a/.gitlab/Makefile b/.gitlab/Makefile deleted file mode 100644 index 75a6988..0000000 --- a/.gitlab/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -SHELL := /bin/bash - -VERSION ?= $(shell cat VERSION) -IMAGE ?= $(shell cat IMAGE):$(VERSION) -IMAGE_LATEST ?= $(shell cat IMAGE):latest -PWD ?= $(shell pwd) -STASH ?= "common-update-stash" - -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: - @printf "Running a potentially destructive command. If a conflict occurs, fix the conflict and re-run the command.\n" - @printf "Cancel with ctrl + c within 3 seconds." - @sleep 3 - -.PHONY: make-stash-drop -make-stash-drop: - @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash drop; fi - -.PHONY: make-update -make-update: - -git remote add common git@gitlab.ducoterra.net:services/common.git - -git subtree pull --prefix .gitlab --message "Merge update from Common" -q git@gitlab.ducoterra.net:services/common.git main - -.PHONY: make-push -make-push: warning - @make make-update - @git remote add common git@gitlab.ducoterra.net:services/common.git - @git subtree split --branch common-minecraft --prefix .gitlab - @git subtree push --prefix .gitlab common main - @git remote remove common diff --git a/.gitlab/README.md b/.gitlab/README.md deleted file mode 100644 index 8aa1cbe..0000000 --- a/.gitlab/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Adding the "common" subtree as your .gitlab folder - -```bash -# Add the subtree as a remote -git subtree add --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash - -# Now you can run the following to update -make make-update -``` diff --git a/.gitlab/make/docker.makefile b/.gitlab/make/docker.makefile deleted file mode 100644 index 23e4a52..0000000 --- a/.gitlab/make/docker.makefile +++ /dev/null @@ -1,29 +0,0 @@ -.PHONY: docker-init -docker-init: - @touch VERSION - @touch IMAGE - -.PHONY: buildx-context -buildx-context: - docker buildx create --name container-builder --use --platform linux/amd64,linux/arm64 - -.PHONY: buildx-clear -buildx-clear: - docker buildx rm container-builder - -.PHONY: build -build: - docker buildx build --load . -t $(IMAGE) - @docker buildx build --load . -t $(IMAGE_LATEST) - -.PHONY: push -push: - -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) - -.PHONY: docker-release -docker-release: - @yq e ".services.minecraft.image = \"$(IMAGE)\"" -i docker-compose.yaml - @make push diff --git a/.gitlab/make/git.makefile b/.gitlab/make/git.makefile deleted file mode 100644 index f80a243..0000000 --- a/.gitlab/make/git.makefile +++ /dev/null @@ -1,5 +0,0 @@ -.PHONY: git-release -git-release: - @git add . - @git commit -m "Automated release for version $(VERSION)" - @git tag $(VERSION) diff --git a/.gitlab/make/helm.makefile b/.gitlab/make/helm.makefile deleted file mode 100644 index f603af4..0000000 --- a/.gitlab/make/helm.makefile +++ /dev/null @@ -1,4 +0,0 @@ -.PHONY: helm-release -helm-release: - @yq e ".version = \"$(shell cat VERSION)\"" -i helm/Chart.yaml - @yq e ".appVersion = \"$(shell cat VERSION)\"" -i helm/Chart.yaml diff --git a/.gitlab/make/kaniko.makefile b/.gitlab/make/kaniko.makefile deleted file mode 100644 index e69de29..0000000 diff --git a/.gitlab/make/truenas.makefile b/.gitlab/make/truenas.makefile deleted file mode 100644 index c6fb58c..0000000 --- a/.gitlab/make/truenas.makefile +++ /dev/null @@ -1,3 +0,0 @@ -.PHONY: chart-release -chart-release: - @rsync -av $(CHART)/helm/ charts/$(CHART)/$(shell cat $(CHART)/VERSION)/