Skip to content

Commit 7eda8ce

Browse files
authored
feat: Pull version from ldflag (#393)
1 parent b806f91 commit 7eda8ce

7 files changed

Lines changed: 43 additions & 28 deletions

File tree

.github/workflows/ci.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ jobs:
4949
# temporary work around for https://github.com/actions/checkout/issues/1169
5050
- run: git config --system --add safe.directory /__w/e2core/e2core
5151

52+
- uses: docker/metadata-action@v4
53+
id: docker_meta
54+
with:
55+
images: suborbital/e2core,ghcr.io/suborbital/e2core
56+
tags: |
57+
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/v') }}
58+
type=semver,pattern={{raw}}
59+
flavor: |
60+
latest=auto
61+
5262
- uses: goreleaser/goreleaser-action@v4
5363
with:
5464
version: latest
@@ -58,9 +68,12 @@ jobs:
5868
run: goreleaser release --clean
5969
env:
6070
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
VERSION: ${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
6172

6273
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
6374
run: goreleaser release --clean --snapshot
75+
env:
76+
VERSION: ${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
6477

6578
image:
6679
needs: [lint, test]
@@ -70,10 +83,22 @@ jobs:
7083
- uses: docker/setup-buildx-action@v2
7184
- uses: docker/setup-qemu-action@v2
7285

86+
- uses: docker/metadata-action@v4
87+
id: docker_meta
88+
with:
89+
images: suborbital/e2core,ghcr.io/suborbital/e2core
90+
tags: |
91+
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/v') }}
92+
type=semver,pattern={{raw}}
93+
flavor: |
94+
latest=auto
95+
7396
- name: Build e2core image
7497
uses: docker/build-push-action@v4
7598
with:
7699
cache-from: type=gha
100+
build-args: |
101+
VERSION=${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
77102
load: true
78103
push: false
79104
tags: suborbital/e2core:dev
@@ -116,21 +141,13 @@ jobs:
116141
username: ${{ github.actor }}
117142
password: ${{ secrets.GITHUB_TOKEN }}
118143

119-
- uses: docker/metadata-action@v4
120-
if: startsWith(github.ref, 'refs/tags/v')
121-
id: docker_meta
122-
with:
123-
images: suborbital/e2core,ghcr.io/suborbital/e2core
124-
tags: |
125-
type=match,pattern=(v.*)
126-
flavor: |
127-
latest=auto
128-
129144
- name: Build and push e2core image
130145
if: startsWith(github.ref, 'refs/tags/v')
131146
uses: docker/build-push-action@v4
132147
with:
133148
cache-from: type=gha
149+
build-args: |
150+
VERSION=${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
134151
cache-to: type=gha,mode=max
135152
platforms: linux/amd64,linux/arm64
136153
push: true

.goreleaser.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ builds:
2222
- CC=x86_64-linux-gnu-gcc
2323
- CXX=x86_64-linux-gnu-g++
2424
ldflags:
25-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
25+
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
2626
- -extldflags "-static"
2727
- goos: linux
2828
goarch: arm64
@@ -31,7 +31,7 @@ builds:
3131
- CC=aarch64-linux-gnu-gcc
3232
- CXX=aarch64-linux-gnu-g++
3333
ldflags:
34-
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
34+
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
3535
- -extldflags "-static"
3636
- goos: darwin
3737
goarch: amd64
@@ -40,12 +40,16 @@ builds:
4040
- CGO_ENABLED=1
4141
- CC=o64-clang
4242
- CXX=o64-clang++
43+
ldflags:
44+
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
4345
- goos: darwin
4446
goarch: arm64
4547
env:
4648
- CGO_ENABLED=1
4749
- CC=oa64-clang
4850
- CXX=oa64-clang++
51+
ldflags:
52+
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
4953

5054
changelog:
5155
skip: true

Dockerfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
FROM golang:1.20 as builder
2-
3-
RUN mkdir -p /go/src/github.com/suborbital/e2core
42
WORKDIR /go/src/github.com/suborbital/e2core/
3+
ARG VERSION="dev"
54

6-
# Deps first
75
COPY go.mod go.sum ./
86
RUN go mod download
97

10-
# Then the rest
118
COPY . ./
12-
RUN go mod vendor
9+
RUN go build -o .bin/e2core -tags netgo -ldflags="-extldflags=-static -X 'github.com/suborbital/e2core/e2core/release.Version=$VERSION'" .
1310

14-
RUN make e2core/static
1511

1612
FROM debian:buster-slim
17-
1813
RUN groupadd -g 999 e2core && \
1914
useradd -r -u 999 -g e2core e2core && \
2015
mkdir -p /home/e2core && \
2116
chown -R e2core /home/e2core && \
2217
chmod -R 700 /home/e2core
23-
2418
RUN apt-get update \
2519
&& apt-get install -y ca-certificates
2620

e2core/command/mod_start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func ModStart() *cobra.Command {
2222
Use: "start [module path or FQMN]",
2323
Short: "start a E2Core module",
2424
Long: "starts a single module and connects to the mesh to receive jobs",
25-
Version: release.E2CoreServerDotVersion,
25+
Version: release.Version,
2626
RunE: func(cmd *cobra.Command, args []string) error {
2727
path := ""
2828
if len(args) > 0 {

e2core/command/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func Start() *cobra.Command {
3434
Use: "start [bundle-path]",
3535
Short: "start the e2core server",
3636
Long: "starts the e2core server using the provided options",
37-
Version: release.E2CoreServerDotVersion,
37+
Version: release.Version,
3838
RunE: func(cmd *cobra.Command, args []string) error {
3939
path := "./modules.wasm.zip"
4040
if len(args) > 0 {
@@ -142,7 +142,7 @@ func setupLogger() zerolog.Logger {
142142
logger := zerolog.New(os.Stderr).With().
143143
Timestamp().
144144
Str("command", "start").
145-
Str("version", release.E2CoreServerDotVersion).
145+
Str("version", release.Version).
146146
Logger().Level(zerolog.InfoLevel)
147147

148148
return logger

e2core/release/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package release
22

3-
// E2CoreServerDotVersion represents the dot version for E2Core Server
4-
var E2CoreServerDotVersion = "0.6.0"
3+
// Version represents the version for E2Core server
4+
var Version = "dev"

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ func main() {
2121
func rootCommand() *cobra.Command {
2222
cmd := &cobra.Command{
2323
Use: "e2core",
24-
Version: release.E2CoreServerDotVersion,
24+
Version: release.Version,
2525
Long: `
2626
E2Core is a secure development kit and server for writing and running untrusted third-party plugins.
27-
27+
2828
The E2Core server is responsible for managing and running plugins using simple HTTP, RPC, or streaming interfaces.`,
2929
}
3030

@@ -34,7 +34,7 @@ func rootCommand() *cobra.Command {
3434
func modCommand() *cobra.Command {
3535
cmd := &cobra.Command{
3636
Use: "mod",
37-
Version: release.E2CoreServerDotVersion,
37+
Version: release.Version,
3838
Short: "commands for working with modules",
3939
Hidden: true,
4040
}

0 commit comments

Comments
 (0)