Skip to content

Commit

Permalink
Merge pull request #6 from conduktor/put_version_info
Browse files Browse the repository at this point in the history
add version in cli
  • Loading branch information
strokyl authored Feb 15, 2024
2 parents 6b7d6c9 + 52ab290 commit aaa89b4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
org.opencontainers.image.documentation=${{ env.LABEL_IMAGE_DOCUMENTATION }}
org.opencontainers.image.vendor=${{ env.LABEL_IMAGE_VENDOR }}
org.opencontainers.image.url=${{ env.LABEL_IMAGE_URL }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ github.event.release.tag_name || github.ref_name }}
- uses: actions/checkout@v3
- name: Build ${{ env.IMAGE_NAME }} for ${{ steps.buildx.outputs.platforms }}
id: build
Expand All @@ -78,4 +80,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 || github.ref_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 aaa89b4

Please sign in to comment.