Skip to content

Commit

Permalink
add version in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
strokyl committed Feb 14, 2024
1 parent 6b7d6c9 commit 822197d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@ jobs:
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=registry,ref=${{env.HARBOR_IMAGE}}:main
cache-to: type=inline,mode=min
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
build-args: |
hash=${{ github.sha }}
version=${{ github.event.release.tag_name }}
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.22.0"
build_flags: -X 'github.com/conduktor/ctl/cmd.version=${{ github.event.release.tag_name }}' -X 'github.com/conduktor/ctl/cmd.hash=${{ github.sha }}'
project_path: "./"
binary_name: "conduktor"
build-docker:
Expand Down
23 changes: 23 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
)

var version = "unknown"
var hash = "unknown"

// versionCmd represents the apply command
var versionCmd = &cobra.Command{
Use: "version",
Short: "display the version of conduktor",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\nHash: %s\n", version, hash)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM golang:1.22
ARG version=unknown
ARG hash=unknown
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 GOOS=linux go build -o /conduktor . && rm -rf /app
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'github.com/conduktor/ctl/cmd.version=$version' -X 'github.com/conduktor/ctl/cmd.hash=$hash'" -o /conduktor . && rm -rf /app
CMD ["/bin/conduktor"]

FROM scratch
Expand Down

0 comments on commit 822197d

Please sign in to comment.