Skip to content

Commit c8409b7

Browse files
committed
release binaries
improve the way the version is configured so it can be set by the docker build. Signed-off-by: Yves Brissaud <[email protected]>
1 parent 051bc96 commit c8409b7

File tree

5 files changed

+138
-7
lines changed

5 files changed

+138
-7
lines changed

Diff for: .github/workflows/release.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Release on tag
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install Task
20+
uses: arduino/setup-task@v1
21+
with:
22+
repo-token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Set up containerd
25+
uses: crazy-max/ghaction-setup-docker@v3
26+
with:
27+
set-host: true
28+
daemon-config: |
29+
{
30+
"features": {
31+
"containerd-snapshotter": true
32+
}
33+
}
34+
- name: Binaries
35+
run: task go:bin:all
36+
37+
- name: Create Release
38+
uses: softprops/action-gh-release@v1
39+
with:
40+
files: |
41+
dist/*/docker-runx-*

Diff for: Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# syntax=docker/dockerfile:1.4
2+
3+
ARG XX_VERSION=1.2.1
4+
ARG ALPINE_VERSION=3.20
5+
ARG GO_VERSION=1.23.1
6+
7+
ARG BIN_NAME
8+
9+
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
10+
11+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base
12+
COPY --from=xx / /
13+
RUN apk add --no-cache curl
14+
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
15+
RUN apk add --no-cache git ca-certificates openssh-client
16+
17+
FROM build-base AS build
18+
ARG TARGETPLATFORM
19+
RUN xx-go --wrap
20+
WORKDIR /go/src/
21+
COPY go.mod ./
22+
COPY go.sum ./
23+
RUN --mount=type=ssh \
24+
--mount=type=cache,target=/root/.cache \
25+
--mount=type=cache,target=/go/pkg/mod \
26+
go mod download
27+
COPY . ./
28+
29+
FROM build AS binary
30+
ENV CGO_ENABLED=0
31+
ARG BIN_NAME
32+
RUN --mount=type=cache,target=/root/.cache \
33+
--mount=type=cache,target=/go/pkg/mod \
34+
GIT_VERSION=$(git describe --tags | cut -c 2-) && \
35+
xx-go build \
36+
-o dist/${BIN_NAME} \
37+
-ldflags="-w -s \
38+
-X {{.PKG_NAME}}/internal/constants.Version=$GIT_VERSION" \
39+
./cmd/${BIN_NAME} && \
40+
xx-verify dist/${BIN_NAME}
41+
42+
FROM scratch AS export-bin
43+
ARG BIN_NAME
44+
ARG TARGETOS
45+
ARG TARGETARCH
46+
COPY --from=binary /go/src/dist/${BIN_NAME} /${BIN_NAME}-${TARGETOS}-${TARGETARCH}

Diff for: Taskfile.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: '3'
33
vars:
44
BIN_NAME: docker-runx
55
PKG_NAME: github.com/eunomie/docker-runx
6+
BIN_PLATFORMS: linux/amd64,linux/arm64,darwin/amd64,darwin/arm64,windows/amd64,windows/arm64
67
GOLANGCI_LINT_IMAGE_NAME: docker/golangci-lint:1.61.0-go1.23.1
78

89
tasks:
@@ -42,6 +43,17 @@ tasks:
4243
VERSION:
4344
sh: git describe --tags | cut -c 2-
4445

46+
go:bin:all:
47+
cmds:
48+
- |
49+
docker buildx build \
50+
--build-arg BIN_NAME={{.BIN_NAME}} \
51+
-f Dockerfile \
52+
--platform {{.BIN_PLATFORMS}} \
53+
--target export-bin \
54+
-o type=local,dest=dist \
55+
.
56+
4557
go:fmt:
4658
cmds:
4759
- find . -type f -name "*.go" -exec .github/remove_empty_imports.sh "{}" \;
@@ -84,3 +96,7 @@ tasks:
8496
- go:lint
8597
- go:test
8698
- go:gendocs
99+
100+
clean:
101+
cmds:
102+
- rm -rf dist

Diff for: internal/commands/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func NewCmd(_ command.Cli) *cobra.Command {
1414
Use: "version",
1515
Short: "Show Docker RunX version information",
1616
Run: func(_ *cobra.Command, _ []string) {
17-
fmt.Println(constants.Version)
17+
fmt.Println(constants.Short())
1818
},
1919
}
2020

Diff for: internal/constants/constants.go

+34-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"runtime"
66
"runtime/debug"
7+
"strings"
8+
"time"
79
)
810

911
const (
@@ -17,19 +19,45 @@ const (
1719
)
1820

1921
var (
20-
Version string = "devel"
21-
commit string
22-
UserAgent string
22+
Version string = "(devel)"
23+
Revision string
24+
LastCommit time.Time
25+
DirtyBuild bool
26+
UserAgent string
2327
)
2428

2529
func init() {
2630
if info, ok := debug.ReadBuildInfo(); ok {
2731
for _, setting := range info.Settings {
28-
if setting.Key == "vcs.revision" {
29-
commit = setting.Value
32+
if setting.Value == "" {
33+
continue
34+
}
35+
switch setting.Key {
36+
case "vcs.revision":
37+
Revision = setting.Value
38+
case "vcs.time":
39+
LastCommit, _ = time.Parse(time.RFC3339, setting.Value)
40+
case "vcs.modified":
41+
DirtyBuild = setting.Value == "true"
3042
}
3143
}
3244
}
3345

34-
UserAgent = fmt.Sprintf("%s/%s go/%s git-commit/%s", BinaryName, Version, runtime.Version(), commit)
46+
UserAgent = fmt.Sprintf("%s/%s go/%s git-commit/%s", BinaryName, Version, runtime.Version(), Revision)
47+
}
48+
49+
func Short() string {
50+
parts := make([]string, 0, 3)
51+
parts = append(parts, Version)
52+
if Revision != "unknown" && Revision != "" {
53+
commit := Revision
54+
if len(commit) > 7 {
55+
commit = commit[:7]
56+
}
57+
parts = append(parts, commit)
58+
if DirtyBuild {
59+
parts = append(parts, "dirty")
60+
}
61+
}
62+
return strings.Join(parts, "-")
3563
}

0 commit comments

Comments
 (0)