acorn-io / runtime

A simple application deployment framework built on Kubernetes

Home Page:https://docs.acorn.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build image failing on acorn platform when if statement is used inside the Acornfile

slayer321 opened this issue · comments

Hi, I'm working on Developing Acornfile for Jellyfin. As it is a media server so I have given an options to pass the s3 bucket details to the users. To take the user input I'm using the args field and as there is not way we can make the specific field required . So there can be the scenrios if users don't pass the s3 credentails along with bucket name the jellyfin container will start failing, to prevent this I have added a if check for both the sidecar image and other container image that we are using. Now if user forget to pass the s3 bucket details the jellyfin container will still be running as it will skip both the sidecar and other container.

While testing it using acorn cli it works as expected for both the scenarios when the s3 details are given and not given. Below is how i'm running while passing all the s3 details

acorn run -n jellyfin . --access_key <>  --bucket_name <> --secret_key <>

and when I just run acorn run -n jellyfin . jellyfin server is still running just other containers are skipped.

After testing it using Acorn CLI i created the image for the Acornfile and was trying to run it on the platform using the image and after passing all the s3 details when I click on Deploy. Below is the error I'm getting.

Screenshot from 2023-11-30 18-02-10

In the error it says image/build field is required for bucketsync container but when I check my Acornfile on the platform I was able to see those field.

I doubt there can be some bug on the platform causing this issue.

TL;DR : When using if statement in the Acornfile and running the jellyfin image on the platform it fails with the above error (see the image) , but when the same Acornfile is run using acorn cli it works as expected in both the scenarios when bucket details is given and not given.

This is a known behavior, and isn't documented at the moment, but there is a solution. The tl;dr is you need to use the top level images key to define images that will be hidden behind conditionals during build. Because they aren't found during build time, they aren't available in the Acorn image which is why you are seeing this error.

So, images look like:

// Just an image like you would use in containers.foo.image
images: sidecar: image: "ghcr.io/this/image:v0.0.0"
// Same fields you would use for a container build in the container block.
images: sidecarToBeBuilt: containerBuild: { context: "." }

// use it like so
if foo != "" {
  containers: sidecar: {
    image: images.sidecar.image
  }
}

// or for a build scenario
if foo != "" {
  containers: sidecar: {
    build: images.sidecarToBeBuilt.containerBuild
  }
}

you can also do an acornBuild with the same fields you would use in the acorns block.

I'll be adding this to the docs.