How to pass build secrets to the build image with files

Hi,

I want to create an ENV VAR with the value of a secret that I want to mount in my Dockerfile and use it in a RUN command there.

How can I do it with Okteto?

Okteto has an option in the build section of the Manifest where you can add secrets.

The important thing to note here is that Okteto uses in this part the format of FILES.

You cant add in secrets directly the content of an ENV VAR like $MY_VAR

How to do it then?

The best and more secured option is to create in the same repository a file: .my_secretand inside the file having : $MY_SECRET

Then you can add to Okteto Admin Variables (or Settings→Variables) the value of MY_SECRET

In the Okteto manifest:

build:

  test-secret:

    secrets:

       my_mount_secret: .my_secret


And in the Dockerfile:

RUN --mount=type=secret,id=my_mount_secret \

    export MY_SECRET=$(cat /run/secrets/my_mount_secret || echo "(no secret)") && echo $MY_SECRET

We have a sample repo prepared for this with instructions to test it:

1 Like