Skip to content

Commit

Permalink
chore: update config files
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zeng <[email protected]>
  • Loading branch information
knight42 committed Jan 7, 2024
1 parent 004e8ee commit 543faed
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/yukid
/yukictl
28 changes: 21 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,39 @@ concurrency:

permissions:
contents: write
# packages: write
# issues: write
packages: write

jobs:
goreleaser:
releaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ghcr.io/ustclug/yukid:${{ github.ref_name }}

# More assembly might be required: Docker logins, GPG, etc.
# It all depends on your needs.
- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
Expand Down
21 changes: 3 additions & 18 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
before:
hooks:
- go mod tidy
# TODO: publish docker images
# https://goreleaser.com/customization/docker/#how-it-works
builds:
# NOTE: Currently, we cannot distribute yukid as a binary, because it requires CGO.
# Instead, we distribute it as a Docker image. Please refer to the release workflow for more details.
-
id: yukictl
binary: yukictl
Expand All @@ -17,22 +17,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}}
-
id: yukid
binary: yukid
main: ./cmd/yukid
env:
# required by sqlite
- CGO_ENABLED=1
goos:
- linux
goarch:
- amd64
flags:
- -trimpath
ldflags:
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}}
- -s -w -X github.com/ustclug/Yuki/pkg/info.Version={{.Version}} -X github.com/ustclug/Yuki/pkg/info.BuildDate={{.Date}} -X github.com/ustclug/Yuki/pkg/info.GitCommit={{.Commit}}
archives:
- format: binary
checksum:
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# syntax=docker/dockerfile:1

FROM golang:1.21-bookworm AS build
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,target=/app \
OUT_DIR=/tmp make yukid

FROM debian:bookworm-slim
RUN apt update && apt install -y sqlite3 && rm -rf /var/lib/apt/lists/*
COPY --link --from=build /tmp/yukid /yukid
CMD ["/yukid"]
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ unit-test:
integration-test:
go test -v ./test/integration/...

git_commit := $(shell git rev-parse HEAD)
build_date := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')

VERSION ?= $(shell git describe --tags)
OUT_DIR ?= $(PWD)

.PHONY: yukid
yukid:
go build -trimpath ./cmd/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 -o $(OUT_DIR)/yukid ./cmd/yukid

.PHONY: yukictl
yukictl:
go build -trimpath ./cmd/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

BUILD_IMAGE ?= golang:1.21-bookworm

Expand Down
3 changes: 3 additions & 0 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import (
var (
Version string
BuildDate string
GitCommit string
)

var VersionInfo = struct {
Version string
GoVersion string
BuildDate string
GitCommit string
}{
Version: Version,
BuildDate: BuildDate,
GitCommit: GitCommit,
GoVersion: runtime.Version(),
}

0 comments on commit 543faed

Please sign in to comment.