https://garden.io logo
Sharing images between modules
b

blue-lunch-98125

01/17/2023, 6:03 PM
Is there a preferred way to share a base image between modules? Does the image have to be pushed to a remote registry as a middle step? What I want to do is something like the following:
kind: Module
description: ebtflask
type: container
name: ebtflask
image: efs-server
build:
  timeout: 3600
services:
  - name: ebtflask
    ports:
      - name: http
        containerPort: 5000
    dependencies:
      - kafka-broker
      - pgbouncer
      - redis
    command:
      - nodemon
      - -e
      - py
      - --exec
      - './manage.py runserver --disable_reloader'
      - --config
      - freshebt/nodemon.json
    env:
      EFS_DB_HOST: pgbouncer
      EFS_REDIS_HOST: redis
      OPENSEARCH_HOST: opensearch
exclude:
  - devops/images/**/*
---
kind: Module
description: celery-beat
type: container
name: celery-beat
image: efs-server
build:
  dependencies:
    - name: ebtflask
services:
  - name: celery-beat
    env:
      EFS_DB_HOST: pgbouncer
      EFS_REDIS_HOST: redis
    dependencies:
      - pgbouncer
      - redis
    command:
      - nodemon 
      - -e 
      - py 
      - --exec 
      - 'celery beat -A freshebt.app:celery --pidfile= --schedule /var/lib/celery-beat.db --loglevel=INFO'
      - --watch 
      - freshebt
include: []
Where the second module simply reuses the container image built in the first, but with a different command.
b

bright-policeman-43626

01/17/2023, 7:36 PM
Hey there, not sure if this is going to help but I had a similar case where I needed to build the docker image with 1 module and then pass it to another module; I used the following syntax, hopefully it helps:
kind: Module
type: container
name: application-image
dockerfile: Dockerfile
include: [./modules.garden.yml, Dockerfile, .]
Then you can reuse that image using outputs of that module:
kind: Module
description: celery-beat
type: container
name: celery-beat
image: ${modules.application-image.outputs.deployment-image-name}:${modules.application-image.version}
build:
  dependencies:
    - name: ebtflask
services:
**** continues...
This example will build `application-image:v1.X.X) for example
After you have that possibilities are unlimited, you can reuse that image version; it is documented in the container module https://docs.garden.io/reference/module-types/container#usd-modules.less-than-module-name-greater-than.outputs.deployment-image-name
b

blue-lunch-98125

01/17/2023, 7:56 PM
Awesome. I'll give this a shot. Thanks!
b

bright-policeman-43626

01/17/2023, 8:10 PM
Sounds good, let me know if it works! Thanks
b

blue-lunch-98125

01/19/2023, 10:10 AM
Works like a charm. Thanks a lot.
b

bright-policeman-43626

01/19/2023, 8:55 PM
Amazing! happy to help @blue-lunch-98125 ❤️ @ancient-diamond-80011 would you mind changing this to resolved?
a

ancient-diamond-80011

01/20/2023, 8:27 AM
thank you so much for the community help! 💚