Skip to content

Commit

Permalink
chore:add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
alphanota committed Jan 16, 2025
1 parent ae699c0 commit 0b19012
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
29 changes: 29 additions & 0 deletions integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/runner/runcontext"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util"
"github.com/GoogleContainerTools/skaffold/v2/testutil"
"k8s.io/apimachinery/pkg/util/wait"
)

const imageName = "us-central1-docker.pkg.dev/k8s-skaffold/testing/simple-build:"
Expand Down Expand Up @@ -331,3 +332,31 @@ func failNowIfError(t Fataler, err error) {
t.Fatal(err)
}
}

func TestRunWithDockerAndBuildArgs(t *testing.T) {
tests := []struct {
description string
projectDir string
}{
{
description: "IMAGE_REPO, IMAGE_TAG, and IMAGE_NAME are passed to the docker build args",
projectDir: "testdata/docker-run-with-build-args",
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {

Check failure on line 348 in integration/build_test.go

View workflow job for this annotation

GitHub Actions / PR linters, checks

unnecessary leading newline (whitespace)

skaffold.Build().InDir(test.projectDir).Run(t.T)

defer skaffold.Delete().InDir(test.projectDir).Run(t.T)
expected := "IMAGE_REPO: gcr.io/k8s-skaffold, IMAGE_NAME: skaffold, IMAGE_TAG:latest"

err := wait.PollImmediate(time.Millisecond*500, 1*time.Minute, func() (bool, error) {
out, _ := exec.Command("docker", "run", "child:latest").Output()
return string(out) == expected, nil
})
failNowIfError(t, err)
})
}
}
11 changes: 11 additions & 0 deletions integration/testdata/docker-run-with-build-args/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.23 as builder
WORKDIR /code
COPY main.go .
COPY go.mod .
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
ARG IMAGE_REPO
ARG IMAGE_NAME
ARG IMAGE_TAG
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -ldflags="-X main.ImageRepo=${IMAGE_REPO} -X main.ImageName=${IMAGE_NAME} -X main.ImageTag=${IMAGE_TAG}" -trimpath -o /app main.go

3 changes: 3 additions & 0 deletions integration/testdata/docker-run-with-build-args/base/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/GoogleContainerTools/skaffold/examples/docker-deploy-with-build-args/base

go 1.23
13 changes: 13 additions & 0 deletions integration/testdata/docker-run-with-build-args/base/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
)

var ImageRepo = "unknown"
var ImageTag = "unknown"
var ImageName = "unknown"

func main() {
fmt.Printf("IMAGE_REPO: %s, IMAGE_NAME: %s, IMAGE_TAG:%s", ImageRepo, ImageName, ImageTag)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG BASE
FROM $BASE as parent
FROM alpine
COPY --from=parent /app .
CMD ["./app"]
29 changes: 29 additions & 0 deletions integration/testdata/docker-run-with-build-args/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: skaffold/v4beta12
kind: Config
build:
tagPolicy:
sha256: {}
local:
push: false
useDockerCLI: true
artifacts:
- image: gcr.io/k8s-skaffold/skaffold
context: base
docker:
dockerfile: Dockerfile
noCache: true
buildArgs:
IMAGE_REPO: '{{.IMAGE_REPO}}'
IMAGE_NAME: '{{.IMAGE_NAME}}'
IMAGE_TAG: '{{.IMAGE_TAG}}'
- image: child
requires:
- image: gcr.io/k8s-skaffold/skaffold
alias: BASE
context: child
docker:
dockerfile: Dockerfile
noCache: true
deploy:
docker:
images: [child]

0 comments on commit 0b19012

Please sign in to comment.