Skip to content

Commit

Permalink
Using sets.Strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dekiel committed Dec 1, 2023
1 parent 4e69981 commit 75dee35
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 26 deletions.
23 changes: 6 additions & 17 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type options struct {
exportTags bool
// signOnly only sign images. No build will be performed.
signOnly bool
imagesToSign imagesToSign
imagesToSign sets.Strings
buildInADO bool
parseTagsOnly bool
debug bool
Expand All @@ -55,17 +55,6 @@ const (
PlatformLinuxArm64 = "linux/arm64"
)

type imagesToSign []string

func (i *imagesToSign) String() string {
return fmt.Sprintf("%v", *i)
}

func (i *imagesToSign) Set(value string) error {
*i = append(*i, value)
return nil
}

// parseVariable returns a build-arg.
// Keys are set to upper-case.
func parseVariable(key, value string) string {
Expand Down Expand Up @@ -268,27 +257,27 @@ func buildInADO(o options) error {
}

fmt.Println("Running ADO pipeline.")
adoClient := adopipelines.NewClient(o.ADOOrganizationURL, adoPAT)
adoClient := adopipelines.NewClient(o.AdoConfig.ADOOrganizationURL, adoPAT)

fmt.Println("Triggering ADO build pipeline")
ctx := context.Background()
pipelineRun, err := adopipelines.Run(ctx, adoClient, templateParameters, o.GetADOConfig())
pipelineRun, err := adopipelines.Run(ctx, adoClient, templateParameters, o.AdoConfig.GetADOConfig())
if err != nil {
return fmt.Errorf("build in ADO failed, failed running ADO pipeline, err: %s", err)
}

pipelineRunResult, err := adopipelines.GetRunResult(ctx, adoClient, o.GetADOConfig(), pipelineRun.Id, 30*time.Second)
pipelineRunResult, err := adopipelines.GetRunResult(ctx, adoClient, o.AdoConfig.GetADOConfig(), pipelineRun.Id, 30*time.Second)
if err != nil {
return fmt.Errorf("build in ADO failed, failed getting ADO pipeline run result, err: %s", err)
}
fmt.Printf("ADO pipeline run finished with status: %s", *pipelineRunResult)

fmt.Println("Getting ADO pipeline run logs.")
adoBuildClient, err := adopipelines.NewBuildClient(o.ADOOrganizationURL, adoPAT)
adoBuildClient, err := adopipelines.NewBuildClient(o.AdoConfig.ADOOrganizationURL, adoPAT)
if err != nil {
fmt.Printf("Can't read ADO pipeline run logs, failed creating ADO build client, err: %s", err)
}
logs, err := adopipelines.GetRunLogs(ctx, adoBuildClient, &http.Client{}, o.GetADOConfig(), pipelineRun.Id, adoPAT)
logs, err := adopipelines.GetRunLogs(ctx, adoBuildClient, &http.Client{}, o.AdoConfig.GetADOConfig(), pipelineRun.Id, adoPAT)
if err != nil {
fmt.Printf("Failed read ADO pipeline run logs, err: %s", err)
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/azuredevops/pipelines/templatesParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p OCIImageBuilderTemplateParams) SetImageName(name string) {
// SetDockerfilePath sets required parameter DockerfilePath.
func (p OCIImageBuilderTemplateParams) SetDockerfilePath(path string) {
// TODO: Rename key to DockerfilePath
p["Dockerfile"] = path
p["dockerfile"] = path
}

// SetBuildContext sets required parameter BuildContext.
Expand All @@ -85,7 +85,7 @@ func (p OCIImageBuilderTemplateParams) SetBuildArgs(args string) {
// SetImageTags sets optional parameter ImageTags.
func (p OCIImageBuilderTemplateParams) SetImageTags(tags string) {
// TODO: Rename key to ImageTags
p["Tags"] = tags
p["tags"] = tags
}

// Validate validates if required OCIImageBuilderTemplateParams are set
Expand All @@ -112,7 +112,7 @@ func (p OCIImageBuilderTemplateParams) Validate() error {
if _, ok = p["Name"]; !ok {
return ErrRequiredParamNotSet("ImageName")
}
if _, ok = p["Dockerfile"]; !ok {
if _, ok = p["dockerfile"]; !ok {
return ErrRequiredParamNotSet("DockerfilePath")
}
if _, ok = p["Context"]; !ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/azuredevops/pipelines/templatesParams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("Test OCIImageBuilderTemplateParams", func() {

It("sets the correct DockerfilePath", func() {
params.SetDockerfilePath("/path/to/dockerfile")
Expect(params["Dockerfile"]).To(Equal("/path/to/dockerfile"))
Expect(params["dockerfile"]).To(Equal("/path/to/dockerfile"))
})

It("sets the correct BuildContext", func() {
Expand All @@ -76,7 +76,7 @@ var _ = Describe("Test OCIImageBuilderTemplateParams", func() {

It("sets the correct ImageTags", func() {
params.SetImageTags("tag1 tag2")
Expect(params["Tags"]).To(Equal("tag1 tag2"))
Expect(params["tags"]).To(Equal("tag1 tag2"))
})

// TODO: Improve assertions with more specific matchers and values.
Expand Down
9 changes: 5 additions & 4 deletions pkg/tools/pjtester/pjtester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package pjtester
import (
"context"
"fmt"
"github.com/kyma-project/test-infra/pkg/github/git"
prtagbuildermock "github.com/kyma-project/test-infra/pkg/tools/prtagbuilder/mocks"
"net/http"
"os"
"strconv"

"github.com/kyma-project/test-infra/pkg/github/git"
prtagbuildermock "github.com/kyma-project/test-infra/pkg/tools/prtagbuilder/mocks"

gogithub "github.com/google/go-github/v48/github"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -92,7 +93,7 @@ var _ = Describe("Pjtester", func() {
testConfig, _ := readTestCfg(testCfgFile)

Expect(testConfig).To(MatchAllFields(Fields{
// "ConfigPath": Equal("fake/config/file/path.yaml"),
// "configPath": Equal("fake/config/file/path.yaml"),
"PjConfigs": MatchAllFields(Fields{
"PrConfig": MatchAllKeys(Keys{
"kyma-project": MatchAllKeys(Keys{
Expand Down Expand Up @@ -148,7 +149,7 @@ var _ = Describe("Pjtester", func() {

Expect(testConfig).To(MatchAllFields(Fields{
"PrConfigs": BeZero(),
// "ConfigPath": BeZero(),
// "configPath": BeZero(),
"PjConfigs": MatchAllFields(Fields{
"PrConfig": BeZero(),
"ProwJobs": MatchAllKeys(Keys{
Expand Down
57 changes: 57 additions & 0 deletions prow/jobs/test-infra/image-builder-ado-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,63 @@

presubmits: # runs on PRs
kyma-project/test-infra:
- name: pull-build-image-builder-test
annotations:
description: "image-builder test job"
owner: "neighbors"
labels:
prow.k8s.io/pubsub.project: "sap-kyma-prow"
prow.k8s.io/pubsub.runID: "pull-gitserver-build"
prow.k8s.io/pubsub.topic: "prowjobs"
preset-sa-kyma-push-images: "true"
run_if_changed: '^tools/gitserver'
optional: true
skip_report: false
decorate: true
cluster: untrusted-workload
max_concurrency: 10
spec:
containers:
- image: "europe-docker.pkg.dev/kyma-project/dev/image-builder:PR-8806"
imagePullPolicy: Always
securityContext:
privileged: false
seccompProfile:
type: RuntimeDefault
allowPrivilegeEscalation: false
env:
- name: ADO_PAT
valueFrom:
secretKeyRef:
name: image-builder-ado-token
key: token
command:
- "/image-builder"
args:
- "--name=test-build"
- "--config=/config/kaniko-build-config.yaml"
- "--context=."
- "--dockerfile=development/secrets-rotator/cloud-run/rotate-service-account/Dockerfile"
- "--build-in-ado=true"
- "--export-tags=true"
resources:
requests:
memory: 500Mi
cpu: 500m
volumeMounts:
- name: config
mountPath: /config
readOnly: true
- name: signify-secret
mountPath: /secret
readOnly: true
volumes:
- name: config
configMap:
name: kaniko-build-config-ado
- name: signify-secret
secret:
secretName: signify-dev-secret
- name: pull-image-builder-test
annotations:
description: "image-builder test job"
Expand Down

0 comments on commit 75dee35

Please sign in to comment.