Skip to content

Commit

Permalink
use build args for image
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed May 9, 2024
1 parent d32f979 commit 0f976f6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ COPY cmd/ cmd/
# Build
ARG VERSION
ARG BUILD_COMMIT
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 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 GOARCH=amd64 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 GOARCH=amd64 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.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.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.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.RootCommandName=$NAME'" -a -o windows-kantra main.go

FROM quay.io/konveyor/analyzer-lsp:release-0.3

Expand Down
23 changes: 18 additions & 5 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 @@ -43,7 +43,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 All @@ -52,9 +54,20 @@ func (c *Config) Load() 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
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 = "release-0.3"
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 0f976f6

Please sign in to comment.