Skip to content

Instantly share code, notes, and snippets.

@djmason9
Last active January 29, 2020 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djmason9/03d8cc48c405dbab9c0881e59c6040b1 to your computer and use it in GitHub Desktop.
Save djmason9/03d8cc48c405dbab9c0881e59c6040b1 to your computer and use it in GitHub Desktop.
Axway AMPLIFY API Builder and MongoDB Containerization in 5 minutes

Create The API Builder Project

Build Project

api-builder init axwayairport

Install Modules

cd axwayairport
npm install --no-optional

Install Mongo Plugin

npm install @axway/api-builder-plugin-dc-mongo

Start Project

npm start

Create Mongo DB Container

Install Mongo Docker

docker pull mongo

Update Config (config/mongo.default.js)

Add the environmental variable process.env.MONGO_URL as your URL so we can pass the current URL to the docker container on the fly.

module.exports = {
	connectors: {
		mongo: {
			connector: '@axway/api-builder-plugin-dc-mongo',
			url: process.env.MONGO_URL,
			generateModelsFromSchema: true,
			modelAutogen: true
		}
	}
};

Make Network Bridge

A bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network

docker network create -d bridge mybridge

Run Mongo

Add -d to run in background.

docker run --name mongodbtest --network=mybridge -p 27017:27017 -v ~/mongodata:/data/db mongo:latest

Add Mongo Database

Create a database and collection in your docker container

docker exec -it mongodbtest bash
//once in the bash type
mongo
//then create database called axwayairport
use axwayairport
//add a collection for vendors
db.createCollection("vendors")
show collections
//add a new vendor
db.vendors.insert({"name":"Southwest","hub":"PHX"})
exit
exit

Create API Builder Container

Inside your axwayairport project folder you will have a Dockerfile already created.

Build Container

docker build -t axwayairport ./

Run Container

Remember -e is our environmental variable we need to pass the container designating the URL for mongo. Add -d to run in background.

docker run --rm --name axwayairport --network=mybridge -p 8080:8080 -e MONGO_URL="mongodb://mongodbtest:27017/axwayairport" axwayairport

Test API

User will be your own apikey: 'xxxxxxxxxxxxxxxxx' in config/default.js

curl -u [YOUR API_KEY]: 'http://localhost:8080/api/mongo/vendors'

Break it down

In three basic steps we can run our containers

docker network create -d bridge mybridge
docker run --name mongodbtest --network=mybridge -p 27017:27017 -v ~/mongodata:/data/db mongo:latest
docker run --rm --name axwayairport --network=mybridge -p 8080:8080 -e MONGO_URL="mongodb://mongodbtest:27017/axwayairport" axwayair
@aaronj314
Copy link

this is just great!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment