ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.18k stars 392 forks source link

Build base image, and use it to build other services #552

Open chouseknecht opened 7 years ago

chouseknecht commented 7 years ago

See thread here: https://groups.google.com/forum/#!topic/ansible-container/MFhi_PZo7p8

I am wanting to create a base image defined in my container.yml that is shared by 2 or more service declarations. I was able to achieve this in the example container.yml I am including below. However, the problem comes when I try to deploy to Openshift, the image reference created results in an error on Openshift. The base image is the foreman-base which has a series of roles applied to it. The foreman container uses that foreman-base image but adds all of the service definitions. Then, the foreman-tasks container uses that same foreman-base image but runs a different service requiring everything from foreman-base.

When this gets deployed out to Openshift, the foreman container (because it has no roles and thus is not "built" by ansible-container) ends up with a deployment configuration that points at openshift-foreman-base:latest which Openshift errors on finding. The exact error is:

Failed to pull image "openshift-foreman-base:latest": Error: image library/openshift-foreman-base:latest not found

The foreman-base image does get built and pushed into the Openshift registry, so it is available but the deployment configuration ends up pointing at what seems to be the incorrect reference point.

library/openshift-foreman-base vs. '172.30.1.1:5000/openshift/openshift-foreman-base'

services:
  foreman-base:
    from: centos:7
    roles:
      - epel-repositories
      - role: puppet-repositories
        puppet_repositories_version: 4
      - foreman-repositories
      - katello-repositories
      - foreman
    openshift:
      state: absent
  foreman:
    from: openshift-foreman-base:latest
    command: ['/usr/bin/start-foreman.sh']
    entrypoint: ['/usr/bin/entrypoint.sh']
    environment:
      - POSTGRES_DB={{ POSTGRES_DB }}
      - POSTGRES_USER={{ POSTGRES_USER }}
      - POSTGRES_PASSWORD={{ POSTGRES_PASSWORD }}
      - SEED_ADMIN_USER=admin
      - SEED_ADMIN_PASSWORD=changeme
      - SEED_ORGANIZATION=Default Organization
      - SEED_LOCATION=Raleigh
    ports:
      - 8080:8080
    expose:
      - 8080
  foreman-tasks:
    from: openshift-foreman-base:latest
    roles:
      - foreman-tasks
    command: ['/usr/bin/start-foreman-tasks.sh']
    entrypoint: ['/usr/bin/entrypoint.sh']
    environment:
      - POSTGRES_DB={{ POSTGRES_DB }}
      - POSTGRES_USER={{ POSTGRES_USER }}
      - POSTGRES_PASSWORD={{ POSTGRES_PASSWORD }}
ehelms commented 7 years ago

For anyone that wants to do the same in the meantime, I worked around this by creating a tiny "noop" role that does nothing and added it to the foreman service described above. This has very little overhead and let's me optimize my build until a proper fix is provided.