Sharing images between modules
# 🌱|help-and-getting-started
b
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:
Copy code
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
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:
Copy code
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:
Copy code
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
Awesome. I'll give this a shot. Thanks!
b
Sounds good, let me know if it works! Thanks
b
Works like a charm. Thanks a lot.
b
Amazing! happy to help @blue-lunch-98125 ❤️ @ancient-diamond-80011 would you mind changing this to resolved?
a
thank you so much for the community help! 💚
8 Views