#How to load image from tar?

1 messages · Page 1 of 1 (latest)

proud compass
#

I have this image in my local Docker hub which I want to use in Dagger, this seems like the easiest way (since the image is used in a yml file) but I couldn't quite find the proper way of using it

cursive gorge
#

Ah, you've hit something that's not quite possible yet

proud compass
#

😭

#

So the only way (currently) would be to build the image inside Dagger?

cursive gorge
#

yeah, you can use the .DockerBuild function to build a docker image

#

i would say - this is probably coming soon-ish? i've been working on this area a lot recently, so want to get this working properly

proud compass
#

But what if I want just the image, not a container? (I see that .DockerBuild gives me a container)

#

Cause the image is used in a yml file for a Docker Compose, stuff is messy

#

Also, on a sidenote, I assume healthchecks defined in said yml file are respected by the inner Docker daemon (dind), right? This would be another reasoning, those healthchecks are used in the setup process and since Dagger has no withHealthcheck I found it to be a pain to do it by hand (and also ran into multiple issues)

cursive gorge
#

In dagger, there's not really a difference between a container and an image

#

you can think of each WithExec in a pipeline as similar to a RUN step in a dockerfile

#

they all build layers

cursive gorge
proud compass
#

Oh, ok, but since Dagger by default ignores entrypoint, and my Dockerfile has one, do I have to do something like

.withExec(nil, dagger.ContainerWithExecOpts{
  UseEntrypoint: true,
})
``` for it to be respected?
cursive gorge
#

you need to add it for each withExec

#

that you want the entrypoint to be used for

proud compass
cursive gorge
#

oh i see, you're running docker-compose in dagger

#

yeah, if you're running docker-compose in dagger, then it'll work just as normal docker-compose does

tacit wedge
#

Can't you also docker save and container().import() ? as a stopgap

cursive gorge
#

of course import is a thing

proud compass
#

So I have

blockchain := dag.Container().
        WithMountedDirectory("/src", source).
        WithWorkdir("/src").
        Import(source.File("localcontract:latest.tar"))

which is how I hope it works. But do I have to run it as service for the other container to access it? As for the entrypoint, I don't actually run anything inside it, I only need it as an image (so no withExec 😦 ), and the yml file in question just pulls the image

blockchain:
    container_name: blockchain
    image: localcontract:latest
    ports:
      - 8545:8545
    volumes:
      - configs-volume:/usr/src/app/configs
    healthcheck:
      test:
        - CMD-SHELL
        - find deployment_completed.txt || exit 1
      interval: 1m
      timeout: 5s
      retries: 30
      start_period: 15s
tacit wedge
#

Note @proud compass : for rapid experimentation you can call the dagger API from dagger shell. Example:

dagger <<.
  source() {
   host | directory ./path/to/your/source/dir
  }

  container |
  with-mounted-directory /src $(source) |
  with-workdir /src |
  import $(source | file localcontract:latest.tar)
.
proud compass
#

Ok, I'll keep that in mind! However, how does that help my problem? 😅

tacit wedge
#

Not directly - just mentioning it, since it can help you iterate faster

#

I don't completely understand your problem, got lost in the many messages

#

Where are you stuck @proud compass ?

#

You may need to do the import first:

blockchain := dag.Container().
        Import(source.File("localcontract:latest.tar"))
        WithMountedDirectory("/src", source)
        WithWorkdir("/src").
proud compass
#

Sorry for the delay, I ate lunch

#

I'm stuck at how to actually use the image (/container) in the actual container where I'm using docker-compose on the .yml file which I shared a snippet from. So, the yml would run blockchain as service itself, but because of this setup, do I have to run it myself? Something like

    blockchain := dag.Container().
        Import(source.File("localcontract:latest.tar")).
        WithMountedDirectory("/src", source).
        WithWorkdir("/src").
        WithExposedPort(8545).
        WithMountedCache("/usr/src/app/configs", dag.CacheVolume("configs-volume")).
        AsService() // and then also a manual healthcheck

to mimick what the .yml does. It just seems like too much of a hassle since the .yml does this already but idk what else to do.

tacit wedge
#

I guess it depends what you're trying to achieve in the end.

#

Do you have a clear picture of how you want to fit dagger in your stack, or is that what you're trying to figure out?

proud compass
#

I'm trying to figure out if I can do this workaround. Currently the team gets the image from ECR but they told me to simulte the CI/CD pipeline locally, which is why I have this headache