Makefile
157 Zeilen · 5.2 KB · Makefile
| 1 | .PHONY: serve serve-dev generate build build-native build-macos build-linux \ |
| 2 | build-raspberry build-windows checksums new-theme clean \ |
| 3 | docker-images docker-static docker-run |
| 4 | |
| 5 | GIT := $(shell git pull --quiet 2>/dev/null || true) |
| 6 | LATEST_TAG := $(shell git tag --sort=-version:refname | head -n 1) |
| 7 | |
| 8 | tag: |
| 9 | @echo "Latest tag: $(LATEST_TAG)" |
| 10 | |
| 11 | serve: |
| 12 | go run . serve |
| 13 | |
| 14 | # Server mit Template-Live-Reload (Theme-Entwicklung), optional: make serve-dev THEME=newdesign |
| 15 | serve-dev: |
| 16 | go run . serve -dev $(if $(THEME),-theme $(THEME)) |
| 17 | |
| 18 | generate: |
| 19 | go run . generate |
| 20 | |
| 21 | # --------------------------------------------------------------------------- |
| 22 | # Builds |
| 23 | # |
| 24 | # Alle Binaries landen in $(DIST)/ und heissen quilldrop-<os>-<arch>[v<arm>]. |
| 25 | # Einzelne Ziele: make build-linux, build-macos, build-windows, build-raspberry |
| 26 | # --------------------------------------------------------------------------- |
| 27 | |
| 28 | BINARY_NAME := quilldrop |
| 29 | DIST := dist |
| 30 | GOFLAGS_REL := -trimpath -ldflags=-s\ -w |
| 31 | |
| 32 | # $(call go_build,GOOS,GOARCH[,GOARM][,Kommentar]) |
| 33 | define go_build |
| 34 | @mkdir -p $(DIST) |
| 35 | @echo " -> $(1)/$(2)$(if $(3),v$(3))$(if $(4), [$(4)])" |
| 36 | @GOOS=$(1) GOARCH=$(2) GOARM=$(3) CGO_ENABLED=0 \ |
| 37 | go build $(GOFLAGS_REL) \ |
| 38 | -o $(DIST)/$(BINARY_NAME)-$(1)-$(2)$(if $(3),v$(3))$(if $(filter windows,$(1)),.exe) . |
| 39 | endef |
| 40 | |
| 41 | # Alle Plattformen |
| 42 | build: build-macos build-linux build-windows checksums |
| 43 | @echo "" |
| 44 | @ls -1 $(DIST) |
| 45 | |
| 46 | # Nur fuer die aktuelle Maschine -> ./quilldrop |
| 47 | build-native: |
| 48 | CGO_ENABLED=0 go build $(GOFLAGS_REL) -o $(BINARY_NAME) . |
| 49 | |
| 50 | build-macos: |
| 51 | @echo "macOS:" |
| 52 | $(call go_build,darwin,amd64,,Intel) |
| 53 | $(call go_build,darwin,arm64,,Apple Silicon M1-M4) |
| 54 | |
| 55 | build-linux: |
| 56 | @echo "Linux:" |
| 57 | $(call go_build,linux,amd64,,x86_64) |
| 58 | $(call go_build,linux,386,,x86 32-bit) |
| 59 | $(call go_build,linux,arm64,,ARM 64-bit) |
| 60 | $(call go_build,linux,arm,7,ARMv7 32-bit) |
| 61 | $(call go_build,linux,arm,6,ARMv6 32-bit) |
| 62 | |
| 63 | # Raspberry Pi (Teilmenge von build-linux, zum separaten Bauen) |
| 64 | # armv6 : Pi 1, Pi Zero / Zero W, CM1 |
| 65 | # armv7 : Pi 2 und Pi 3/4/5 mit 32-bit OS |
| 66 | # arm64 : Pi 3/4/5, Pi Zero 2 W, CM3/CM4/CM5 mit 64-bit OS (Raspberry Pi OS 64-bit) |
| 67 | build-raspberry: |
| 68 | @echo "Raspberry Pi:" |
| 69 | $(call go_build,linux,arm,6,Pi 1 / Zero / Zero W / CM1) |
| 70 | $(call go_build,linux,arm,7,Pi 2 / Pi 3-5 mit 32-bit OS) |
| 71 | $(call go_build,linux,arm64,,Pi 3-5 / Zero 2 W / CM3-CM5 mit 64-bit OS) |
| 72 | |
| 73 | build-windows: |
| 74 | @echo "Windows:" |
| 75 | $(call go_build,windows,amd64,,x86_64) |
| 76 | $(call go_build,windows,386,,x86 32-bit) |
| 77 | $(call go_build,windows,arm64,,ARM 64-bit) |
| 78 | |
| 79 | # SHA256-Summen ueber alle gebauten Binaries |
| 80 | checksums: |
| 81 | @cd $(DIST) && \ |
| 82 | if command -v sha256sum >/dev/null 2>&1; then \ |
| 83 | sha256sum $(BINARY_NAME)-* > checksums.txt; \ |
| 84 | else \ |
| 85 | shasum -a 256 $(BINARY_NAME)-* > checksums.txt; \ |
| 86 | fi |
| 87 | @echo "Checksums: $(DIST)/checksums.txt" |
| 88 | |
| 89 | commit-build: |
| 90 | @echo "Commit build: $(GIT)" |
| 91 | @git add dist |
| 92 | @git commit -m "Commit binaries for" || true |
| 93 | @git push |
| 94 | |
| 95 | # Copy the default theme: make new-theme NAME=newdesign |
| 96 | new-theme: |
| 97 | @test -n "$(NAME)" || { echo "Usage: make new-theme NAME=<theme>"; exit 1; } |
| 98 | @test ! -d themes/$(NAME) || { echo "themes/$(NAME) already exists"; exit 1; } |
| 99 | cp -r themes/default themes/$(NAME) |
| 100 | @echo "Created themes/$(NAME) — activate with 'theme: $(NAME)' in config.yaml or 'go run . serve -theme $(NAME)'" |
| 101 | |
| 102 | docker-static: |
| 103 | podman build --platform linux/arm64 -t quilldrop -f ./Dockerfile-static . |
| 104 | |
| 105 | docker-images: |
| 106 | @echo "Building for tag: $(LATEST_TAG)" |
| 107 | @echo "Building AMD64..." |
| 108 | podman build --platform linux/amd64 \ |
| 109 | -t ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images-amd64 \ |
| 110 | -f ./Dockerfile-images . |
| 111 | @echo "Building ARM64..." |
| 112 | podman build --platform linux/arm64 \ |
| 113 | -t ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images-arm64 \ |
| 114 | -f ./Dockerfile-images . |
| 115 | @echo "Creating manifest..." |
| 116 | podman manifest rm ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images 2>/dev/null || true |
| 117 | podman manifest create ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images |
| 118 | @echo "Adding AMD64 to manifest..." |
| 119 | podman manifest add ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images \ |
| 120 | ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images-amd64 |
| 121 | @echo "Adding ARM64 to manifest..." |
| 122 | podman manifest add ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images \ |
| 123 | ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images-arm64 |
| 124 | @echo "Inspecting manifest:" |
| 125 | podman manifest inspect ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images |
| 126 | @echo "Pushing manifest:" |
| 127 | podman manifest push --all ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images |
| 128 | # docker-images: |
| 129 | # $(eval LATEST_TAG := $(shell git tag --sort=-version:refname | head -n 1)) |
| 130 | # podman build --platform linux/amd64,linux/arm64 \ |
| 131 | # --manifest ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images \ |
| 132 | # -f ./Dockerfile-images . |
| 133 | # podman manifest push --all ghcr.io/9it-full-service/quilldrop:$(LATEST_TAG)-images |
| 134 | |
| 135 | docker-run: |
| 136 | podman run --rm -i -p 8081:80 quilldrop:latest |
| 137 | |
| 138 | test: |
| 139 | go test ./... |
| 140 | |
| 141 | clean: |
| 142 | rm -rf bin/ $(DIST)/ $(BINARY_NAME) |
| 143 | |
| 144 | docker-up: |
| 145 | docker compose up -d |
| 146 | |
| 147 | docker-down: |
| 148 | docker compose down |
| 149 | |
| 150 | generate-keys: |
| 151 | @mkdir -p keys |
| 152 | openssl genrsa -out keys/private.pem 2048 |
| 153 | openssl rsa -in keys/private.pem -pubout -out keys/public.pem |
| 154 | @echo "RSA key pair generated in keys/" |
| 155 | |
| 156 | migrate: |
| 157 | go run ./cmd/migrate |