Skip to content

Commit

Permalink
feat: Pull version from ldflag (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbourd committed Mar 8, 2023
1 parent b806f91 commit 7eda8ce
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 28 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/ci.yml
Expand Up @@ -49,6 +49,16 @@ jobs:
# temporary work around for https://github.com/actions/checkout/issues/1169
- run: git config --system --add safe.directory /__w/e2core/e2core

- uses: docker/metadata-action@v4
id: docker_meta
with:
images: suborbital/e2core,ghcr.io/suborbital/e2core
tags: |
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{raw}}
flavor: |
latest=auto
- uses: goreleaser/goreleaser-action@v4
with:
version: latest
Expand All @@ -58,9 +68,12 @@ jobs:
run: goreleaser release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}

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

image:
needs: [lint, test]
Expand All @@ -70,10 +83,22 @@ jobs:
- uses: docker/setup-buildx-action@v2
- uses: docker/setup-qemu-action@v2

- uses: docker/metadata-action@v4
id: docker_meta
with:
images: suborbital/e2core,ghcr.io/suborbital/e2core
tags: |
type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{raw}}
flavor: |
latest=auto
- name: Build e2core image
uses: docker/build-push-action@v4
with:
cache-from: type=gha
build-args: |
VERSION=${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
load: true
push: false
tags: suborbital/e2core:dev
Expand Down Expand Up @@ -116,21 +141,13 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: docker/metadata-action@v4
if: startsWith(github.ref, 'refs/tags/v')
id: docker_meta
with:
images: suborbital/e2core,ghcr.io/suborbital/e2core
tags: |
type=match,pattern=(v.*)
flavor: |
latest=auto
- name: Build and push e2core image
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v4
with:
cache-from: type=gha
build-args: |
VERSION=${{ fromJSON(steps.docker_meta.outputs.json).labels['org.opencontainers.image.version'] }}
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
push: true
Expand Down
8 changes: 6 additions & 2 deletions .goreleaser.yml
Expand Up @@ -22,7 +22,7 @@ builds:
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
- -extldflags "-static"
- goos: linux
goarch: arm64
Expand All @@ -31,7 +31,7 @@ builds:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
- -extldflags "-static"
- goos: darwin
goarch: amd64
Expand All @@ -40,12 +40,16 @@ builds:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
ldflags:
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}
- goos: darwin
goarch: arm64
env:
- CGO_ENABLED=1
- CC=oa64-clang
- CXX=oa64-clang++
ldflags:
- -X github.com/suborbital/e2core/e2core/release.Version={{.Env.VERSION}}

changelog:
skip: true
Expand Down
10 changes: 2 additions & 8 deletions Dockerfile
@@ -1,26 +1,20 @@
FROM golang:1.20 as builder

RUN mkdir -p /go/src/github.com/suborbital/e2core
WORKDIR /go/src/github.com/suborbital/e2core/
ARG VERSION="dev"

# Deps first
COPY go.mod go.sum ./
RUN go mod download

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

RUN make e2core/static

FROM debian:buster-slim

RUN groupadd -g 999 e2core && \
useradd -r -u 999 -g e2core e2core && \
mkdir -p /home/e2core && \
chown -R e2core /home/e2core && \
chmod -R 700 /home/e2core

RUN apt-get update \
&& apt-get install -y ca-certificates

Expand Down
2 changes: 1 addition & 1 deletion e2core/command/mod_start.go
Expand Up @@ -22,7 +22,7 @@ func ModStart() *cobra.Command {
Use: "start [module path or FQMN]",
Short: "start a E2Core module",
Long: "starts a single module and connects to the mesh to receive jobs",
Version: release.E2CoreServerDotVersion,
Version: release.Version,
RunE: func(cmd *cobra.Command, args []string) error {
path := ""
if len(args) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions e2core/command/start.go
Expand Up @@ -34,7 +34,7 @@ func Start() *cobra.Command {
Use: "start [bundle-path]",
Short: "start the e2core server",
Long: "starts the e2core server using the provided options",
Version: release.E2CoreServerDotVersion,
Version: release.Version,
RunE: func(cmd *cobra.Command, args []string) error {
path := "./modules.wasm.zip"
if len(args) > 0 {
Expand Down Expand Up @@ -142,7 +142,7 @@ func setupLogger() zerolog.Logger {
logger := zerolog.New(os.Stderr).With().
Timestamp().
Str("command", "start").
Str("version", release.E2CoreServerDotVersion).
Str("version", release.Version).
Logger().Level(zerolog.InfoLevel)

return logger
Expand Down
4 changes: 2 additions & 2 deletions e2core/release/version.go
@@ -1,4 +1,4 @@
package release

// E2CoreServerDotVersion represents the dot version for E2Core Server
var E2CoreServerDotVersion = "0.6.0"
// Version represents the version for E2Core server
var Version = "dev"
6 changes: 3 additions & 3 deletions main.go
Expand Up @@ -21,10 +21,10 @@ func main() {
func rootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "e2core",
Version: release.E2CoreServerDotVersion,
Version: release.Version,
Long: `
E2Core is a secure development kit and server for writing and running untrusted third-party plugins.
The E2Core server is responsible for managing and running plugins using simple HTTP, RPC, or streaming interfaces.`,
}

Expand All @@ -34,7 +34,7 @@ func rootCommand() *cobra.Command {
func modCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "mod",
Version: release.E2CoreServerDotVersion,
Version: release.Version,
Short: "commands for working with modules",
Hidden: true,
}
Expand Down

0 comments on commit 7eda8ce

Please sign in to comment.