Skip to content

Commit b910390

Browse files
Default kiln test to docker-virtual Artifactory path
Remove --broadcom-proxy. The embedded Dockerfile pins FROM lines on\ntas-rel-eng-docker-virtual and sets GOPROXY/GOSUMDB from ARTIFACTORY\nbuild args. Kiln always requires ARTIFACTORY_USERNAME and\nARTIFACTORY_PASSWORD, passes them as the only ImageBuild build args,\nand sends AuthConfigs for DockerVirtualRegistryHost so pulls work\nwithout docker login. Retains quiet image build output and the\nContainerWait(next-exit) fix for AutoRemove. ai-assisted=yes Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f6930c9 commit b910390

7 files changed

Lines changed: 325 additions & 62 deletions

File tree

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -520,56 +520,65 @@ Any variables that Kilnfile needs for the kiln re-bake command should be set in
520520

521521
### `test`
522522

523-
The `test` command exercises to ginkgo tests under the `/<tile>/test/manifest` and `/<tile>/migrations` paths of the `pivotal/tas` repos (where `<tile>` is tas, ist, or tasw).
523+
The `test` command exercises the Ginkgo tests under the `/<tile>/test/manifest` and `/<tile>/migrations` paths of the `pivotal/tas` repos (where `<tile>` is tas, ist, or tasw).
524524

525-
Running these tests requires a docker daemon. It also requires the user to
526-
provide Artifactory credentials via the ARTIFACTORY_USERNAME and
527-
ARTIFACTORY_PASSWORD environment variables to allow the ops-manifest gem to
528-
be installed. The credentials must have access to the `tas-rel-eng-gem-dev-local`
529-
repository within Broadcom's Artifactory.
525+
Running these tests requires a Docker daemon (or Podman API-compatible socket). You must provide **ARTIFACTORY_USERNAME** and **ARTIFACTORY_PASSWORD** using **`-e`** and/or **exported** environment variables. They are used for the **ops-manifest** gem (`tas-rel-eng-gem-dev-local`), for **Go module** downloads during **`go install ginkgo`** (via **`GOPROXY`** / **`GOSUMDB=off`** in the embedded Dockerfile), and Kiln sends the same credentials to the daemon as **registry auth** so base images can be pulled from **docker-virtual** (`tas-rel-eng-docker-virtual.usw1.packages.broadcom.com`) **without a separate `docker login`** for `kiln test`.
526+
527+
The embedded Dockerfile pins **`FROM`** paths on that registry. The registry hostname in Kiln’s **`AuthConfigs`** must stay aligned with those **`FROM`** lines (see **`DockerVirtualRegistryHost`** in `internal/test/container.go`). Passwords with characters that are special in URLs may not behave the same as URL-encoded credentials when interpolated into **`GOPROXY`** inside the Dockerfile.
528+
529+
If either credential is missing, `kiln test` exits with an error before talking to Docker.
530530

531531
If you run into this docker error `could not execute "test": failed to connect to Docker daemon: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running`,
532532
then create a symlink `sudo ln -s ~/.docker/run/docker.sock /var/run/docker.sock`
533533

534-
Here are command line examples:
534+
Examples:
535535

536536
```
537537
$ cd ~/workspace/tas/ist
538538
$ kiln test -e ARTIFACTORY_USERNAME=myuser -e ARTIFACTORY_PASSWORD=secretpassword
539539
```
540540

541541
```
542-
cd ~
543-
$ kiln test --verbose -tp ~/workspace/tas/ist --ginkgo-manifest-flags "-p -nodes 8 -v"
542+
$ export ARTIFACTORY_USERNAME=myuser
543+
$ export ARTIFACTORY_PASSWORD=secretpassword
544+
$ kiln test --verbose -tp ~/workspace/tas/ist --ginkgo-flags "-p -nodes 8 -v"
544545
```
545546

546547
<details>
547548
<summary>Additional test options</summary>
548549

549-
##### `--ginkgo-manifest-flags`
550+
##### `--ginkgo-flags`
551+
552+
The `--ginkgo-flags` flag can be used to pass through Ginkgo test flags. The defaults being passed through are `-r -p -slowSpecThreshold 15`. Pass `help` as a flag to retrieve the available options for the embedded version of ginkgo.
550553

551-
The `--ginkgo-manifest-flags` flag can be used to pass through Ginkgo test flags. The defaults being passed through are `-r -p -slowSpecThreshold 15`. Pass `help` as a flag to retrieve the available options for the embeded version of ginkgo.
554+
#### `--manifest`
552555

553-
#### `--manifest-only`
556+
The `--manifest` flag can be used to run only Manifest tests.
554557

555-
The `--manifest-only` flag can be used to run only Manifest tests. If not passed, `kiln test` will run both Manifest and Migration tests by default.
558+
#### `--migrations`
556559

557-
#### `--migrations-only`
560+
The `--migrations` flag can be used to run only Migration tests.
558561

559-
The `--migrations-only` flag can be used to run only Migration tests. If not passed, `kiln test` will run both Manifest and Migration tests by default.
562+
#### `--stability`
563+
564+
The `--stability` flag can be used to run only Stability tests.
560565

561566
##### `--tile-path`
562567

563-
The `--tile-path` (`-tp`) flag can be set the path the directory you wish to test. It defaults to the current working directory. For example
568+
The `--tile-path` (`-tp`) flag can be set to the directory you wish to test. It defaults to the current working directory. For example:
564569

565570
```
566-
$ kiln test -tp ~/workspace/tas/ist
571+
$ kiln test -e ARTIFACTORY_USERNAME=myuser -e ARTIFACTORY_PASSWORD=secret -tp ~/workspace/tas/ist
567572
```
568573

569574
##### `--verbose`
570575

571576
The `--verbose` (`-v`) flag will log additional debugging info.
572577

578+
##### `--silent`
579+
580+
The `--silent` (`-s`) flag hides Kiln info lines (not Ginkgo output).
581+
573582
</details>
574583

575584
### `fetch`

internal/commands/test_tile.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ type TileTestFunction func(ctx context.Context, w io.Writer, configuration test.
1717

1818
type TileTest struct {
1919
Options struct {
20-
TilePath string ` long:"tile-path" default:"." description:"Path to the Tile directory (e.g., ~/workspace/tas/ist)."`
20+
TilePath string ` long:"tile-path" default:"." description:"Path to the Tile directory (e.g. ~/workspace/tas/ist)."`
2121
Verbose bool `short:"v" long:"verbose" default:"true" description:"Print info lines. This doesn't affect Ginkgo output."`
2222
Silent bool `short:"s" long:"silent" default:"false" description:"Hide info lines. This doesn't affect Ginkgo output."`
2323
Manifest bool ` long:"manifest" default:"false" description:"Focus the Manifest tests."`
2424
Migrations bool ` long:"migrations" default:"false" description:"Focus the Migration tests."`
2525
Stability bool ` long:"stability" default:"false" description:"Focus the Stability tests."`
2626

27-
EnvironmentVars []string `short:"e" long:"environment-variable" description:"Pass environment variable to the test suites. For example --stability -e 'PRODUCT=srt'."`
27+
EnvironmentVars []string `short:"e" long:"environment-variable" description:"Pass environment variables to the test suites (e.g. -e 'PRODUCT=srt'). Include -e ARTIFACTORY_USERNAME=... and -e ARTIFACTORY_PASSWORD=... unless they are exported."`
2828
GingkoFlags string ` long:"ginkgo-flags" default:"-r -p -slowSpecThreshold 15" description:"Flags to pass to the Ginkgo Manifest and Stability test suites."`
2929
}
3030
function TileTestFunction
@@ -64,7 +64,10 @@ func (cmd TileTest) configuration() (test.Configuration, error) {
6464
if _, err := os.Stat(absPath); err != nil {
6565
return test.Configuration{}, fmt.Errorf("failed to get information about --tile-path: %w", err)
6666
}
67-
return test.Configuration{
67+
if _, _, err := test.RequiredArtifactoryCredentials(cmd.Options.EnvironmentVars); err != nil {
68+
return test.Configuration{}, err
69+
}
70+
cfg := test.Configuration{
6871
AbsoluteTileDirectory: absPath,
6972

7073
RunAll: !cmd.Options.Migrations && !cmd.Options.Manifest && !cmd.Options.Stability,
@@ -74,12 +77,13 @@ func (cmd TileTest) configuration() (test.Configuration, error) {
7477

7578
GinkgoFlags: cmd.Options.GingkoFlags,
7679
Environment: cmd.Options.EnvironmentVars,
77-
}, absErr
80+
}
81+
return cfg, absErr
7882
}
7983

8084
func (cmd TileTest) Usage() jhanda.Usage {
8185
return jhanda.Usage{
82-
Description: "Run the Manifest, Migrations, and Stability tests for a Tile in a Docker container. Requires a Docker daemon to be running and Artifactory credentials to be provided via the ARTIFACTORY_USERNAME and ARTIFACTORY_PASSWORD environment variables to install the ops-manifest gem.",
86+
Description: "Run the Manifest, Migrations, and Stability tests for a Tile in a Docker container. Requires a Docker daemon. Requires ARTIFACTORY_USERNAME and ARTIFACTORY_PASSWORD (via -e or your environment) for the test image build and ops-manifest gem. Kiln passes the same credentials to the Docker daemon for pulling base images from docker-virtual (no separate docker login needed for kiln test).",
8387
ShortDescription: "Runs unit tests for a Tile.",
8488
Flags: cmd.Options,
8589
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package commands
2+
3+
import (
4+
"context"
5+
"io"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/pivotal-cf/kiln/internal/test"
11+
)
12+
13+
func TestTileTest_RequiresArtifactoryCredentials(t *testing.T) {
14+
t.Setenv("ARTIFACTORY_USERNAME", "")
15+
t.Setenv("ARTIFACTORY_PASSWORD", "")
16+
17+
err := NewTileTest().Execute([]string{})
18+
require.Error(t, err)
19+
require.ErrorContains(t, err, "ARTIFACTORY_USERNAME")
20+
require.ErrorContains(t, err, "kiln test")
21+
}
22+
23+
func TestTileTest_RequiresArtifactoryPassword(t *testing.T) {
24+
t.Setenv("ARTIFACTORY_PASSWORD", "")
25+
26+
err := NewTileTest().Execute([]string{"-e", "ARTIFACTORY_USERNAME=onlyuser"})
27+
require.Error(t, err)
28+
require.ErrorContains(t, err, "ARTIFACTORY_PASSWORD")
29+
}
30+
31+
func TestTileTest_PassesArtifactoryViaEnvironmentToConfiguration(t *testing.T) {
32+
var captured test.Configuration
33+
stub := func(_ context.Context, _ io.Writer, c test.Configuration) error {
34+
captured = c
35+
return nil
36+
}
37+
err := NewTileTestWithCollaborators(io.Discard, stub).Execute([]string{
38+
"-e", "ARTIFACTORY_USERNAME=u",
39+
"-e", "ARTIFACTORY_PASSWORD=p",
40+
})
41+
require.NoError(t, err)
42+
require.Contains(t, captured.Environment, "ARTIFACTORY_USERNAME=u")
43+
require.Contains(t, captured.Environment, "ARTIFACTORY_PASSWORD=p")
44+
}
45+
46+
func TestTileTest_UsesProcessEnvArtifactoryCredentials(t *testing.T) {
47+
t.Setenv("ARTIFACTORY_USERNAME", "fromenv")
48+
t.Setenv("ARTIFACTORY_PASSWORD", "frompass")
49+
50+
var captured test.Configuration
51+
stub := func(_ context.Context, _ io.Writer, c test.Configuration) error {
52+
captured = c
53+
return nil
54+
}
55+
err := NewTileTestWithCollaborators(io.Discard, stub).Execute([]string{})
56+
require.NoError(t, err)
57+
require.Empty(t, captured.Environment)
58+
}

internal/commands/test_tile_test.go

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ func init() {
3434
var _ = Describe("kiln test", func() {
3535
var output bytes.Buffer
3636

37+
BeforeEach(func() {
38+
t := GinkgoT()
39+
t.Setenv("ARTIFACTORY_USERNAME", "ginkgo-test-user")
40+
t.Setenv("ARTIFACTORY_PASSWORD", "ginkgo-test-pass")
41+
})
42+
3743
AfterEach(func() {
3844
output.Reset()
3945
})
@@ -210,9 +216,9 @@ var _ = Describe("kiln test", func() {
210216
})
211217
})
212218

213-
When("when the stability test is enabled", func() {
214-
It("it sets the RunMetadata configuration flag", func() {
215-
args := []string{"--stability"}
219+
When("when ginkgo/v2 flag arguments are passed", func() {
220+
It("it sets the GinkgoFlags configuration", func() {
221+
args := []string{"--ginkgo-flags=peach pair"}
216222

217223
fakeTestFunc := fakes.TestTileFunction{}
218224
fakeTestFunc.Returns(nil)
@@ -226,29 +232,55 @@ var _ = Describe("kiln test", func() {
226232
Expect(ctx).NotTo(BeNil())
227233
Expect(w).NotTo(BeNil())
228234

229-
Expect(configuration.RunManifest).To(BeFalse())
230-
Expect(configuration.RunMetadata).To(BeTrue())
231-
Expect(configuration.RunMigrations).To(BeFalse())
235+
Expect(configuration.GinkgoFlags).To(Equal("peach pair"))
232236
})
233237
})
234238

235-
When("when ginkgo/v2 flag arguments are passed", func() {
236-
It("it sets the GinkgoFlags configuration", func() {
237-
args := []string{"--ginkgo-flags=peach pair"}
239+
When("when Artifactory credentials are provided via -e", func() {
240+
It("invokes the test function with those variables in Environment", func() {
241+
args := []string{
242+
"-e", "ARTIFACTORY_USERNAME=u",
243+
"-e", "ARTIFACTORY_PASSWORD=p",
244+
}
238245

239246
fakeTestFunc := fakes.TestTileFunction{}
240247
fakeTestFunc.Returns(nil)
241248

242249
err := commands.NewTileTestWithCollaborators(&output, fakeTestFunc.Spy).Execute(args)
243250
Expect(err).NotTo(HaveOccurred())
244251

245-
Expect(fakeTestFunc.CallCount()).To(Equal(1))
252+
_, _, configuration := fakeTestFunc.ArgsForCall(0)
253+
Expect(configuration.Environment).To(ContainElement("ARTIFACTORY_USERNAME=u"))
254+
Expect(configuration.Environment).To(ContainElement("ARTIFACTORY_PASSWORD=p"))
255+
})
256+
})
246257

247-
ctx, w, configuration := fakeTestFunc.ArgsForCall(0)
248-
Expect(ctx).NotTo(BeNil())
249-
Expect(w).NotTo(BeNil())
258+
When("when Artifactory credentials are missing", func() {
259+
It("returns an error before invoking the test function", func() {
260+
savedU, hasU := os.LookupEnv("ARTIFACTORY_USERNAME")
261+
savedP, hasP := os.LookupEnv("ARTIFACTORY_PASSWORD")
262+
DeferCleanup(func() {
263+
if hasU {
264+
Expect(os.Setenv("ARTIFACTORY_USERNAME", savedU)).To(Succeed())
265+
} else {
266+
Expect(os.Unsetenv("ARTIFACTORY_USERNAME")).To(Succeed())
267+
}
268+
if hasP {
269+
Expect(os.Setenv("ARTIFACTORY_PASSWORD", savedP)).To(Succeed())
270+
} else {
271+
Expect(os.Unsetenv("ARTIFACTORY_PASSWORD")).To(Succeed())
272+
}
273+
})
274+
Expect(os.Unsetenv("ARTIFACTORY_USERNAME")).To(Succeed())
275+
Expect(os.Unsetenv("ARTIFACTORY_PASSWORD")).To(Succeed())
250276

251-
Expect(configuration.GinkgoFlags).To(Equal("peach pair"))
277+
fakeTestFunc := fakes.TestTileFunction{}
278+
fakeTestFunc.Returns(nil)
279+
280+
err := commands.NewTileTestWithCollaborators(&output, fakeTestFunc.Spy).Execute([]string{})
281+
Expect(err).To(HaveOccurred())
282+
Expect(err.Error()).To(ContainSubstring("ARTIFACTORY_USERNAME"))
283+
Expect(fakeTestFunc.CallCount()).To(Equal(0))
252284
})
253285
})
254286

internal/test/Dockerfile

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
FROM golang AS go-image
2-
FROM docker.io/pivotalcfreleng/kiln:v0.110.0-rc2 AS kiln
1+
# Base images: host must match DockerVirtualRegistryHost in internal/test/container.go (AuthConfigs).
2+
FROM tas-rel-eng-docker-virtual.usw1.packages.broadcom.com/golang AS go-image
3+
FROM tas-rel-eng-docker-virtual.usw1.packages.broadcom.com/pivotalcfreleng/kiln:v0.110.0-rc2 AS kiln
34

4-
FROM ruby:3.4.8 AS builder
5+
FROM tas-rel-eng-docker-virtual.usw1.packages.broadcom.com/ruby:3.4.8 AS builder
56
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
67

7-
FROM ruby:3.4.8
8+
FROM tas-rel-eng-docker-virtual.usw1.packages.broadcom.com/ruby:3.4.8
89

910
# Install Go
1011
COPY --from=go-image /usr/local/go/ /usr/local/go/
@@ -17,19 +18,24 @@ COPY --from=kiln /kiln /usr/local/bin/kiln
1718
# Install JQ
1819
RUN apt-get update && apt-get install jq -y
1920

20-
# Install Ginkgo
21-
RUN go install github.com/onsi/ginkgo/ginkgo@latest
22-
23-
# Install NodeJS
24-
RUN apt-get update && apt-get install nodejs npm -y
25-
26-
# Install OpsManifest from Artifactory
2721
ARG ARTIFACTORY_USERNAME
2822
ARG ARTIFACTORY_PASSWORD
29-
3023
ENV ARTIFACTORY_USERNAME=${ARTIFACTORY_USERNAME}
3124
ENV ARTIFACTORY_PASSWORD=${ARTIFACTORY_PASSWORD}
3225

26+
# Install Ginkgo (module download via Artifactory Go virtual; credentials from build args).
27+
ARG GOTOOLCHAIN=local
28+
ENV GOTOOLCHAIN=${GOTOOLCHAIN}
29+
ENV GOPROXY=https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_PASSWORD}@usw1.packages.broadcom.com/artifactory/api/go/tas-rel-eng-go-virtual
30+
ENV GOSUMDB=off
31+
# Pure-Go install; avoid invoking gcc. On linux/arm64 (e.g. Podman on Apple Silicon),
32+
# cgo can fail with: gcc: error: unrecognized command-line option '-m64'.
33+
ENV CGO_ENABLED=0
34+
RUN go install github.com/onsi/ginkgo/ginkgo@latest
35+
36+
# Install NodeJS
37+
RUN apt-get update && apt-get install nodejs npm -y
38+
3339
RUN gem source -a https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_PASSWORD}@usw1.packages.broadcom.com/artifactory/api/gems/tas-rel-eng-gem-dev-local/
3440
RUN gem install --verbose ops-manifest -v 0.0.4.pre
3541

0 commit comments

Comments
 (0)