-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packaging: add make file to build and upload deb
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DEB_USER=<youruser> | ||
DEB_TOKEN=<yourdebianregistrytoken> | ||
# example gitea debian package registry: | ||
DEB_REGISTRY=https://<yourgitea>/api/packages/<youruserororg>/debian/pool/bookworm/stable/upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
.env | ||
ringlog | ||
test.log | ||
.vscode/settings.json | ||
build/ | ||
# Editor | ||
*~ | ||
.emacs.d/ | ||
*.swp | ||
*.swo | ||
.vim/ | ||
__* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Load variables from .env if it exists | ||
ifneq (,$(wildcard .env)) | ||
include .env | ||
export $(shell sed 's/=.*//' .env) | ||
endif | ||
|
||
BINARY_NAME=ringlog | ||
GO_MODULE=github.com/anti-spin/ringlog | ||
GOOS=linux | ||
GOARCH=amd64 | ||
CGO_ENABLED=0 | ||
|
||
# Get the latest git tag or commit hash | ||
VERSION := $(shell git describe --tags --always --dirty) | ||
|
||
BUILD_DIR=build | ||
DEB_DIR=$(BUILD_DIR)/$(BINARY_NAME)_$(VERSION)_amd64 | ||
|
||
# Default target | ||
all: clean package upload | ||
|
||
# Build the binary with static linking | ||
build: | ||
@echo "Building $(BINARY_NAME) $(VERSION)..." | ||
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build -ldflags="-X $(GO_MODULE)/cmd.version=$(VERSION)" -o $(BINARY_NAME) | ||
@echo "Build completed: $(BINARY_NAME)" | ||
|
||
# Clean the binary | ||
clean: | ||
@echo "Cleaning up..." | ||
rm -f $(BINARY_NAME) | ||
rm -rf $(BUILD_DIR) | ||
@echo "Clean completed." | ||
|
||
package-prepare: build | ||
mkdir -p $(DEB_DIR)/DEBIAN | ||
install -m 755 -D $(BINARY_NAME) $(DEB_DIR)/usr/local/bin/$(BINARY_NAME) | ||
install -m 644 -D debian/$(BINARY_NAME).1 $(DEB_DIR)/usr/share/man/man1/$(BINARY_NAME).1 | ||
sed "s/@VERSION@/$(VERSION)/g" < debian/control.template > $(DEB_DIR)/DEBIAN/control | ||
if [ -f debian/postinst ]; then install -m 755 -D debian/postinst $(DEB_DIR)/DEBIAN/postinst; fi | ||
if [ -f debian/postrm ]; then install -m 755 -D debian/postrm $(DEB_DIR)/DEBIAN/postrm; fi | ||
|
||
package: package-prepare | ||
@echo "Packaging $(BINARY_NAME)..." | ||
dpkg-deb --build $(DEB_DIR) | ||
@echo "Created $(BINARY_NAME)_$(VERSION)_amd64.deb" | ||
|
||
upload: | ||
@echo "Checking for DEB_REGISTRY..." | ||
@if [ -n "$(DEB_REGISTRY)" ]; then \ | ||
echo "Uploading to registry $(DEB_REGISTRY)"; \ | ||
./upload-deb.sh $(BUILD_DIR)/$(BINARY_NAME)_$(VERSION)_amd64.deb; \ | ||
else \ | ||
echo "DEB_REGISTRY not set, skipping upload"; \ | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/sh | ||
|
||
# read DEB_USER, DEB_TOKEN, and DEB_REGISTRY from .env file | ||
set -a | ||
. ./.env | ||
set +a | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "Error: Please provide a file path as an argument." | ||
echo "Usage: $0 <file_path>" | ||
exit 1 | ||
fi | ||
|
||
file_path="$1" | ||
|
||
if [ ! -f "$file_path" ]; then | ||
echo "Error: File '$file_path' does not exist." | ||
exit 1 | ||
fi | ||
|
||
curl --user $DEB_USER:$DEB_TOKEN \ | ||
--upload-file $file_path \ | ||
$DEB_REGISTRY | ||
|
||
# Check the curl exit status | ||
if [ $? -eq 0 ]; then | ||
echo "Uploaded to debian registry $DEB_REGISTRY" | ||
else | ||
echo "Error: File upload failed." | ||
fi |