How to Package and Install Apigee Microgateway Plugins with Docker

Assume that you have developed an Apigee Microgateway plugin with the name response-override, it has dependencies to be installed and Microgateway needs to be deployed on Docker. If so, we could follow below steps for this purpose:

1. Create a Dockerfile with the following content:

FROM gcr.io/apigee-microgateway/edgemicro:latest

USER root
RUN mkdir /opt/apigee/customplugins && \
chown apigee:apigee /opt/apigee/customplugins
COPY plugins /opt/apigee/customplugins/plugins
RUN npm install --prefix /opt/apigee/customplugins/plugins/response-override

USER apigee

Note that in the above Dockerfile we are doing following:

  • Use official Apigee Microgateway Docker image: gcr.io/apigee-microgateway/edgemicro:latest as the base image
  • Directly copy plugins directory content without creating a zip file and extracting it
  • Execute a npm install command in /opt/apigee/customplugins/plugins/response-override for installing the dependencies

2. Ensure both Dockerfile and plugins directory are located in the same directory:

├── Dockerfile
├── plugins
│   └── response-override
│   ├── index.js
│   └── package.json

3. Build the Docker image:

docker build -t edgemicroplugins .

4. Configure Microgateway on the local machine and export key and secret values to environment variables:

org=# org
env=# env
edgemicro configure -o $org -e $env -u $user
export key=# key generated by edgemicro configure command
export secret=# secret generated by edgemicro configure command

5. Export Microgateway configuration file content in base64 format to EDGEMICRO_CONFIG environment variable:

export EDGEMICRO_CONFIG=$(base64 $HOME/.edgemicro/${org}-${env}-config.yaml)

6. Start a Microgateway docker container:

docker run -d -p 8000:8000 --name edgemicroplugins \
-e DEBUG=* \
-e EDGEMICRO_PLUGIN_DIR=/opt/apigee/customplugins/plugins \
-e EDGEMICRO_ORG=$org \
-e EDGEMICRO_ENV=$env \
-e EDGEMICRO_KEY=$key \
-e EDGEMICRO_SECRET=$secret \
-e "EDGEMICRO_CONFIG=$EDGEMICRO_CONFIG" \
-e SERVICE_NAME=edgemicroplugins edgemicroplugins

7. Tail docker container logs:

docker ps
docker logs -f {container-instance-id}

8. Send an API request to an API proxy deployed on the Microgateway and verify above container logs. For an example, create and deploy a Microgateway aware proxy with the base path /hello and send an API request as follows:

curl -i http://localhost:8000/hello

In addition to above, you could use console.log('') statements for adding debug statements in the plugin index.js file:

...
module.exports.init = function(config, logger, stats) {
return {

ondata_response: function(req, res, data, next) {
console.log('***** plugin ondata_response');
next(null, null);
}, 
Version history
Last update:
‎09-28-2020 08:38 PM
Updated by: