Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image build in ADO failing on postsubmit when generating tag value from env file value #10413

Open
5 tasks done
dekiel opened this issue Apr 12, 2024 · 2 comments
Open
5 tasks done
Assignees
Labels
area/ci Issues or PRs related to CI related topics kind/bug Categorizes issue or PR as related to a bug.

Comments

@dekiel
Copy link
Contributor

dekiel commented Apr 12, 2024

Description

After moving to use ADO backend it was needed to stop using env file and remove env-flag flag from prowjob args. ADO backend doesn't support env files feature. Because oci-image-builder pipelines doesn't use env file the build failing on preparing image tags. This happen because image-builder when loading env file content not only adds them as build arguments, but additionally creates environment variables for each key value pair.

Creating environment variables is happening in loadEnv func in image-builder.

err := os.Setenv(key, val)

The environment variables created from env file content can be referenced in tag templates by using .Env function. If that's happening, oci-image-builder pipeline will not be able to create a tag with such template.
Example failing tag template --tag={{ .Env PROMETHEUS_VERSION }}-ShortSHA={{ .Env PROMETHEUS_VERSION }}-{{ .ShortSHA }}
Failed build in ADO https://status.build.kyma-project.io/view/gs/kyma-prow-logs/logs/post-main-tpi-telemetry-self-monitor/1778750592647172096#1:build-log.txt%3A653

In the past we made a decision to not add env file support as it was used by only few prowjobs and we expected that this can be easily replaced by defining ARG values in Dockerfile. Feature of creating environment variables was overlooked. We can't ask users to define an env variable and set it's value in a prowjob or workflow and pass it as build argument and use for generating image tag value. Because prowjobs are taken from test-infra repo branch and for workflow we are forced to use pull-request-target event, users wouldn't be able to easily build image with new values of such variables. Changing a values would require merging them in to the branch from which build definition is taken.

We must add support for env files in oci-image-builder.

Acceptance Criteria

  • image-builder client support env-file flag.
  • oci-image-builder pipeline support env-file flag
  • oci-image-builder adds build args from env file content.
  • oci-image-builder generate tags from templates using environment variables defined from env file content.
  • We should use an existing library for working with env files.
@dekiel dekiel added area/ci Issues or PRs related to CI related topics kind/bug Categorizes issue or PR as related to a bug. labels Apr 12, 2024
@Sawthis Sawthis self-assigned this Apr 18, 2024
@Sawthis
Copy link
Contributor

Sawthis commented Apr 19, 2024

I've done research about existing libraries which can be used.

First one with the biggest number of stars is Viper. Viper can load env vars from .env file and unmarshal them into the struct(example code).

Second option with less number of stars but also very popular is godotenv (loads env vars from a .env file) and env (parses environment variables into structs). Example code can be found here.

@Sawthis
Copy link
Contributor

Sawthis commented Apr 19, 2024

For Python code we can use: https://pypi.org/project/python-dotenv/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci Issues or PRs related to CI related topics kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants