A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory

playing with spindle

+190 -33
+2 -1
.gitignore
··· 1 1 .DS_Store 2 2 /plcbundle 3 - plc_bundles.json 3 + plc_bundles.json 4 + dist
+36
.goreleaser.yml
··· 1 + version: 2 2 + 3 + project_name: plcbundle 4 + 5 + before: 6 + hooks: 7 + - go mod tidy 8 + - go test ./... 9 + 10 + builds: 11 + - id: plcbundle 12 + main: ./cmd/plcbundle 13 + binary: plcbundle 14 + env: 15 + - CGO_ENABLED=1 16 + # Only build for current platform locally 17 + goos: 18 + - darwin 19 + goarch: 20 + - arm64 21 + ldflags: 22 + - -s -w 23 + - -X main.version={{.Version}} 24 + - -X main.gitCommit={{.ShortCommit}} 25 + - -X main.buildDate={{.Date}} 26 + 27 + archives: 28 + - formats: ["tar.gz"] 29 + name_template: >- 30 + {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }} 31 + 32 + checksum: 33 + name_template: 'checksums.txt' 34 + 35 + release: 36 + disable: true
+33
.tangled/workflows/build.yml
··· 1 + # Build workflow - test compilation on pull requests 2 + 3 + when: 4 + - event: ["push", "pull_request"] 5 + branch: ["main", "develop"] 6 + 7 + engine: "nixery" 8 + 9 + dependencies: 10 + nixpkgs: 11 + - go 12 + - goreleaser 13 + 14 + environment: 15 + CGO_ENABLED: "0" 16 + 17 + steps: 18 + - name: "Download dependencies" 19 + command: | 20 + go mod download 21 + go mod verify 22 + 23 + - name: "Run tests" 24 + command: | 25 + go test -v ./... 26 + 27 + - name: "Build snapshot (test cross-compilation)" 28 + command: | 29 + goreleaser build --snapshot --clean 30 + 31 + - name: "Show artifacts" 32 + command: | 33 + ls -lh dist/
+37
.tangled/workflows/release.yml
··· 1 + when: 2 + - event: ["manual"] 3 + branch: ["main"] 4 + 5 + engine: "nixery" 6 + 7 + clone: 8 + depth: 0 9 + 10 + dependencies: 11 + nixpkgs: 12 + - go 13 + - gcc 14 + - gnumake 15 + - zstd 16 + - git 17 + 18 + steps: 19 + - name: "Build Linux binaries (native with CGO)" 20 + command: | 21 + # Build for current platform (Linux) 22 + CGO_ENABLED=1 go build \ 23 + -ldflags="-s -w -X main.version=$(git describe --tags --always) -X main.gitCommit=$(git rev-parse --short HEAD)" \ 24 + -o dist/plcbundle_linux_amd64/plcbundle \ 25 + ./cmd/plcbundle 26 + 27 + echo "✓ Linux binary built:" 28 + ls -lh dist/plcbundle_linux_amd64/plcbundle 29 + 30 + - name: "Create archive" 31 + command: | 32 + cd dist 33 + tar -czf plcbundle_$(git describe --tags)_linux_amd64.tar.gz plcbundle_linux_amd64/ 34 + sha256sum *.tar.gz > checksums.txt 35 + 36 + echo "✓ Artifacts:" 37 + ls -lh *.tar.gz checksums.txt
+19
Dockerfile.goreleaser
··· 1 + # syntax=docker/dockerfile:1 2 + 3 + FROM alpine:3.19 4 + 5 + RUN apk add --no-cache ca-certificates zstd-libs 6 + 7 + RUN addgroup -g 1000 plcbundle && \ 8 + adduser -D -u 1000 -G plcbundle plcbundle && \ 9 + mkdir -p /data && \ 10 + chown plcbundle:plcbundle /data 11 + 12 + # GoReleaser puts binaries in $TARGETPLATFORM/ 13 + ARG TARGETPLATFORM 14 + COPY ${TARGETPLATFORM}/plcbundle /usr/local/bin/plcbundle 15 + 16 + WORKDIR /data 17 + USER plcbundle 18 + 19 + ENTRYPOINT ["plcbundle"]
+63 -32
Makefile
··· 1 - .PHONY: all build install test clean fmt lint help version bump-patch bump-minor bump-major release 2 - .PHONY: docker-build docker-push docker-run docker-clean docker-shell compose-up compose-down compose-logs 1 + .PHONY: all build install test clean fmt lint help version bump-patch bump-minor bump-major release release-build 2 + .PHONY: docker-build docker-buildx docker-push docker-run docker-clean docker-shell compose-up compose-down compose-logs 3 3 4 4 # Binary name 5 5 BINARY_NAME=plcbundle ··· 8 8 # Docker configuration 9 9 DOCKER_IMAGE=plcbundle 10 10 DOCKER_TAG=$(VERSION) 11 - DOCKER_REGISTRY=atscan 11 + DOCKER_REGISTRY?=atscan 12 12 DOCKER_FULL_IMAGE=$(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)$(DOCKER_IMAGE):$(DOCKER_TAG) 13 13 DOCKER_LATEST=$(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)$(DOCKER_IMAGE):latest 14 + DOCKER_PLATFORMS?=linux/amd64,linux/arm64 14 15 15 16 # Version information 16 17 VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") ··· 58 59 @echo "Cleaning..." 59 60 $(GOCLEAN) 60 61 rm -f $(BINARY_NAME) 62 + rm -rf dist/ 61 63 62 64 # Format code 63 65 fmt: ··· 96 98 @echo "Bumping major version..." 97 99 @./scripts/bump-version.sh major 98 100 99 - # Create a release (tags and pushes) 101 + # Build release binaries with GoReleaser (local test) 102 + release-build: 103 + @echo "Building release binaries with GoReleaser..." 104 + @goreleaser build --snapshot --clean 105 + @echo "✓ Binaries built in dist/" 106 + 107 + # Create release (runs your script + GoReleaser) 100 108 release: 101 109 @echo "Creating release for version $(VERSION)..." 102 110 @./scripts/release.sh 103 - @echo "Releasing docker image..." 104 - @make docker-release 111 + 112 + # Full release with binaries 113 + release-full: release release-publish 114 + 115 + # Publish release with GoReleaser 116 + release-publish: 117 + @echo "Publishing release with GoReleaser..." 118 + @goreleaser release --clean 105 119 106 120 # ============================================================================ 107 121 # Docker Commands 108 122 # ============================================================================ 109 123 110 - # Build Docker image 124 + # Build Docker image (local) 111 125 docker-build: 112 126 @echo "Building Docker image $(DOCKER_FULL_IMAGE)..." 113 127 docker build \ ··· 118 132 . 119 133 @echo "✓ Built: $(DOCKER_FULL_IMAGE)" 120 134 121 - # Push Docker image to registry 135 + # Build multi-platform and push 136 + docker-buildx: 137 + @echo "Building multi-platform image $(DOCKER_FULL_IMAGE)..." 138 + docker buildx build \ 139 + --platform $(DOCKER_PLATFORMS) \ 140 + --build-arg VERSION=$(VERSION) \ 141 + --build-arg GIT_COMMIT=$(GIT_COMMIT) \ 142 + --tag $(DOCKER_FULL_IMAGE) \ 143 + --tag $(DOCKER_LATEST) \ 144 + --push \ 145 + . 146 + @echo "✓ Built and pushed: $(DOCKER_FULL_IMAGE) ($(DOCKER_PLATFORMS))" 147 + 148 + # Push Docker image 122 149 docker-push: 123 150 @echo "Pushing Docker image..." 124 151 docker push $(DOCKER_FULL_IMAGE) 125 152 docker push $(DOCKER_LATEST) 126 153 @echo "✓ Pushed: $(DOCKER_FULL_IMAGE)" 127 154 128 - # Build and push 129 - docker-release: docker-build docker-push 130 - 131 155 # Run Docker container as CLI 132 156 docker-run: 133 - docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) $(CMD) 157 + @docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle $(CMD) 158 + 159 + # Shortcuts 160 + docker-info: 161 + @docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle info 134 162 135 - # Run Docker container as server 163 + docker-fetch: 164 + @docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle fetch 165 + 166 + docker-verify: 167 + @docker run --rm -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle verify 168 + 169 + # Run as server 136 170 docker-serve: 137 - docker run --rm -it \ 138 - -p 8080:8080 \ 139 - -v $(PWD)/data:/data \ 140 - $(DOCKER_FULL_IMAGE) \ 141 - plcbundle serve --host 0.0.0.0 171 + docker run --rm -it -p 8080:8080 -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) plcbundle serve --host 0.0.0.0 142 172 143 - # Open shell in Docker container 173 + # Open shell 144 174 docker-shell: 145 175 docker run --rm -it -v $(PWD)/data:/data $(DOCKER_FULL_IMAGE) sh 146 176 ··· 167 197 @echo " make test-coverage - Run tests with coverage" 168 198 @echo " make fmt - Format code" 169 199 @echo " make deps - Download dependencies" 170 - @echo " make verify - Verify dependencies" 171 200 @echo "" 172 - @echo "Versioning:" 201 + @echo "Release:" 173 202 @echo " make version - Show current version" 174 - @echo " make bump-patch - Bump patch version (0.1.0 -> 0.1.1)" 175 - @echo " make bump-minor - Bump minor version (0.1.0 -> 0.2.0)" 176 - @echo " make bump-major - Bump major version (0.1.0 -> 1.0.0)" 177 - @echo " make release - Create and push release tag" 203 + @echo " make bump-patch - Bump patch (0.1.0 -> 0.1.1)" 204 + @echo " make bump-minor - Bump minor (0.1.0 -> 0.2.0)" 205 + @echo " make bump-major - Bump major (0.1.0 -> 1.0.0)" 206 + @echo " make release - Push tag to trigger release" 207 + @echo " make release-build - Test build all platforms locally" 208 + @echo " make release-publish- Publish with GoReleaser" 209 + @echo " make release-full - Complete release (tag + binaries)" 178 210 @echo "" 179 211 @echo "Docker:" 180 - @echo " make docker-build - Build Docker image" 181 - @echo " make docker-push - Push image to registry" 182 - @echo " make docker-release - Build and push" 183 - @echo " make docker-run - Run as CLI (CMD='info')" 212 + @echo " make docker-build - Build image (current platform)" 213 + @echo " make docker-buildx - Build multi-platform and push" 214 + @echo " make docker-run - Run CLI (CMD='info')" 215 + @echo " make docker-info - Show bundle info" 184 216 @echo " make docker-serve - Run as server" 185 - @echo " make docker-shell - Open shell in container" 186 - @echo " make docker-clean - Remove Docker images" 187 - @echo "" 217 + @echo " make docker-shell - Open shell" 218 + @echo ""