Thank you so much for your reply Victor!
I have worked on this a few more times without any edits to the dockerfile. Last time I added a wait-for shell script to make the container start after mongodb but I think its not needed. This time I have noticed some interesting things. When I send a POST request through postman to
http://localhost:8080/tmf-api/document/v4/document I receive an error from the sample app with the code name 'AuthenticationFailed' and some details like `failed to connect to server [mongo:27017]`
ENV MONGO_URL=mongodb://admin:pass@mongo:27017/tmf
This is the environment variable set in the docker file. I have also tested the app with other values for MONGO_URL Previously I have used the same username and password I have set for the root user for mongodb in my docker-compose file. I changed to admin:pass as every time I run the container mongo-express outputs a message saying basicAuth is set to admin:pass but this did not work either. Maybe admin:pass is the basicAuth for mongo-express. I have also included the url without any username and password like this.
mongodb://mongo:27017/tmf
Dockerfile
FROM alpine:3.12.0
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN apk add --update nodejs npm
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
# Bundle app source
COPY . .
ENV MONGO_URL=mongodb://mongodb:mongodb@mongo:27017/tmf
EXPOSE 8080
CMD [ "node", "index.js" ]
config.json (sample app)
{
"db_prot": "mongodb",
"db_user": "mongodb",
"db_password": "mongodb",
"db_host": "mongo",
"db_port": 27017,
"db_name": "tmf",
"alarm_host": "http://localhost:10011",
"alarm_url_hal": "/api/",
"strict_schema": true
}
docker-compose.yml
version: '3.8'
services:
mongo:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: mongodb
MONGO_INITDB_ROOT_PASSWORD: mongodb
# MONGO_INITDB_DATABASE: tmf
volumes:
- tmf_mongo:/data/db
# - '.mongodb/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro'
ports:
- '27017:27017'
restart: unless-stopped
mongo-express:
image: mongo-express:latest
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: mongodb
ME_CONFIG_MONGODB_ADMINPASSWORD: mongodb
ME_CONFIG_MONGODB_URL: mongodb://mongodb:mongodb@mongo:27017/
app:
build: .
ports:
- 8080:8080
depends_on:
- mongo
volumes:
tmf_mongo:
------------------------------
Ahmed Jalwan Waheed
Dhivehi Raajjeyge Gulhun Plc
------------------------------
Original Message:
Sent: Mar 30, 2022 00:23
From: Victor Rodriguez
Subject: Running CTK against Document Management API Sample Implementation
Hi @Ahmed Jalwan Waheed
I looked into your compose file and the configuration looks good. There is no need for mongo-express since the ri will create the database automatically once the request comes in and successfully connects to the database. I will paste here the docker-compose file together with the dockerfile that we use for testing the ris so you can compare. Notice that the environment variable MONGO_URL set in the dockerfile superseeds the configuration variables in the config.json file present in the ri folder. With the following files you should be able to run the reference implementation. If the same error still persists it would be helpful to see your docker file so I can replicate your environment.
Answering your second question about the ctk. In order to run the ctk you only need to point the url from the config.json file to where the api is running. An example is provided below with the attributes set to work with the given compose files. Note that the url attribute points to localhost:8642 which is the port defined in the docker-compose file. After setting up this variable you can run the ctk using one of the helper scripts provided at the root of the folder, for example "sh Mac-Linux-RUNCTK.sh". Once the ctk runs the results will be available on the results.html file.
config.json found at the root of the ctk folder
{ "url": " http://localhost:8642/tmf-api/alarmManagement/v4/", "headers": { "Accept": "application/json", "Content-Type": "application/json" }, "payloads": { "Alarm": { "POST": { "payload": { "alarmRaisedTime": "2019-07-03T03:32:17.235Z", "alarmType": "environmentalAlarm", "alarmedObject": { "id": "93051825" }, "perceivedSeverity": "minor", "probableCause": "rectifierLowVoltage", "sourceSystemId": "ems-1", "state": "raised" } } } }}
Docker-compose
version: "3.9"services: mongo: image: mongo:latest environment: MONGO_INITDB_ROOT_USERNAME: mongodb MONGO_INITDB_ROOT_PASSWORD: mongodb volumes: - tmf_mongo:/data/db ports: - "27017:27017" restart: unless-stopped tmf642: build: . ports: ['8642:8080'] stdin_open: true tty: truevolumes: tmf_mongo:
Docker file
FROM alpine:3.12.0# Create app directoryWORKDIR /usr/src/app# Install app dependencies# A wildcard is used to ensure both package.json AND package-lock.json are copied# where available (npm@5+)COPY package*.json ./RUN apk add --update nodejs npmRUN npm install# If you are building your code for production# RUN npm ci --only=production# Bundle app sourceCOPY . .ENV MONGO_URL=mongodb://mongo:27017/tmfEXPOSE 8080CMD [ "node", "index.js" ]
------------------------------
Victor Rodriguez
TM Forum
Original Message:
Sent: Mar 28, 2022 09:21
From: Ahmed Jalwan Waheed
Subject: Running CTK against Document Management API Sample Implementation
I am facing two problems
One being that I am unable to connect the sample implementation to mongodb. I am using the dockerfile provided to create a container of the app and using docker-compose, Im running the container alongside mongo and mongo express. As the sample does not create the tmf database, I create the database using the mongo express client and restart the containers. However I am still unable to connect and receive the following error on sending request to the sample server.
{ "code": 1, "reason": "Internal Server Error", "message": "Internal database error"}
The second issue is regarding the ctk. I do not know how to set up the config. Is there a tutorial?
docker-compose.yml
version: '3.8'
services:
mongo:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: mongodb
MONGO_INITDB_ROOT_PASSWORD: mongodb
# MONGO_INITDB_DATABASE: tmf
volumes:
- tmf_mongo:/data/db
# - '.mongodb/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro'
ports:
- '27017:27017'
restart: unless-stopped
mongo-express:
image: mongo-express:latest
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: mongodb
ME_CONFIG_MONGODB_ADMINPASSWORD: mongodb
ME_CONFIG_MONGODB_URL: mongodb://mongodb:mongodb@mongo:27017/
app:
build: .
ports:
- 8080:8080
depends_on:
- mongo
command: [ "./wait-for", "mongo:27017", "--timeout=300", "--", "node", "index.js" ]
volumes:
tmf_mongo:
sample-app config.json (not ctk)
{
"db_prot": "mongodb",
"db_user": "mongodb",
"db_password": "mongodb",
"db_host": "mongo",
"db_port": 27017,
"db_name": "tmf",
"alarm_host": "http://localhost:10011",
"alarm_url_hal": "/api/",
"strict_schema": true
}
------------------------------
Ahmed Jalwan Waheed
Dhivehi Raajjeyge Gulhun Plc
------------------------------