Skip to content

Commit

Permalink
Docker image now gets provided the ServicesUrl, ServicesAuthType and …
Browse files Browse the repository at this point in the history
…ServicesAuthContext variables. Published docker image now uses also new mcma-core library
  • Loading branch information
Joost Rovers committed Jan 24, 2019
1 parent f32a172 commit e6f59b8
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 46 deletions.
11 changes: 10 additions & 1 deletion multi-cloud-ai-workflow/deployment/ec2/app-servers.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/* App servers */
data "template_file" "cloud_config_app_yml" {
template = "${file("ec2/cloud-config/app.yml")}"

vars {
services_url = "${var.services_url}"
services_auth_type = "${var.services_auth_type}"
services_auth_context = "${var.services_auth_context}"
}
}
resource "aws_instance" "app" {
count = "${var.aws_instance_count}"
ami = "${lookup(var.amis, var.aws_region)}"
Expand All @@ -9,7 +18,7 @@ resource "aws_instance" "app" {
vpc_security_group_ids = ["${aws_security_group.default.id}"]
key_name = "${aws_key_pair.deployer.key_name}"
source_dest_check = false
user_data = "${file("ec2/cloud-config/app.yml")}"
user_data = "${data.template_file.cloud_config_app_yml.rendered}"
iam_instance_profile = "${aws_iam_instance_profile.app_iam_instance_profile.id}"

tags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ runcmd:
# Pull the image
- sudo docker pull joostrovers/mcma-ec2-transform-service > /var/log/docker-install.log
# Run docker
- sudo docker run -d -p 80:8080 joostrovers/mcma-ec2-transform-service > /var/log/docker-run.log
- sudo docker run -d -e SERVICES_URL=${services_url} -e SERVICES_AUTH_TYPE=${services_auth_type} -e SERVICES_AUTH_CONTEXT=${services_auth_context} -p 80:8080 joostrovers/mcma-ec2-transform-service > /var/log/docker-run.log
4 changes: 4 additions & 0 deletions multi-cloud-ai-workflow/deployment/ec2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ variable "aws_ec2_private_subnet_cidr" {
variable "aws_account_id" {}
variable "global_prefix" {}

variable "services_url" {}
variable "services_auth_type" {}
variable "services_auth_context" {}

/* Ubuntu 16.04 amis by region */
variable "amis" {
description = "Base AMI to launch the instances with"
Expand Down
21 changes: 12 additions & 9 deletions multi-cloud-ai-workflow/deployment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ module "services" {
conform_workflow_id = "${module.workflows.conform_workflow_id}"
ai_workflow_id = "${module.workflows.ai_workflow_id}"

ec2_transform_service_hostname = "${module.ec2.elb.hostname}"
ec2_transform_service_hostname = "${module.ec2.elb.hostname}"

aws_account_id = "${var.aws_account_id}"
aws_access_key = "${var.aws_access_key}"
aws_secret_key = "${var.aws_secret_key}"
aws_region = "${var.aws_region}"
aws_account_id = "${var.aws_account_id}"
aws_access_key = "${var.aws_access_key}"
aws_secret_key = "${var.aws_secret_key}"
aws_region = "${var.aws_region}"
azure_location = "${var.azure_location}"
azure_account_id = "${var.azure_account_id}"
azure_subscription_key = "${var.azure_subscription_key}"
azure_api_url = "${var.azure_api_url}"
environment_name = "${var.environment_name}"
environment_type = "${var.environment_type}"
environment_name = "${var.environment_name}"
environment_type = "${var.environment_type}"
}

module "workflows" {
Expand Down Expand Up @@ -98,6 +98,10 @@ module "ec2" {
aws_region = "${var.aws_region}"
aws_instance_type = "${var.aws_instance_type}"
aws_instance_count = "${var.aws_instance_count}"

services_url = "${module.services.services_url}"
services_auth_type = "${module.services.services_auth_type}"
services_auth_context = "${module.services.services_auth_context}"
}

output "aws_region" {
Expand Down Expand Up @@ -165,7 +169,7 @@ output "workflow_service_url" {
}

output "workflow_service_notification_url" {
value = "${module.workflows.workflow_service_notification_url}"
value = "${module.workflows.workflow_service_notification_url}"
}

output "transform_service_url" {
Expand All @@ -183,4 +187,3 @@ output "azure_ai_service_url" {
output "ec2_transform_service_hostname" {
value = "${module.ec2.elb.hostname}"
}

6 changes: 5 additions & 1 deletion multi-cloud-ai-workflow/docker/docker-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ DOCKER_PASSWORD=password
AWS_ACCESS_KEY_ID=awsAccessKey
AWS_SECRET_ACCESS_KEY=awsSecretAccessKey

SERVICES_URL=servicesUrl
SERVICES_AUTH_TYPE=AWS4
SERVICES_AUTH_CONTEXT=x

IMAGE_NAME=${DOCKER_USER}/mcma-ec2-transform-service
EXT_PORT=8080
INT_PORT=8080
RETVAL=0

start() {
docker run -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} -p ${EXT_PORT}:${INT_PORT} -d ${IMAGE_NAME}
docker run -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} -e SERVICES_URL=${SERVICES_URL} -e SERVICES_AUTH_TYPE=${SERVICES_AUTH_TYPE} -e SERVICES_AUTH_CONTEXT=${SERVICES_AUTH_CONTEXT} -p ${EXT_PORT}:${INT_PORT} -d ${IMAGE_NAME}
RET=$?
if [ $RET -ne 0 ];
then
Expand Down
14 changes: 10 additions & 4 deletions multi-cloud-ai-workflow/docker/package-lock.json

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

93 changes: 63 additions & 30 deletions multi-cloud-ai-workflow/docker/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,80 @@ const transform = require('./transform');
const fs = require('fs');
const MCMA_CORE = require("mcma-core");

const appRouter = function (app) {
const AWS = require("aws-sdk");

const awsV4AuthenticatorConfig = {
accessKey: AWS.config.credentials.accessKeyId,
secretKey: AWS.config.credentials.secretAccessKey,
sessionToken: AWS.config.credentials.sessionToken,
region: AWS.config.region
}

const authenticatorAWS4 = new MCMA_CORE.AwsV4Authenticator(awsV4AuthenticatorConfig);

const authProvider = new MCMA_CORE.AuthenticatorProvider(
async (authType, authContext) => {
switch (authType) {
case "AWS4":
return authenticatorAWS4;
}
}
);

const resourceManagerConfig = {
servicesUrl: process.env.SERVICES_URL,
servicesAuthType: process.env.SERVICES_AUTH_TYPE,
servicesAuthContext: process.env.SERVICES_AUTH_CONTEXT,
authProvider
}

app.get('/', function (req, res) {
res.status(200).send('Welcome to MCMA EC2 Transform Service');
});
const appRouter = function (app) {

app.get('/', function (req, res) {
console.log(JSON.stringify(awsV4AuthenticatorConfig, null, 2));

app.post('/new-transform-job', async (req, res, next) => {
try {
if (req.body) {
res.sendStatus(200);
console.log(JSON.stringify(resourceManagerConfig, null, 2));

let job = req.body;
res.status(200).send('Welcome to MCMA EC2 Transform Service');
});

app.post('/new-transform-job', async (req, res, next) => {
try {
const output = await transform.start(job.input);
job.status = "COMPLETED";
job.output = output;
} catch (error) {
job.status = "FAILED";
job.statusMessage = error.message;
}
if (req.body) {
res.sendStatus(200);

let resourceManager = new MCMA_CORE.ResourceManager();
let job = req.body;

console.log('Send Callback:', job);
await resourceManager.sendNotification(job);
try {
const output = await transform.start(job.input);
job.status = "COMPLETED";
job.output = output;
} catch (error) {
job.status = "FAILED";
job.statusMessage = error.message;
}

} else {
res.status(500).send({error: 'No job found in given assignment'});
}
} catch (e) {
next(e);
}
});
let resourceManager = new MCMA_CORE.ResourceManager(resourceManagerConfig);

console.log('Send Callback:', job);
try {
await resourceManager.sendNotification(job);
} catch (error) {
console.log(error.toString())
}
} else {
res.status(400).send({ error: 'No job found in given assignment' });
}
} catch (e) {
next(e);
}
});


app.get('/log', function (req, res) {
let log = fs.readFileSync('deployment.log', 'utf-8');
res.send(log);
});
app.get('/log', function (req, res) {
let log = fs.readFileSync('deployment.log', 'utf-8');
res.send(log);
});
};

module.exports = appRouter;

0 comments on commit e6f59b8

Please sign in to comment.