Skip to content

Commit

Permalink
use build args for image and cmd name
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed May 6, 2024
1 parent d995863 commit 9c0e9f4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ COPY pkg/ pkg/
# Build
ARG VERSION=latest
ARG BUILD_COMMIT
RUN CGO_ENABLED=0 GOOS=linux go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT'" -a -o kantra main.go
RUN CGO_ENABLED=0 GOOS=darwin go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT'" -a -o darwin-kantra main.go
RUN CGO_ENABLED=0 GOOS=windows go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT'" -a -o windows-kantra main.go
ARG IMAGE=quay.io/konveyor/kantra
ARG NAME=kantra
ARG JAVA_BUNDLE=/jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar

RUN CGO_ENABLED=0 GOOS=linux go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.Image=$IMAGE' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT' -X 'github.com/konveyor-ecosystem/kantra/cmd.JavaBundlesLocation=$JAVA_BUNDLE' -X 'github.com/konveyor-ecosystem/kantra/cmd.RootCommandName=$NAME'" -a -o kantra main.go
RUN CGO_ENABLED=0 GOOS=darwin go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.Image=$IMAGE' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT' -X 'github.com/konveyor-ecosystem/kantra/cmd.JavaBundlesLocation=$JAVA_BUNDLE' -X 'github.com/konveyor-ecosystem/kantra/cmd.RootCommandName=$NAME'" -a -o darwin-kantra main.go
RUN CGO_ENABLED=0 GOOS=windows go build --ldflags="-X 'github.com/konveyor-ecosystem/kantra/cmd.Version=$VERSION' -X 'github.com/konveyor-ecosystem/kantra/cmd.Image=$IMAGE' -X 'github.com/konveyor-ecosystem/kantra/cmd.BuildCommit=$BUILD_COMMIT' -X 'github.com/konveyor-ecosystem/kantra/cmd.JavaBundlesLocation=$JAVA_BUNDLE' -X 'github.com/konveyor-ecosystem/kantra/cmd.RootCommandName=$NAME'" -a -o windows-kantra main.go

FROM quay.io/konveyor/analyzer-lsp:${VERSION}

Expand Down
20 changes: 17 additions & 3 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/codingconcepts/env"
)
Expand All @@ -19,7 +20,6 @@ const (
XMLRulePath = "/opt/xmlrules"
ShimOutputPath = "/opt/shimoutput"
CustomRulePath = "/opt/input/rules"
JavaBundlesLocation = "/jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar"
)

type Config struct {
Expand All @@ -41,7 +41,9 @@ func (c *Config) Load() error {
if err := c.loadRunnerImg(); err != nil {
return err
}

if err := c.loadCommandName(); err != nil {
return err
}
err := env.Set(c)
if err != nil {
return err
Expand Down Expand Up @@ -83,11 +85,23 @@ func (c *Config) trySetDefaultPodmanBin(file string) (found bool, err error) {

func (c *Config) loadRunnerImg() error {
if Version != "v99.0.0" {
updatedImg := fmt.Sprintf("quay.io/konveyor/kantra:%v", Version)
// if version tag is given in image
img := strings.TrimSuffix(RunnerImage, fmt.Sprintf(":%v", Version))
updatedImg := fmt.Sprintf("%v:%v", img, Version)
err := os.Setenv("RUNNER_IMG", updatedImg)
if err != nil {
return err
}
}
return nil
}

func (c *Config) loadCommandName() error {
if RootCommandName != "kantra" {
err := os.Setenv("CMD_NAME", RootCommandName)
if err != nil {
return err
}
}
return nil
}
8 changes: 6 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
)

var (
BuildCommit = ""
Version = "v99.0.0"
BuildCommit = ""
Version = "v99.0.0"
RunnerImage = "quay.io/konveyor/kantra"
RootCommandName = "kantra"
JavaBundlesLocation = "/jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar"
)

// Use build flags to set correct Version and BuildCommit
Expand All @@ -22,6 +25,7 @@ func NewVersionCommand() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("version: %s\n", Version)
fmt.Printf("SHA: %s\n", BuildCommit)
fmt.Printf("image: %s\n", RunnerImage)
},
}
return versionCmd
Expand Down
14 changes: 0 additions & 14 deletions hack/update-settings.sh

This file was deleted.

0 comments on commit 9c0e9f4

Please sign in to comment.