Skip to content

Commit

Permalink
Merge pull request #109 from Moesif/dg-188626037-dockerize-devportal
Browse files Browse the repository at this point in the history
#188626037 Dockerize Dev Portal and Clean Up README.md
  • Loading branch information
dgilling authored Nov 28, 2024
2 parents 3e1d67d + 722c904 commit 241dcf9
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 662 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ npm-debug.log
npm-debug*
.vscode/
.devcontainer
my-dev-portal/.env
my-dev-portal-api/.env
my-dev-portal-api/.env
my-dev-portal-authorizer/.env
.DS_Store
*.zip
*.env
689 changes: 49 additions & 640 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions distribution/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.env
*.zip
*.log
14 changes: 14 additions & 0 deletions distribution/docker/Dockerfile-dev-portal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:18

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Bundle app source
COPY ./my-dev-portal /usr/src/app
RUN npm install
RUN npm run build
RUN npm install -g serve

EXPOSE 4000
CMD [ "serve", "-p", "4000", "-s", "build"]
18 changes: 18 additions & 0 deletions distribution/docker/Dockerfile-dev-portal-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:18

# Create app directory
RUN mkdir -p /usr/src/app
RUN mkdir -p /usr/src/plugins
WORKDIR /usr/src/app

RUN apt-get update && apt-get upgrade -y && \
apt-get install -y \
zip

# Bundle app source
COPY ./my-dev-portal-api /usr/src/app
COPY ./plugins /usr/src/plugins
RUN npm install

EXPOSE 3030
CMD [ "node", "app.js" ]
5 changes: 5 additions & 0 deletions distribution/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
PROJECT_ROOT=../../

docker build -f ./Dockerfile-dev-portal -t moesif/dev-portal $PROJECT_ROOT
docker build -f ./Dockerfile-dev-portal-api -t moesif/dev-portal-api $PROJECT_ROOT
31 changes: 31 additions & 0 deletions distribution/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '2'
services:
dev-portal:
image: moesif/dev-portal
ports:
- 4000:4000
environment:
- HOST=127.0.0.1
- PORT=4000
- REACT_APP_DEV_PORTAL_API_SERVER=http://dev-portal-api:3030
- REACT_APP_AUTH_PROVIDER=Auth0
- REACT_APP_AUTH0_DOMAIN=
- REACT_APP_AUTH0_CLIENT_ID=
- REACT_APP_STRIPE_PUBLISHABLE_KEY=
- REACT_APP_STRIPE_MANAGEMENT_URL=

dev-portal-api:
image: moesif/dev-portal-api
ports:
- 3030:3030
environment:
- FRONT_END_DOMAIN=127.0.0.1:4000
- MOESIF_APPLICATION_ID=
- MOESIF_MANAGEMENT_TOKEN=
- MOESIF_TEMPLATE_WORKSPACE_ID_LIVE_EVENT_LOG=
- MOESIF_TEMPLATE_WORKSPACE_ID_TIME_SERIES=
- STRIPE_API_KEY=
- APIM_PROVIDER=JWT
- JWT_SECRET=
- JWT_EXPIRES_IN=

6 changes: 5 additions & 1 deletion my-dev-portal-api/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require("express");
const path = require("path");
require("dotenv").config();
require("dotenv").config({ path: ['.env', '.env.template'] })
const bodyParser = require("body-parser");
const moesif = require("moesif-nodejs");
const cors = require("cors");
Expand Down Expand Up @@ -287,6 +287,10 @@ app.post("/create-key", jsonParser, async function (req, res) {
const stripeCustomer = await getStripeCustomer(email);
const customerId = (stripeCustomer.data && stripeCustomer.data[0]) ? stripeCustomer.data[0].id : undefined;

if (!customerId) {
throw new Error(`Customer Id unknown. Ensure you're subscribed to a plan. If you just subscribed, try again.`);
}

// Provision new key for access to API
const apiKey = await provisioningService.createApiKey(customerId, email);
// Send the Tyk API key back as the response
Expand Down
18 changes: 11 additions & 7 deletions my-dev-portal-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion my-dev-portal-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@stripe/stripe-js": "^1.29.0",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"express-jwt": "^8.4.1",
"http": "0.0.1-security",
Expand Down
10 changes: 5 additions & 5 deletions my-dev-portal-api/services/moesifApis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const moesif = require("moesif-nodejs");

const moesifManagementToken = process.env.MOESIF_MANAGEMENT_TOKEN;
const moesifManagementToken = process.env.MOESIF_MANAGEMENT_TOKEN
const moesifApiEndPoint = "https://api.moesif.com";

const moesifMiddleware = moesif({
Expand Down Expand Up @@ -39,7 +39,7 @@ function getPlansFromMoesif() {
`https://api.moesif.com/v1/~/billing/catalog/plans?includes=prices&provider=${process.env.APP_PAYMENT_PROVIDER}`,
{
headers: {
Authorization: `Bearer ${process.env.MOESIF_MANAGEMENT_TOKEN}`,
Authorization: `Bearer ${moesifManagementToken}`,
},
}
).then((res) => res.json());
Expand All @@ -52,7 +52,7 @@ function getCompany({ companyId }) {
)}`,
{
headers: {
Authorization: `Bearer ${process.env.MOESIF_MANAGEMENT_TOKEN}`,
Authorization: `Bearer ${moesifManagementToken}`,
},
}
).then((res) => res.json());
Expand All @@ -63,7 +63,7 @@ function getUser({ userId }) {
`https://api.moesif.com/v1/search/~/users/${encodeURIComponent(userId)}`,
{
headers: {
Authorization: `Bearer ${process.env.MOESIF_MANAGEMENT_TOKEN}`,
Authorization: `Bearer ${moesifManagementToken}`,
},
}
).then((res) => res.json());
Expand Down Expand Up @@ -112,7 +112,7 @@ function getSubscriptionForUserEmail({ email }) {
return fetch(`https://api.moesif.com/v1/search/~/search/users`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MOESIF_MANAGEMENT_TOKEN}`,
Authorization: `Bearer ${moesifManagementToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(query),
Expand Down
2 changes: 1 addition & 1 deletion plugins/auth0-m2m/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-portal-auth0-m2m-plugin",
"version": "1.0.0",
"description": "",
"main": "Auth0M2MProvisioningPlugin.js",
"main": "auth0M2MProvisioningPlugin.js",
"author": "",
"license": " Apache-2.0",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/jwt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-portal-jwt-plugin",
"version": "1.0.0",
"description": "",
"main": "JwtProvisioningPlugin.js",
"main": "jwtProvisioningPlugin.js",
"author": "",
"license": " Apache-2.0",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/kong-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-portal-kong-gateway-plugin",
"version": "1.0.0",
"description": "",
"main": "KongProvisioningPlugin.js",
"main": "kongProvisioningPlugin.js",
"author": "",
"license": " Apache-2.0",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/kong-konnect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-portal-kong-konnect-plugin",
"version": "1.0.0",
"description": "",
"main": "KonnectProvisioningPlugin.js",
"main": "konnectProvisioningPlugin.js",
"author": "",
"license": " Apache-2.0",
"dependencies": {
Expand Down

0 comments on commit 241dcf9

Please sign in to comment.