Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Set docker build args and similar for deployment targets #647

Open
aguschin opened this issue Mar 20, 2023 · 1 comment
Open

Set docker build args and similar for deployment targets #647

aguschin opened this issue Mar 20, 2023 · 1 comment
Labels
breaking-change This is going to break users code build Exporting models (building model packages) deploy Related to model deployment 🏡 housekeeping Fighting technical debt and improving dev process

Comments

@aguschin
Copy link
Contributor

Right now mlem build docker --help provide control over many docker build options via using class DockerBuildArgs(BaseModel).

Ideally, these options should be available when running mlem deploy $TARGET, but they're not. One reason for this implementation was that platforms set their own limitations for these options (such as Heroku allows only some platforms for docker build to be used). However, this requires us to introduce each option needed manually, example being:

Ideally, all deployments should inherit class DockerModelDirectory or DockerImageBuilder instead of re-implementing functions like build_heroku_docker or build_k8s_docker or build_sagemaker_docker. This should extend to CLI so users be able to set those options in CLI.

This calls for refactoring with breaking changes, since options added manually (mentioned above) could change their locations, and start looking just like those in build docker now.

Keeping it "as is" instead will lead to manually work (e.g. I've added build_arg to k8s deployment only, but it should be added to each deployment target, and it should be done for each param), so refactoring and breaking changes are inevitable if we're going to improve the tool.

cc @omesser FYI

@aguschin aguschin added 🏡 housekeeping Fighting technical debt and improving dev process deploy Related to model deployment build Exporting models (building model packages) breaking-change This is going to break users code labels Mar 20, 2023
@aguschin
Copy link
Contributor Author

Request from customer: add ability to set ENV X=Y to use ENV in docker image. Will look into on implementing this.

aguschin added a commit that referenced this issue Mar 31, 2023
this is for
#647 (comment)

This work similarly to #645:

`mlem build docker` works the same, but I'll provide an example for k8s
deploy here:

```
$ mlem declare deployment kubernetes deployer \
  --image_name myimage --service_type loadbalancer --registry remote \
  --env docker --env.registry remote --registry.host localhost --namespace myns \
  --set_env.0 VAR1 --set_env.1 VAR2=aguschin
💾 Saving deployment to deployer.mlem
```

```yaml
# deployer.mlem
env:
  object_type: env
  registry:
    type: remote
  type: kubernetes
image_name: myimage
namespace: myns
object_type: deployment
registry:
  host: localhost
  type: remote
service_type:
  type: loadbalancer
set_env:
- VAR1
- VAR2=aguschin
type: kubernetes
```

Then in Dockerfile for your image you'll get:
```
...
ENV VAR1=VALUE1
ENV VAR2=aguschin
```

`VALUE1` will be taken from shell/env vars with `os.getenv("VAR1")`. If
it's not set, an Exception will be raised by MLEM.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change This is going to break users code build Exporting models (building model packages) deploy Related to model deployment 🏡 housekeeping Fighting technical debt and improving dev process
Projects
None yet
Development

No branches or pull requests

1 participant