Skip to content

Commit 2a23c3b

Browse files
committedNov 13, 2019
Fix bundle build command with Docker and update documentation
The bundle build command using Docker fails in some cases due to Docker can't access some files which in turn due to issue with generated Docker command doesn't account for manifests directory. The `ADD` command in Dockerfile is now changed to `COPY` given we don't use any features from ADD. Update documentation + unit test cases for those above changes. Signed-off-by: Vu Dinh <[email protected]>
1 parent 7418392 commit 2a23c3b

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed
 

‎docs/design/operator-bundle.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ The `--package` or `-p` is the name of package fo the operator such as `etcd` wh
159159

160160
All information in `annotations.yaml` is also existed in `LABEL` section of `Dockerfile`.
161161

162+
The `Dockerfile` can used to manually build bundle image using container image tools such as Docker, Podman or Buildah. For example, the Docker build command would be:
163+
164+
```bash
165+
$ docker build -f /path/to/Dockerfile -t quay.io/test/test-operator:latest /path/to/manifests/
166+
```
167+
162168
### Build Bundle Image
163169

164170
Operator bundle image can be built from provided operator manifests using `build` command (see *Notes* below). The overall `bundle build` command usage is:
@@ -196,4 +202,3 @@ The `--package` or `-p` is the name of package fo the operator such as `etcd` wh
196202
*Notes:*
197203
* If there is `Dockerfile` existing in the directory, it will be overwritten.
198204
* If there is an existing `annotations.yaml` in `/metadata` directory, the cli will attempt to validate it and returns any found errors. If the ``annotations.yaml`` is valid, it will be used as a part of build process. The optional boolean `--overwrite/-o` flag can be enabled (false by default) to allow cli to overwrite the `annotations.yaml` if existed.
199-
* The directory where the operator manifests are located must be inside the context of the build which in this case is inside the directory where you run the command.

‎pkg/lib/bundle/build.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ func BuildBundleImage(directory, imageTag, imageBuilder string) (*exec.Cmd, erro
1717

1818
switch imageBuilder {
1919
case "docker", "podman":
20-
args = append(args, "build", "-f", dockerfilePath, "-t", imageTag, ".")
20+
args = append(args, "build", "-f", dockerfilePath, "-t", imageTag, directory)
2121
case "buildah":
22-
args = append(args, "bud", "--format=docker", "-f", dockerfilePath, "-t", imageTag, ".")
22+
args = append(args, "bud", "--format=docker", "-f", dockerfilePath, "-t", imageTag, directory)
2323
default:
2424
return nil, fmt.Errorf("%s is not supported image builder", imageBuilder)
2525
}

‎pkg/lib/bundle/build_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ func TestBuildBundleImage(t *testing.T) {
2222
testOperatorDir,
2323
"test",
2424
"docker",
25-
"docker build -f /test-operator/Dockerfile -t test .",
25+
"docker build -f /test-operator/Dockerfile -t test /test-operator",
2626
"",
2727
},
2828
{
2929
testOperatorDir,
3030
"test",
3131
"buildah",
32-
"buildah bud --format=docker -f /test-operator/Dockerfile -t test .",
32+
"buildah bud --format=docker -f /test-operator/Dockerfile -t test /test-operator",
3333
"",
3434
},
3535
{
3636
testOperatorDir,
3737
"test",
3838
"podman",
39-
"podman build -f /test-operator/Dockerfile -t test .",
39+
"podman build -f /test-operator/Dockerfile -t test /test-operator",
4040
"",
4141
},
4242
{

‎pkg/lib/bundle/generate.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func GenerateFunc(directory, packageName, channels, channelDefault string, overw
7777
log.Info("Building Dockerfile")
7878

7979
// Generate Dockerfile
80-
content, err = GenerateDockerfile(directory, mediaType, ManifestsDir, MetadataDir, packageName, channels, channelDefault)
80+
content, err = GenerateDockerfile(mediaType, ManifestsDir, MetadataDir, packageName, channels, channelDefault)
8181
if err != nil {
8282
return err
8383
}
@@ -226,7 +226,7 @@ func GenerateAnnotations(mediaType, manifests, metadata, packageName, channels,
226226
// GenerateDockerfile builds Dockerfile with mediatype, manifests &
227227
// metadata directories in bundle image, package name, channels and default
228228
// channels information in LABEL section.
229-
func GenerateDockerfile(directory, mediaType, manifests, metadata, packageName, channels, channelDefault string) ([]byte, error) {
229+
func GenerateDockerfile(mediaType, manifests, metadata, packageName, channels, channelDefault string) ([]byte, error) {
230230
var fileContent string
231231

232232
chanDefault, err := ValidateChannelDefault(channels, channelDefault)
@@ -246,8 +246,8 @@ func GenerateDockerfile(directory, mediaType, manifests, metadata, packageName,
246246
fileContent += fmt.Sprintf("LABEL %s=%s\n\n", ChannelDefaultLabel, chanDefault)
247247

248248
// CONTENT
249-
fileContent += fmt.Sprintf("ADD %s %s\n", filepath.Join(directory, "*.yaml"), "/manifests/")
250-
fileContent += fmt.Sprintf("ADD %s %s%s\n", filepath.Join(directory, metadata, AnnotationsFile), "/metadata/", AnnotationsFile)
249+
fileContent += fmt.Sprintf("COPY %s %s\n", "/*.yaml", "/manifests/")
250+
fileContent += fmt.Sprintf("COPY %s %s%s\n", filepath.Join("/", metadata, AnnotationsFile), "/metadata/", AnnotationsFile)
251251

252252
return []byte(fileContent), nil
253253
}

‎pkg/lib/bundle/generate_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ func TestGenerateDockerfileFunc(t *testing.T) {
212212
"LABEL operators.operatorframework.io.bundle.package.v1=test4\n"+
213213
"LABEL operators.operatorframework.io.bundle.channels.v1=test5\n"+
214214
"LABEL operators.operatorframework.io.bundle.channel.default.v1=test5\n\n"+
215-
"ADD %s/*.yaml /manifests/\n"+
216-
"ADD %s/annotations.yaml /metadata/annotations.yaml\n", MetadataDir, getTestDir(),
217-
filepath.Join(getTestDir(), MetadataDir))
215+
"COPY /*.yaml /manifests/\n"+
216+
"COPY %s/annotations.yaml /metadata/annotations.yaml\n", MetadataDir,
217+
filepath.Join("/", MetadataDir))
218218

219-
content, err := GenerateDockerfile(getTestDir(), "test1", "test2", MetadataDir, "test4", "test5", "")
219+
content, err := GenerateDockerfile("test1", "test2", MetadataDir, "test4", "test5", "")
220220
require.NoError(t, err)
221221
require.Equal(t, output, string(content))
222222
}

0 commit comments

Comments
 (0)
Please sign in to comment.