-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build/image: build the storage-operator image
Add a new image to be built: the container image for the Storage operator. Since it's very similar to a LocalImage, except for the building part (we use the operator-sdk command instead of Docker directly, because we need to compile the Go code), we introduce a new class (OperatorImage) that inherits from LocalImage and overload the `_do_build` method. Note that we take care of enabling Go module and compiling from the `storage-operator` directory. Refs: #1410 Signed-off-by: Sylvain Laperche <[email protected]>
- Loading branch information
1 parent
7a34d8a
commit 30b0d50
Showing
6 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# coding: utf-8 | ||
|
||
|
||
"""Provides container image construction for Kubernetes Operator. | ||
Those are very similar to the locally built images, except that they are build | ||
by the `operator-sdk` command (which also takes care of compiling the Go code) | ||
instead of calling Docker directly. | ||
""" | ||
|
||
|
||
from pathlib import Path | ||
import shlex | ||
from typing import Any, List | ||
|
||
import doit # type: ignore | ||
|
||
from buildchain import config | ||
from buildchain import constants | ||
from buildchain import types | ||
|
||
from . import local_image | ||
|
||
|
||
class OperatorImage(local_image.LocalImage): | ||
"""A locally built container image for a Kubernetes Operator.""" | ||
def __init__( | ||
self, name: str, version: str, destination: Path, **kwargs: Any | ||
): | ||
"""Initialize an operator container image. | ||
Arguments: | ||
name: image name | ||
version: image version | ||
destination: where to save the result | ||
Keyword Arguments: | ||
They are passed to `Target` init method. | ||
""" | ||
dockerfile = constants.ROOT/name/'build'/'Dockerfile' | ||
kwargs.setdefault('task_dep', []).append('check_for:operator-sdk') | ||
super().__init__( | ||
name=name, version=version, dockerfile=dockerfile, | ||
destination=destination, save_on_disk=True, build_args=None, | ||
**kwargs | ||
) | ||
|
||
def _do_build(self) -> List[types.Action]: | ||
"""Return the actions used to build the image.""" | ||
cwd = constants.ROOT/self.name | ||
cmd = ' '.join(map(shlex.quote, [ | ||
config.ExtCommand.OPERATOR_SDK.value, 'build', self.tag | ||
])) | ||
return [doit.action.CmdAction(cmd, cwd=cwd)] |