Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "deb" Makefile target #84

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable

- name: Install Go
uses: actions/setup-go@v5
with:
Expand All @@ -42,7 +38,7 @@ jobs:

- name: Build yukid
run: |
CGO_ENABLED=0 make yukid
CGO_ENABLED=0 make yukid yukictl deb

- name: Build and Push Image
uses: docker/build-push-action@v6
Expand All @@ -59,3 +55,8 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: softprops/action-gh-release@v1
with:
files: |
yuki*.deb
Comment on lines +59 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好主意,那么 prefix 要不要从 /usr/local 换到 /usr

(既然我们都在用 package manager 了,可以考虑遵循 FHS)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🉑 我觉得挺好的

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Build output files
/yukictl
/yukid
/*.deb

.idea/
/debian/
dist/

*.swp
Expand Down
36 changes: 28 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.PHONY: all
all: yukid yukictl

.PHONY: clean
clean:
rm -f yukid yukictl *.deb

.PHONY: lint
lint:
golangci-lint run --fix ./...
Expand All @@ -14,16 +21,29 @@ git_commit := $(shell git rev-parse HEAD)
build_date := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
version ?= $(shell git describe --tags)

go_ldflags := -s -w \
-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
-X github.com/ustclug/Yuki/pkg/info.Version=$(version)

.PHONY: yukid
yukid:
go build -ldflags "-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
-X github.com/ustclug/Yuki/pkg/info.Version=$(version)" \
-trimpath ./cmd/yukid
go build -ldflags "$(go_ldflags)" -trimpath ./cmd/yukid

.PHONY: yukictl
yukictl:
go build -ldflags "-X github.com/ustclug/Yuki/pkg/info.BuildDate=$(build_date) \
-X github.com/ustclug/Yuki/pkg/info.GitCommit=$(git_commit) \
-X github.com/ustclug/Yuki/pkg/info.Version=$(version)" \
-trimpath ./cmd/yukictl
go build -ldflags "$(go_ldflags)" -trimpath ./cmd/yukictl

.PHONY: deb

deb_dir := $(shell mktemp -d)
deb: | yukid yukictl
mkdir -p $(addprefix $(deb_dir)/, DEBIAN etc/bash_completion.d etc/yuki lib/systemd/system usr/local/bin)
cp etc/daemon.example.toml $(deb_dir)/etc/yuki
cp etc/yukid.service $(deb_dir)/lib/systemd/system
cp yukid yukictl $(deb_dir)/usr/local/bin
ln -s yukictl $(deb_dir)/usr/local/bin/yuki
$(deb_dir)/usr/local/bin/yukictl completion bash > $(deb_dir)/etc/bash_completion.d/yukictl
sed "s/\$$VERSION\>/$(version)/g;s/^Version: v/Version: /g;s/\$$ARCH\>/$(shell go env GOARCH)/g" \
etc/debian-control > $(deb_dir)/DEBIAN/control
dpkg-deb --root-owner-group --build -Zxz $(deb_dir) .
12 changes: 0 additions & 12 deletions deploy/yukid.service

This file was deleted.

24 changes: 24 additions & 0 deletions etc/daemon.example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
debug = false

listen_addr = "127.0.0.1:9999"
db_url = "/home/mirror/yukid.db"
repo_config_dir = "/home/mirror/repos/"

fs = "zfs"

# uid:gid
owner = "1000:1000"

log_file = "/home/mirror/log/yukid.log"
repo_logs_dir = "/home/mirror/log/"
log_level = "error"

bind_ip = "0.0.0.0"

name_prefix = "syncing-"

images_upgrade_interval = "1h"

post_sync = ["/home/mirror/scripts/post_sync.sh"]

sync_timeout = "48h"
9 changes: 9 additions & 0 deletions etc/debian-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: yuki
Version: $VERSION
Architecture: $ARCH
Priority: optional
Section: admin
Maintainer: USTC LUG <[email protected]>
Homepage: https://github.com/ustclug/Yuki
Depends: docker-engine | docker.io | docker-ce
Description: USTC Mirror Manager
18 changes: 18 additions & 0 deletions etc/yukid.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Yuki - USTC Mirror Manager
After=docker.service
Requires=docker.service
PartOf=docker.service
ConditionPathExists=/etc/yuki/daemon.toml

[Service]
Type=exec
User=mirror
ExecStart=/usr/local/bin/yukid
ExecReload=/usr/local/bin/yukictl reload
Restart=on-failure
RestartSec=5

[Install]
Alias=yuki.service
WantedBy=multi-user.target