Use custom modules with bitnami/magento container on kubernetes

8/10/2018

I have a custom module that I want to install on a container running the bitnami/magento docker image within a kubernetes cluster.

I am currently trying to install the module from a local dir into the containers Dockerfile:

# run bitnami's magento container
FROM bitnami/magento:2.2.5-debian-9

# add magento_code directory to the bitnami magento install
# ./magento_data/code contains the module, i.e. Foo/Bar
ADD ./magento_data/code /opt/bitnami/magento/htdocs/app/code

After building and running this image the site pings back a 500 error. The pod logs show that Magento installs correctly but it doesn't know what to do with the custom module:

Exception #0 (UnexpectedValueException): Setup version for module 'Foo_Bar' is not specified

Therefore to get things working I have to open a shell to the container and run some commands:

$ php /opt/bitnami/magento/htdocs/bin/magento setup:upgrade

$ chown -R bitnami:daemon /opt/bitnami/magento/htdocs

The first sorts the magento set up issue, the second ensures the next time an http request comes in Magento is able to correctly generate any directories and files it needs.

This gives me a functioning container, however, kubernetes is not able to rebuild this container as I am manually running a bunch of commands after Magento has installed.

I thought about running the above commands within the containers readinessProbe however not sure if it would work as not 100% on the state of Magento when that is first called, alongside it seeming very hacky.

Any advice on how to best set up custom modules within a bitnami/magento container would be much appreciated.

UPDATE:

Since opening this issue I've been discussing it further on Github: https://github.com/bitnami/bitnami-docker-magento/issues/82

-- GuyC
bitnami
docker
kubernetes
magento
magento2

1 Answer

8/11/2018

I've got it working via the use of composer instead of manually adding the module to the app/code directory.

I was able to do this by firstly adding the module to Packagist, then I stored my Magento Marketplace authentication details in auth.json:

{
    "http-basic": {
        "repo.magento.com": {
            "username": <MAGENTO_MARKETPLACE_PUBLIC_KEY>,
            "password": <MAGENTO_MARKETPLACE_PRIVATE_KEY>
        }
    }
}

You can get the public & private key values by creating a new access key within marketplace. Place the file in the modules root, alongside your composer.json.

Once I had that I updated my Dockerfile to use the auth.json and require the custom module:

# run bitnami's magento container
FROM bitnami/magento:2.2.5

# Require custom modules
WORKDIR /opt/bitnami/magento/htdocs/
ADD ./auth.json .
RUN composer require foo/bar

I then completed a new install, creating the db container alongside the magento container. However it should also work fine with an existing db so long as the modules versions are the same.

-- GuyC
Source: StackOverflow