Skip to content

Commit 1ed09b9

Browse files
authored
Merge pull request #1384 from cloudfoundry/fbsb-docker-app
Docker test for file-based service bindings
2 parents 99633fa + 8ec1584 commit 1ed09b9

File tree

9 files changed

+116
-2
lines changed

9 files changed

+116
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Create and publish a Docker image with the "catnip" app
2+
3+
on:
4+
push:
5+
branches: ['develop']
6+
paths:
7+
- 'assets/catnip/**'
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: cloudfoundry/catnip-app
12+
13+
jobs:
14+
build-and-push-image:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
id-token: write
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
- name: Log in to the Container registry
24+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
25+
with:
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Build and push Docker image
30+
id: push
31+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
32+
with:
33+
context: ./assets/catnip/
34+
file: ./assets/catnip/Dockerfile
35+
push: true
36+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ include_app_syslog_tcp
111111
* `include_app_syslog_tcp`: Flag to include the app syslog drain over TCP test group.
112112
* `include_apps`: Flag to include the apps test group.
113113
* `readiness_health_checks_enabled`: Defaults to `true`. Set to false if you are using an environment without readiness health checks.
114-
* `include_cnb`: Flag to include tests related to building apps using Cloud Native Buildpacks. Diego must be deployed and the CC API diego_cnb feature flag must be enabled for these tests to pass.
114+
* `include_cnb`: Flag to include tests related to building apps using Cloud Native Buildpacks. Diego must be deployed and the CC API diego_cnb feature flag must be enabled for these tests to pass. The CF CLI version must be at least v8.9.0.
115115
* `include_container_networking`: Flag to include tests related to container networking.
116116
* `credhub_mode`: Valid values are `assisted` or `non-assisted`. [See below](#credhub-modes).
117117
* `credhub_location`: Location of CredHub instance; default is `https://credhub.service.cf.internal:8844`
@@ -359,7 +359,7 @@ Test Group Name| Description
359359
`cnb` | Tests our ability to use cloud native buildpacks.
360360
`detect` | Tests the ability of the platform to detect the correct buildpack for compiling an application if no buildpack is explicitly specified.
361361
`docker`| Tests our ability to run docker containers on Diego and that we handle docker metadata correctly.
362-
`file-based service bindings`| Tests file-based service bindings for a buildpack and a CNB app.
362+
`file-based service bindings`| Tests file-based service bindings for a buildpack app, a CNB app and a Docker app.
363363
`internet_dependent`| Tests the feature of being able to specify a buildpack via a Github URL. As such, this depends on your Cloud Foundry application containers having access to the Internet. You should take into account the configuration of the network into which you've deployed your Cloud Foundry, as well as any security group settings applied to application containers.
364364
`isolation_segments` | This test group requires that Diego be deployed with a minimum of 2 cells. One of those cells must have been deployed with a `placement_tag`. If the deployment has been deployed with a routing isolation segment, `isolation_segment_domain` must also be set. For more information, please refer to the [Isolation Segments documentation](https://docs.cloudfoundry.org/adminguide/isolation-segments.html).
365365
`route_services` | Tests the [Route Services](https://docs.cloudfoundry.org/services/route-services.html) feature of Cloud Foundry.

assets/catnip/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM golang
2+
WORKDIR /go/src/app
3+
COPY ./ ./
4+
5+
RUN go build -o /go/bin/catnip /go/src/app/main.go
6+
7+
ENV PORT=8080
8+
CMD ["/go/bin/catnip"]

cats_suite_helpers/cats_suite_helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func CNBDescribe(description string, callback func()) bool {
112112
const (
113113
BuildpackLifecycle string = "buildpack"
114114
CNBLifecycle = "CNB"
115+
DockerLifecycle = "Docker"
115116
)
116117

117118
func FileBasedServiceBindingsDescribe(description string, lifecycle string, callback func()) bool {
@@ -123,6 +124,9 @@ func FileBasedServiceBindingsDescribe(description string, lifecycle string, call
123124
if lifecycle == CNBLifecycle && (!Config.GetIncludeFileBasedServiceBindings() || !Config.GetIncludeCNB()) {
124125
Skip(skip_messages.SkipFileBasedServiceBindingsCnbApp)
125126
}
127+
if lifecycle == DockerLifecycle && (!Config.GetIncludeFileBasedServiceBindings() || !Config.GetIncludeDocker()) {
128+
Skip(skip_messages.SkipFileBasedServiceBindingsDockerApp)
129+
}
126130
})
127131
Describe(description, callback)
128132
})

file_based_service_bindings/file_based_service_bindings.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var _ = FileBasedServiceBindingsDescribe("Enabling file based service binding fo
2525
callback(CNBLifecycle)
2626
})
2727

28+
var _ = FileBasedServiceBindingsDescribe("Enabling file based service binding for a Docker app", DockerLifecycle, func() {
29+
callback(DockerLifecycle)
30+
})
31+
2832
var callback = func(lifecycle string) {
2933
var appName, serviceName string
3034

@@ -77,6 +81,9 @@ var callback = func(lifecycle string) {
7781
if lifecycle == CNBLifecycle {
7882
Expect(cf.Cf("create-app", appName, "--app-type", "cnb", "--buildpack", Config.GetGoBuildpackName()).Wait()).To(Exit(0))
7983
}
84+
if lifecycle == DockerLifecycle {
85+
Expect(cf.Cf("create-app", appName, "--app-type", "docker").Wait()).To(Exit(0))
86+
}
8087
appGuid := app_helpers.GetAppGuid(appName)
8188

8289
appFeatureUrl := fmt.Sprintf("/v3/apps/%s/features/file-based-service-bindings", appGuid)
@@ -101,6 +108,15 @@ var callback = func(lifecycle string) {
101108
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
102109
}
103110

111+
if lifecycle == DockerLifecycle {
112+
Expect(cf.Cf(
113+
"push",
114+
appName,
115+
"--docker-image", Config.GetCatnipDockerAppImage(),
116+
"-m", DEFAULT_MEMORY_LIMIT,
117+
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
118+
}
119+
104120
checkFileContent("binding-guid", getServiceBindingGuid(appGuid, serviceGuid))
105121
checkFileContent("instance-guid", serviceGuid)
106122
checkFileContent("instance-name", serviceName)

helpers/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type CatsConfig interface {
111111
SleepTimeoutDuration() time.Duration
112112

113113
GetPublicDockerAppImage() string
114+
GetCatnipDockerAppImage() string
114115
}
115116

116117
func NewCatsConfig(path string) (CatsConfig, error) {

helpers/config/config_struct.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type config struct {
116116
PrivateDockerRegistryUsername *string `json:"private_docker_registry_username"`
117117
PrivateDockerRegistryPassword *string `json:"private_docker_registry_password"`
118118
PublicDockerAppImage *string `json:"public_docker_app_image"`
119+
CatnipDockerAppImage *string `json:"catnip_docker_app_image"`
119120

120121
UnallocatedIPForSecurityGroup *string `json:"unallocated_ip_for_security_group"`
121122

@@ -240,6 +241,7 @@ func getDefaults() config {
240241
defaults.PrivateDockerRegistryUsername = ptrToString("")
241242
defaults.PrivateDockerRegistryPassword = ptrToString("")
242243
defaults.PublicDockerAppImage = ptrToString("cloudfoundry/diego-docker-app:latest")
244+
defaults.CatnipDockerAppImage = ptrToString("ghcr.io/cloudfoundry/catnip-app:latest")
243245

244246
defaults.UnallocatedIPForSecurityGroup = ptrToString("10.0.244.255")
245247

@@ -292,6 +294,11 @@ func validateConfig(config *config) error {
292294

293295
}
294296

297+
err = validateCatnipDockerAppImage(config)
298+
if err != nil {
299+
errs = errors.Join(errs, err)
300+
}
301+
295302
err = validatePrivateDockerRegistry(config)
296303
if err != nil {
297304
errs = errors.Join(errs, err)
@@ -602,6 +609,16 @@ func validatePublicDockerAppImage(config *config) error {
602609
return nil
603610
}
604611

612+
func validateCatnipDockerAppImage(config *config) error {
613+
if config.CatnipDockerAppImage == nil {
614+
return fmt.Errorf("* 'catnip_docker_app_image' must not be null")
615+
}
616+
if config.GetCatnipDockerAppImage() == "" {
617+
return fmt.Errorf("* Invalid configuration: 'catnip_docker_app_image' must be set to a valid image source")
618+
}
619+
return nil
620+
}
621+
605622
func validatePrivateDockerRegistry(config *config) error {
606623
if config.IncludePrivateDockerRegistry == nil {
607624
return fmt.Errorf("* 'include_private_docker_registry' must not be null")
@@ -1123,6 +1140,10 @@ func (c *config) GetPublicDockerAppImage() string {
11231140
return *c.PublicDockerAppImage
11241141
}
11251142

1143+
func (c *config) GetCatnipDockerAppImage() string {
1144+
return *c.CatnipDockerAppImage
1145+
}
1146+
11261147
func (c *config) GetUnallocatedIPForSecurityGroup() string {
11271148
return *c.UnallocatedIPForSecurityGroup
11281149
}

helpers/config/config_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type testConfig struct {
4242
PrivateDockerRegistryUsername *string `json:"private_docker_registry_username,omitempty"`
4343
PrivateDockerRegistryPassword *string `json:"private_docker_registry_password,omitempty"`
4444
PublicDockerAppImage *string `json:"public_docker_app_image,omitempty"`
45+
CatnipDockerAppImage *string `json:"catnip_docker_app_image,omitempty"`
4546

4647
IsolationSegmentName *string `json:"isolation_segment_name,omitempty"`
4748
IsolationSegmentDomain *string `json:"isolation_segment_domain,omitempty"`
@@ -633,6 +634,32 @@ var _ = Describe("Config", func() {
633634
})
634635
})
635636

637+
Context("when including catnip_docker_app_image", func() {
638+
Context("when image name is set", func() {
639+
var image = "some-image"
640+
BeforeEach(func() {
641+
testCfg.CatnipDockerAppImage = ptrToString(image)
642+
})
643+
644+
It("has the value in the config", func() {
645+
config, err := cfg.NewCatsConfig(tmpFilePath)
646+
Expect(err).NotTo(HaveOccurred())
647+
Expect(config.GetCatnipDockerAppImage()).To(Equal(image))
648+
})
649+
})
650+
651+
Context("when image is an empty string", func() {
652+
BeforeEach(func() {
653+
testCfg.CatnipDockerAppImage = ptrToString("")
654+
})
655+
656+
It("returns an error", func() {
657+
_, err := cfg.NewCatsConfig(tmpFilePath)
658+
Expect(err).To(MatchError("* Invalid configuration: 'catnip_docker_app_image' must be set to a valid image source"))
659+
})
660+
})
661+
})
662+
636663
Context("when including isolation segment tests", func() {
637664
BeforeEach(func() {
638665
testCfg.IncludeIsolationSegments = ptrToBool(true)

helpers/skip_messages/skip_messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const SkipCNBMessage = `Skipping this test because config.IncludeCNB is set to '
1111
NOTE: Ensure CNB lifecycle is enabled on your platform before enabling this test.`
1212
const SkipFileBasedServiceBindingsBuildpackApp = `Skipping this test because config.IncludeFileBasedServiceBindings is set to 'false'.`
1313
const SkipFileBasedServiceBindingsCnbApp = `Skipping this test because config.IncludeFileBasedServiceBindings and/or config.IncludeCNB are set to 'false'.`
14+
const SkipFileBasedServiceBindingsDockerApp = `Skipping this test because config.IncludeFileBasedServiceBindings and/or config.IncludeDocker are set to 'false'.`
1415
const SkipInternetDependentMessage = `Skipping this test because config.IncludeInternetDependent is set to 'false'.
1516
NOTE: Ensure that your platform has access to the internet before running this test.`
1617
const SkipPrivateDockerRegistryMessage = `Skipping this test because config.IncludePrivateDockerRegistry is set to 'false'.

0 commit comments

Comments
 (0)