diff --git a/api/logic/job_logic.go b/api/logic/job_logic.go index b9881b538..a4f9e80e2 100644 --- a/api/logic/job_logic.go +++ b/api/logic/job_logic.go @@ -168,9 +168,11 @@ func (this *L0JobLogic) createJobDeploy(jobID string) (*models.Deploy, error) { context := struct { RunnerVersionTag string + DockerRegistry string Variables []struct{ Key, Val string } }{ RunnerVersionTag: config.RunnerVersionTag(), + DockerRegistry: config.DockerRegistry(), Variables: []struct{ Key, Val string }{ { Key: config.JOB_ID, @@ -243,7 +245,7 @@ var jobDockerrun string = ` "containerDefinitions": [ { "name": "l0-job", - "image": "quintilesims/l0-runner:{{ .RunnerVersionTag }}", + "image": "{{ .DockerRegistry }}/l0-runner:{{ .RunnerVersionTag }}", "essential": true, "memory": 64, "environment": [ diff --git a/common/config/config.go b/common/config/config.go index c99a25836..1fee83fce 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -39,6 +39,7 @@ const ( TEST_AWS_TAG_DYNAMO_TABLE = "LAYER0_TEST_AWS_TAG_DYNAMO_TABLE" TEST_AWS_JOB_DYNAMO_TABLE = "LAYER0_TEST_AWS_JOB_DYNAMO_TABLE" AWS_TIME_BETWEEN_REQUESTS = "LAYER0_AWS_TIME_BETWEEN_REQUESTS" + DOCKER_REGISTRY = "LAYER0_DOCKER_REGISTRY" ) // defaults @@ -173,6 +174,11 @@ func AWSRegion() string { return get(AWS_REGION) } +func DockerRegistry() string { + return get(DOCKER_REGISTRY) +} + + func AWSVPCID() string { return get(AWS_VPC_ID) } diff --git a/setup/command/init.go b/setup/command/init.go index b5db175aa..08c03a38d 100644 --- a/setup/command/init.go +++ b/setup/command/init.go @@ -42,6 +42,10 @@ func (f *CommandFactory) Init() cli.Command { Name: "aws-ssh-key-pair", Usage: instance.INPUT_AWS_SSH_KEY_PAIR_DESCRIPTION, }, + cli.StringFlag{ + Name: "docker-registry", + Usage: instance.INPUT_DOCKER_REGISTRY_DESCRIPTION, + }, }, Action: func(c *cli.Context) error { args, err := extractArgs(c.Args(), "NAME") @@ -72,6 +76,10 @@ func (f *CommandFactory) Init() cli.Command { overrides[instance.INPUT_AWS_SSH_KEY_PAIR] = v } + if v := c.String("docker-registry"); v != "" { + overrides[instance.INPUT_DOCKER_REGISTRY] = v + } + dockerPath := strings.Replace(c.String("docker-path"), "~", homedir.Get(), -1) instance := f.NewInstance(args["NAME"]) if err := instance.Init(dockerPath, overrides); err != nil { diff --git a/setup/instance/inputs.go b/setup/instance/inputs.go index cf0452b49..3f6f90184 100644 --- a/setup/instance/inputs.go +++ b/setup/instance/inputs.go @@ -20,6 +20,7 @@ const ( INPUT_PASSWORD = "password" INPUT_DOCKERCFG = "dockercfg" INPUT_VPC_ID = "vpc_id" + INPUT_DOCKER_REGISTRY = "docker_registry" ) const INPUT_SOURCE_DESCRIPTION = ` @@ -97,6 +98,11 @@ created for you. Existing VPCs must satisfy the following constraints: - The subnets in each tier cannot have overlapping availability zones Note that changing this value will destroy and recreate any existing resources. +` +const INPUT_DOCKER_REGISTRY_DESCRIPTION = ` +Docker registry (optional): The container registry (domain/layer0, eg: d.ims.io/layer0) from where the layer0 +pulls the image + ` type ModuleInput struct { @@ -177,6 +183,12 @@ var Layer0ModuleInputs = []*ModuleInput{ Description: INPUT_VPC_ID_DESCRIPTION, prompter: OptionalStringPrompter, }, + { + Name: INPUT_DOCKER_REGISTRY, + Default: "quintilesims", + Description: INPUT_DOCKER_REGISTRY_DESCRIPTION, + prompter: OptionalStringPrompter, + }, } func (m ModuleInput) Prompt(current interface{}) (interface{}, error) { diff --git a/setup/module/api/Dockerrun.aws.json b/setup/module/api/Dockerrun.aws.json index 486696a4a..613e03a73 100644 --- a/setup/module/api/Dockerrun.aws.json +++ b/setup/module/api/Dockerrun.aws.json @@ -1,7 +1,7 @@ [ { "name": "api", - "image": "quintilesims/l0-api:${layer0_version}", + "image": "${docker_registry}/l0-api:${layer0_version}", "essential": true, "memory": 500, "portMappings": [ @@ -37,6 +37,7 @@ { "name": "LAYER0_AWS_ECS_ROLE", "value": "${ecs_role}" }, { "name": "LAYER0_AWS_SSH_KEY_PAIR", "value": "${ssh_key_pair}" }, { "name": "LAYER0_AWS_ACCOUNT_ID", "value": "${account_id}" }, + { "name": "LAYER0_DOCKER_REGISTRY", "value": "${docker_registry}" }, { "name": "LAYER0_API_LOG_LEVEL", "value": "debug" }, { "name": "LAYER0_RUNNER_LOG_LEVEL", "value": "debug" } ] diff --git a/setup/module/api/deploy.tf b/setup/module/api/deploy.tf index 7e9eb3c23..b874627ef 100644 --- a/setup/module/api/deploy.tf +++ b/setup/module/api/deploy.tf @@ -26,5 +26,6 @@ data "template_file" "container_definitions" { log_group_name = "${aws_cloudwatch_log_group.mod.id}" dynamo_tag_table = "${aws_dynamodb_table.tags.id}" dynamo_job_table = "${aws_dynamodb_table.jobs.id}" + docker_registry = "${var.docker_registry}" } } diff --git a/setup/module/api/variables.tf b/setup/module/api/variables.tf index a8be99055..add78b095 100644 --- a/setup/module/api/variables.tf +++ b/setup/module/api/variables.tf @@ -8,6 +8,8 @@ variable "layer0_version" {} variable "vpc_id" {} +variable "docker_registry" {} + variable "username" {} variable "password" {} diff --git a/setup/module/main.tf b/setup/module/main.tf index f333563df..bf2332497 100644 --- a/setup/module/main.tf +++ b/setup/module/main.tf @@ -27,6 +27,7 @@ module "api" { layer0_version = "${var.layer0_version}" username = "${var.username}" password = "${var.password}" + docker_registry = "${var.docker_registry}" # todo: format hack is a workaround for https://github.com/hashicorp/terraform/issues/14399 vpc_id = "${ var.vpc_id == "" ? format("%s", module.vpc.vpc_id) : var.vpc_id }" diff --git a/setup/module/variables.tf b/setup/module/variables.tf index bbd8450d9..de6169c8b 100644 --- a/setup/module/variables.tf +++ b/setup/module/variables.tf @@ -20,3 +20,9 @@ variable "vpc_id" { description = "optional - use an empty string to provision a new vpc" type = "string" } + +variable "docker_registry" { + description = "optional - use an empty string to use dockerhub" + type = "string" + default = "quintilesims" +} \ No newline at end of file