Compare commits

...

7 Commits

Author SHA1 Message Date
Chirag S e70d271e93 feat: [CI-18951]: added a log when harness fallback is used 2026-02-18 10:56:51 +05:30
Chirag S f32aa46ea8 feat: [CI-18951]: added unit tests and better comments for the changes 2026-02-18 10:40:37 +05:30
Chirag S 5810bf8a5a feat: [CI-18951]: check for HARNESS prefixed proxy variables 2026-02-13 14:47:58 +05:30
Anurag Madnawat 23887402c3 [feat]: [CI-20260]: Make daemon retry count configurable (#503) 2026-02-11 11:04:38 +05:30
ebtasam-faridy e9bba4ffcf Update pipeline drone-docker-harness (#502) 2026-01-28 19:07:35 +05:30
ebtasam-faridy 7b900ae75d Ci 20437 (#499)
* fix: [CI-20437] Golang version update for vulnerability fix

* fix: [CI-20437] Golang version update for vulnerability fix
2026-01-28 14:13:48 +05:30
OP (oppenheimer) aabeaaf7bb feat: [CI-20527]: add push-only mode to skip build and push pre-existing images (#500)
* Add push-only support

* Include support for PLUGIN_NO_PUSH as well
2026-01-26 22:55:18 +05:30
8 changed files with 374 additions and 50 deletions
+30 -30
View File
@@ -12,7 +12,7 @@ platform:
steps:
- name: vet
image: golang:1.23
image: golang:1.24.11
commands:
- go vet ./...
environment:
@@ -22,7 +22,7 @@ steps:
path: /go
- name: test
image: golang:1.23
image: golang:1.24.11
commands:
- go test -cover ./...
environment:
@@ -55,7 +55,7 @@ platform:
steps:
- name: go build
image: golang:1.23
image: golang:1.24.11
environment:
CGO_ENABLED: 0
commands:
@@ -162,7 +162,7 @@ platform:
steps:
- name: go build
image: golang:1.23
image: golang:1.24.11
environment:
CGO_ENABLED: 0
commands:
@@ -264,7 +264,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker'
environment:
@@ -275,7 +275,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker'
environment:
@@ -285,7 +285,7 @@ steps:
- tag
- name: executable
image: golang:1.23
image: golang:1.24.11
commands:
- ./release/linux/amd64/drone-docker --help
@@ -329,7 +329,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker'
environment:
@@ -340,7 +340,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker'
environment:
@@ -350,7 +350,7 @@ steps:
- tag
- name: executable
image: golang:1.23
image: golang:1.24.11
commands:
- ./release/linux/arm64/drone-docker --help
@@ -429,7 +429,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr'
environment:
@@ -440,7 +440,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr'
environment:
@@ -488,7 +488,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr'
environment:
@@ -499,7 +499,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr'
environment:
@@ -582,7 +582,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-gar ./cmd/drone-gar'
environment:
@@ -593,7 +593,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-gar ./cmd/drone-gar'
environment:
@@ -641,7 +641,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-gar ./cmd/drone-gar'
environment:
@@ -652,7 +652,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-gar ./cmd/drone-gar'
environment:
@@ -734,7 +734,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr'
environment:
@@ -744,7 +744,7 @@ steps:
exclude:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr'
environment:
@@ -792,7 +792,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr'
environment:
@@ -802,7 +802,7 @@ steps:
exclude:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr'
environment:
@@ -885,7 +885,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku'
environment:
@@ -895,7 +895,7 @@ steps:
exclude:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku'
environment:
@@ -944,7 +944,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku'
environment:
@@ -954,7 +954,7 @@ steps:
exclude:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku'
environment:
@@ -1035,7 +1035,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/amd64/drone-acr ./cmd/drone-acr'
environment:
@@ -1045,7 +1045,7 @@ steps:
exclude:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/amd64/drone-acr ./cmd/drone-acr'
environment:
@@ -1093,7 +1093,7 @@ platform:
steps:
- name: build-push
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm64/drone-acr ./cmd/drone-acr'
environment:
@@ -1104,7 +1104,7 @@ steps:
- tag
- name: build-tag
image: golang:1.23
image: golang:1.24.11
commands:
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm64/drone-acr ./cmd/drone-acr'
environment:
+4 -4
View File
@@ -33,7 +33,7 @@ pipeline:
identifier: Run_1
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: golang:1.23.0
image: golang:1.24.11
shell: Sh
command: go vet ./...
- step:
@@ -42,7 +42,7 @@ pipeline:
identifier: Run_2
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: golang:1.23.0
image: golang:1.24.11
shell: Sh
command: go test -cover ./...
- parallel:
@@ -70,7 +70,7 @@ pipeline:
identifier: Build_Push
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: golang:1.23.0
image: golang:1.24.11
shell: Sh
command: go build -a -tags netgo -o release/linux/amd64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
envVariables:
@@ -157,7 +157,7 @@ pipeline:
identifier: buildpush
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: golang:1.23.0
image: golang:1.24.11
shell: Sh
command: go build -a -tags netgo -o release/linux/arm64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
envVariables:
+12 -2
View File
@@ -17,8 +17,14 @@ import (
"github.com/inhies/go-bytesize"
)
// writeCard maintains backward compatibility by using TempTag
func (p Plugin) writeCard() error {
cmd := exec.Command(dockerExe, "inspect", p.Build.TempTag)
return p.writeCardForImage(p.Build.TempTag)
}
// writeCardForImage generates card for any image reference
func (p Plugin) writeCardForImage(imageRef string) error {
cmd := exec.Command(dockerExe, "inspect", imageRef)
data, err := cmd.CombinedOutput()
if err != nil {
return err
@@ -38,7 +44,11 @@ func (p Plugin) writeCard() error {
for _, tag := range inspect.RepoTags {
sliceTagStruct = append(sliceTagStruct, TagStruct{Tag: tag})
}
inspect.ParsedRepoTags = sliceTagStruct[1:] // remove the first tag which is always "hash:latest"
if len(sliceTagStruct) > 1 {
inspect.ParsedRepoTags = sliceTagStruct[1:] // remove the first tag which is always "hash:latest"
} else {
inspect.ParsedRepoTags = sliceTagStruct
}
// create the url from repo and registry
inspect.URL = mapRegistryToURL(p.Daemon.Registry, p.Build.Repo)
cardData, _ := json.Marshal(inspect)
+20 -1
View File
@@ -33,7 +33,7 @@ func main() {
cli.BoolFlag{
Name: "dry-run",
Usage: "dry run disables docker push",
EnvVar: "PLUGIN_DRY_RUN",
EnvVar: "PLUGIN_DRY_RUN, PLUGIN_NO_PUSH",
},
cli.StringFlag{
Name: "remote.url",
@@ -112,6 +112,12 @@ func main() {
Usage: "don't start the docker daemon",
EnvVar: "PLUGIN_DAEMON_OFF",
},
cli.IntFlag{
Name: "daemon.retry-count",
Usage: "number of retry attempts to reach docker daemon",
Value: 15,
EnvVar: "PLUGIN_DAEMON_RETRY_COUNT",
},
cli.StringFlag{
Name: "dockerfile",
Usage: "build dockerfile",
@@ -339,6 +345,16 @@ func main() {
Usage: "additional cosign parameters (e.g., annotations, flags)",
EnvVar: "PLUGIN_COSIGN_PARAMS",
},
cli.BoolFlag{
Name: "push-only",
Usage: "skip build and only push images",
EnvVar: "PLUGIN_PUSH_ONLY",
},
cli.StringFlag{
Name: "source-image",
Usage: "source image to tag and push (format: repo:tag)",
EnvVar: "PLUGIN_SOURCE_IMAGE",
},
}
if err := app.Run(os.Args); err != nil {
@@ -409,6 +425,7 @@ func run(c *cli.Context) error {
DNSSearch: c.StringSlice("daemon.dns-search"),
MTU: c.String("daemon.mtu"),
Experimental: c.Bool("daemon.experimental"),
RetryCount: c.Int("daemon.retry-count"),
RegistryType: registryType,
},
BaseImageRegistry: c.String("docker.baseimageregistry"),
@@ -419,6 +436,8 @@ func run(c *cli.Context) error {
Password: c.String("cosign.password"),
Params: c.String("cosign.params"),
},
PushOnly: c.Bool("push-only"),
SourceImage: c.String("source-image"),
}
if c.Bool("tags.auto") {
+215 -8
View File
@@ -30,6 +30,7 @@ type (
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
RetryCount int // Number of retry attempts to reach Docker daemon
RegistryType drone.RegistryType // Docker registry type
}
@@ -96,6 +97,8 @@ type (
BaseImageRegistry string // Docker registry to pull base image
BaseImageUsername string // Docker registry username to pull base image
BaseImagePassword string // Docker registry password to pull base image
PushOnly bool // Push only mode, skips build process
SourceImage string // Source image to push (optional)
}
Card []struct {
@@ -135,14 +138,18 @@ func (p Plugin) Exec() error {
// poll the docker daemon until it is started. This ensures the daemon is
// ready to accept connections before we proceed.
maxRetries := p.Daemon.RetryCount
if maxRetries <= 0 {
maxRetries = 15 // default value
}
for i := 0; ; i++ {
cmd := commandInfo()
err := cmd.Run()
if err == nil {
break
}
if i == 15 {
fmt.Println("Unable to reach Docker Daemon after 15 attempts.")
if i == maxRetries {
fmt.Printf("Unable to reach Docker Daemon after %d attempts.\n", maxRetries)
break
}
time.Sleep(time.Second * 1)
@@ -201,7 +208,8 @@ func (p Plugin) Exec() error {
fmt.Println(out)
return fmt.Errorf("Error authenticating base connector: exit status 1")
}
} else {
} else if !p.PushOnly {
// Skip base image connector warning in push-only mode (not pulling anything)
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
}
@@ -229,6 +237,16 @@ func (p Plugin) Exec() error {
}
}
// Enforce mutual exclusivity: push-only and dry-run cannot be used together
if p.PushOnly && p.Dryrun {
return fmt.Errorf("conflict: push-only and dry-run cannot be used together")
}
// Handle push-only mode if requested
if p.PushOnly {
return p.pushOnly()
}
if p.Build.Squash && !p.Daemon.Experimental {
fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...")
p.Build.Squash = false
@@ -579,7 +597,8 @@ func addProxyValue(build *Build, key string) {
// helper function to get a proxy value from the environment.
//
// assumes that the upper and lower case versions of are the same.
// Checks in order: lowercase key, uppercase key, then HARNESS_<UPPERCASE_KEY>.
// Assumes that the upper and lower case versions are the same value.
func getProxyValue(key string) string {
value := os.Getenv(key)
@@ -587,15 +606,26 @@ func getProxyValue(key string) string {
return value
}
return os.Getenv(strings.ToUpper(key))
value = os.Getenv(strings.ToUpper(key))
if len(value) > 0 {
return value
}
harnessValue := os.Getenv("HARNESS_" + strings.ToUpper(key))
if len(harnessValue) > 0 {
fmt.Printf("Using HARNESS_%s as proxy value for %s\n", strings.ToUpper(key), key)
}
return harnessValue
}
// helper function that looks to see if a proxy value was set in the build args.
func hasProxyBuildArg(build *Build, key string) bool {
keyUpper := strings.ToUpper(key)
harnessKey := "HARNESS_" + keyUpper
for _, s := range build.Args {
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) {
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) || strings.HasPrefix(s, harnessKey) {
return true
}
}
@@ -604,9 +634,10 @@ func hasProxyBuildArg(build *Build, key string) bool {
}
func hasProxyBuildArgNew(build *Build, key string) bool {
keyUpper := strings.ToUpper(key)
harnessKey := "HARNESS_" + keyUpper
for _, s := range build.ArgsNew {
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) {
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) || strings.HasPrefix(s, harnessKey) {
return true
}
}
@@ -742,6 +773,22 @@ func getDigest(buildName string) (string, error) {
return "", errors.New("unable to fetch digest")
}
// imageExists checks if an image exists in local daemon
func imageExists(tag string) bool {
cmd := exec.Command(dockerExe, "image", "inspect", tag)
return cmd.Run() == nil
}
// getDigestAfterPush gets digest from a pushed image
func getDigestAfterPush(tag string) (string, error) {
cmd := exec.Command(dockerExe, "inspect", "--format", "{{ index (split (index .RepoDigests 0) \"@\") 1 }}", tag)
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to get digest for %s: %w", tag, err)
}
return strings.TrimSpace(string(output)), nil
}
// shouldSignWithCosign determines if cosign signing should be performed
func (p Plugin) shouldSignWithCosign() bool {
return p.Cosign.PrivateKey != ""
@@ -837,7 +884,7 @@ func executeCosignCommand(cmd *exec.Cmd) {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
fmt.Printf("🚀 Executing: %s %s\n", cmd.Path, strings.Join(cmd.Args[1:], " "))
if err := cmd.Run(); err != nil {
fmt.Printf("⚠️ WARNING: Image signing failed: %s\n", err)
fmt.Printf(" Image was pushed successfully but could not be signed\n")
@@ -845,4 +892,164 @@ func executeCosignCommand(cmd *exec.Cmd) {
}
}
// pushOnly handles pushing images without building them
func (p Plugin) pushOnly() error {
// Check if source image is specified
sourceImageName := p.SourceImage
var sourceTags []string
if sourceImageName == "" {
// If no source image specified, use the repo and first tag
fmt.Println("source_image not provided, using repo and tag value")
sourceImageName = p.Build.Repo
sourceTags = p.Build.Tags
} else {
// If source image is specified, check if it has a tag
lastColonIndex := strings.LastIndex(sourceImageName, ":")
if lastColonIndex > 0 && lastColonIndex < len(sourceImageName) {
// Check if there's a slash after the last colon (indicating it's a port, not a tag)
// For example: registry:5000/image (has slash after colon - port not tag)
// vs image:tag (no slash after colon - it's a tag)
if strings.LastIndex(sourceImageName, "/") > lastColonIndex {
// The last colon is part of the registry:port, not a tag separator
sourceTags = []string{"latest"}
} else {
// The last colon separates the tag
tag := sourceImageName[lastColonIndex+1:]
sourceImageName = sourceImageName[:lastColonIndex]
if tag == "" {
fmt.Printf("No tag specified in source image (or empty tag). Using 'latest' as the default tag.\n")
tag = "latest"
}
sourceTags = []string{tag}
}
} else {
// Default to "latest" if no tag specified
sourceTags = []string{"latest"}
}
fmt.Printf("Using source image: %s with tag(s): %s\n", sourceImageName, strings.Join(sourceTags, ", "))
}
// For each source tag and target tag combination
var digest string
var firstPushedImage string
for _, sourceTag := range sourceTags {
sourceFullImageName := fmt.Sprintf("%s:%s", sourceImageName, sourceTag)
// Check if the source image exists in local daemon
if !imageExists(sourceFullImageName) {
fmt.Printf("Warning: Source image %s not found\n", sourceFullImageName)
// Continue to the next source tag if available, otherwise return error
if len(sourceTags) > 1 {
continue
}
return fmt.Errorf("source image %s not found, cannot push", sourceFullImageName)
}
// For each target tag, tag and push
for _, targetTag := range p.Build.Tags {
targetFullImageName := fmt.Sprintf("%s:%s", p.Build.Repo, targetTag)
// Skip if source and target are identical
if sourceFullImageName == targetFullImageName {
fmt.Printf("Source and target image names are identical: %s\n", sourceFullImageName)
} else {
// Tag the source image with the target name
fmt.Printf("Tagging %s as %s\n", sourceFullImageName, targetFullImageName)
tagCmd := exec.Command(dockerExe, "tag", sourceFullImageName, targetFullImageName)
tagCmd.Stdout = os.Stdout
tagCmd.Stderr = os.Stderr
trace(tagCmd)
if err := tagCmd.Run(); err != nil {
return fmt.Errorf("failed to tag image %s as %s: %w", sourceFullImageName, targetFullImageName, err)
}
}
}
}
// Push all target images
for _, tag := range p.Build.Tags {
fullImageName := fmt.Sprintf("%s:%s", p.Build.Repo, tag)
// Check if image exists in local daemon
if !imageExists(fullImageName) {
return fmt.Errorf("image %s not found, cannot push", fullImageName)
}
// Push image
fmt.Println("Pushing image:", fullImageName)
pushCmd := commandPush(p.Build, tag)
pushCmd.Stdout = os.Stdout
pushCmd.Stderr = os.Stderr
trace(pushCmd)
if err := pushCmd.Run(); err != nil {
return fmt.Errorf("failed to push image %s: %w", fullImageName, err)
}
// Track the first pushed image for card generation
if firstPushedImage == "" {
firstPushedImage = fullImageName
}
// Get the digest after push (we only need one)
if digest == "" {
d, err := getDigestAfterPush(fullImageName)
if err == nil {
digest = d
} else {
fmt.Printf("Warning: Could not get digest for %s: %v\n", fullImageName, err)
}
}
}
// Output the adaptive card
if firstPushedImage != "" {
if err := p.writeCardForImage(firstPushedImage); err != nil {
fmt.Printf("Could not create adaptive card. %s\n", err)
}
}
// Write to artifact file
if p.ArtifactFile != "" && digest != "" {
if err := drone.WritePluginArtifactFile(
p.Daemon.RegistryType,
p.ArtifactFile,
p.Daemon.Registry,
p.Build.Repo,
digest,
p.Build.Tags,
); err != nil {
fmt.Printf("Failed to write plugin artifact file at path: %s with error: %s\n",
p.ArtifactFile, err)
}
}
// Handle cosign signing after push
if p.shouldSignWithCosign() {
// Set up environment variables for cosign
os.Setenv("COSIGN_YES", "true")
if digest != "" {
fmt.Printf("🔐 Found image digest: %s\n", digest)
// Sign with digest reference
imageRef := fmt.Sprintf("%s@%s", p.Build.Repo, digest)
cosignCmd := createCosignCommand(imageRef, p.Cosign)
executeCosignCommand(cosignCmd)
} else {
fmt.Printf("⚠️ WARNING: Could not get image digest for cosign signing\n")
fmt.Printf(" Falling back to tag-based signing\n")
// Fall back to tag-based signing for each tag
for _, tag := range p.Build.Tags {
imageRef := fmt.Sprintf("%s:%s", p.Build.Repo, tag)
cosignCmd := createCosignCommand(imageRef, p.Cosign)
executeCosignCommand(cosignCmd)
}
}
}
return nil
}
+88
View File
@@ -1,6 +1,7 @@
package docker
import (
"os"
"os/exec"
"reflect"
"strings"
@@ -179,3 +180,90 @@ func TestCommandBuild(t *testing.T) {
})
}
}
func TestGetProxyValue(t *testing.T) {
tests := []struct {
name string
key string
envVars map[string]string
expected string
}{
{
name: "lowercase env var set",
key: "http_proxy",
envVars: map[string]string{"http_proxy": "http://proxy:8080"},
expected: "http://proxy:8080",
},
{
name: "uppercase env var set",
key: "http_proxy",
envVars: map[string]string{"HTTP_PROXY": "http://proxy:8080"},
expected: "http://proxy:8080",
},
{
name: "HARNESS prefixed env var set",
key: "http_proxy",
envVars: map[string]string{"HARNESS_HTTP_PROXY": "http://harness-proxy:8080"},
expected: "http://harness-proxy:8080",
},
{
name: "standard takes precedence over HARNESS",
key: "http_proxy",
envVars: map[string]string{
"HTTP_PROXY": "http://standard:8080",
"HARNESS_HTTP_PROXY": "http://harness:8080",
},
expected: "http://standard:8080",
},
{
name: "lowercase takes precedence over uppercase",
key: "no_proxy",
envVars: map[string]string{
"no_proxy": "localhost,127.0.0.1",
"NO_PROXY": "*.example.com",
"HARNESS_NO_PROXY": "*.local",
},
expected: "localhost,127.0.0.1",
},
{
name: "lowercase takes precedence over HARNESS",
key: "https_proxy",
envVars: map[string]string{
"https_proxy": "https://standard:8080",
"HARNESS_HTTPS_PROXY": "https://harness:8080",
},
expected: "https://standard:8080",
},
{
name: "no env var set",
key: "http_proxy",
envVars: map[string]string{},
expected: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Clean env
lowercaseKey := tt.key
uppercaseKey := strings.ToUpper(tt.key)
harnessKey := "HARNESS_" + strings.ToUpper(tt.key)
os.Unsetenv(lowercaseKey)
os.Unsetenv(uppercaseKey)
os.Unsetenv(harnessKey)
// Set test environment variables
for k, v := range tt.envVars {
os.Setenv(k, v)
defer os.Unsetenv(k)
}
// Execute and verify
result := getProxyValue(tt.key)
if result != tt.expected {
t.Errorf("getProxyValue(%q) = %q, want %q", tt.key, result, tt.expected)
}
})
}
}
+3 -3
View File
@@ -11,7 +11,7 @@ require (
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743
github.com/joho/godotenv v1.3.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
github.com/urfave/cli v1.22.2
golang.org/x/oauth2 v0.27.0
@@ -48,6 +48,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
go 1.23.0
go 1.24
toolchain go1.23.7
toolchain go1.24.11
+2 -2
View File
@@ -108,8 +108,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=