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 7, 2024
1 parent d995863 commit 0491b85
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
23 changes: 20 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,26 @@ 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
ARG JAVA_PROVIDER_IMG=quay.io/konveyor/java-external-provider:latest
ARG GENERIC_PROVIDER_IMG=quay.io/konveyor/generic-external-provider:latest

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.RunnerImage=$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.JavaProviderImage=$JAVA_PROVIDER_IMG' \
-X 'github.com/konveyor-ecosystem/kantra/cmd.GenericProviderImage=$GENERIC_PROVIDER_IMG' -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.RunnerImage=$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.JavaProviderImage=$JAVA_PROVIDER_IMG' \
-X 'github.com/konveyor-ecosystem/kantra/cmd.GenericProviderImage=$GENERIC_PROVIDER_IMG' -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.RunnerImage=$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.JavaProviderImage=$JAVA_PROVIDER_IMG' \
-X 'github.com/konveyor-ecosystem/kantra/cmd.GenericProviderImage=$GENERIC_PROVIDER_IMG' -X 'github.com/konveyor-ecosystem/kantra/cmd.RootCommandName=$NAME'" -a -o windows-kantra main.go

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

Expand Down
25 changes: 18 additions & 7 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 @@ -30,8 +30,6 @@ type Config struct {
RunLocal bool `env:"RUN_LOCAL"`
JavaProviderImage string `env:"JAVA_PROVIDER_IMG" default:"quay.io/konveyor/java-external-provider:latest"`
GenericProviderImage string `env:"GENERIC_PROVIDER_IMG" default:"quay.io/konveyor/generic-external-provider:latest"`
DotNetProviderImage string `env:"DOTNET_PROVIDER_IMG" default:"quay.io/konveyor/dotnet-external-provider:latest"`
YQProviderImage string `env:"YQ_PROVIDER_IMG" default:"quay.io/konveyor/yq-external-provider:latest"`
}

func (c *Config) Load() error {
Expand All @@ -41,7 +39,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 @@ -82,9 +82,20 @@ 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)
err := os.Setenv("RUNNER_IMG", updatedImg)
// 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
}
Expand Down
10 changes: 8 additions & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import (
)

var (
BuildCommit = ""
Version = "v99.0.0"
BuildCommit = ""
Version = "latest"
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"
JavaProviderImage = "quay.io/konveyor/java-external-provider:latest"
GenericProviderImage = "quay.io/konveyor/generic-external-provider:latest"
)

// Use build flags to set correct Version and BuildCommit
Expand All @@ -22,6 +27,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 0491b85

Please sign in to comment.