Skip to content

Commit

Permalink
fix: docker version (#444)
Browse files Browse the repository at this point in the history
* feat: added the ability to set a user default AI provider

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* feat: added the ability to set a user default AI provider

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* feat: s3 based caching

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* fix: missing version info and improvements

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

* chore: fixing local build

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>

---------

Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
AlexsJones committed May 20, 2023
1 parent b7dc384 commit 1f767eb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Expand Up @@ -15,6 +15,8 @@ builds:
- darwin
ldflags:
- -s -w -X main.version={{.Version}}
- -s -w -X main.commit={{.ShortCommit}}
- -s -w -X main.Date={{.CommitDate}}

nfpms:
- file_name_template: '{{ .ProjectName }}_{{ .Arch }}'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -54,7 +54,7 @@ all: tidy add-copyright lint cover build
build:
@echo "$(shell go version)"
@echo "===========> Building binary $(BUILDAPP) *[Git Info]: $(VERSION)-$(GIT_COMMIT)"
@export CGO_ENABLED=0 && go build -o $(BUILDAPP) -ldflags '-s -w' $(BUILDFILE)
@export CGO_ENABLED=0 && go build -o $(BUILDAPP) -ldflags "-s -w -X main.version=dev -X main.commit=$$(git rev-parse --short HEAD) -X main.date=$$(date +%FT%TZ)" $(BUILDFILE)

## tidy: tidy go.mod
.PHONY: tidy
Expand Down
10 changes: 7 additions & 3 deletions cmd/root.go
Expand Up @@ -34,7 +34,9 @@ var (
cfgFile string
kubecontext string
kubeconfig string
version string
Version string
Commit string
Date string
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -49,8 +51,10 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(v string) {
version = v
func Execute(v string, c string, d string) {
Version = v
Commit = c
Date = d
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
19 changes: 18 additions & 1 deletion cmd/version.go
Expand Up @@ -14,6 +14,9 @@ limitations under the License.
package cmd

import (
"fmt"
"runtime/debug"

"github.com/spf13/cobra"
)

Expand All @@ -23,7 +26,21 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of k8sgpt",
Long: `All software has versions. This is k8sgpt's`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Printf("k8sgpt version %s\n", version)
if Version == "dev" {
details, ok := debug.ReadBuildInfo()
if ok && details.Main.Version != "" && details.Main.Version != "(devel)" {
Version = details.Main.Version
for _, i := range details.Settings {
if i.Key == "vcs.time" {
Date = i.Value
}
if i.Key == "vcs.revision" {
Commit = i.Value
}
}
}
}
fmt.Printf("ks8gpt: %s (%s), built at: %s\n", Version, Commit, Date)
},
}

Expand Down
6 changes: 4 additions & 2 deletions container/Dockerfile
Expand Up @@ -12,15 +12,17 @@
FROM golang:1.20.4-alpine3.16 AS builder

ENV CGO_ENABLED=0

ARG VERSION
ARG COMMIT
ARG DATE
WORKDIR /workspace

COPY go.mod go.sum ./
RUN go mod download

COPY ./ ./

RUN go build -o /workspace/k8sgpt ./
RUN go build -o /workspace/k8sgpt -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" ./

FROM gcr.io/distroless/static AS production

Expand Down
8 changes: 6 additions & 2 deletions main.go
Expand Up @@ -15,8 +15,12 @@ package main

import "github.com/k8sgpt-ai/k8sgpt/cmd"

var version = "dev"
var (
version = "dev"
commit = "HEAD"
date = "unknown"
)

func main() {
cmd.Execute(version)
cmd.Execute(version, commit, date)
}

0 comments on commit 1f767eb

Please sign in to comment.