Skip to content

Commit

Permalink
OCEMCM-11036 (#661)
Browse files Browse the repository at this point in the history
* Introducing optional docker_registry input
* docker_registry for container definition
* Docker registry description updated

Authored-by: Mahesh <mbalasubramanyam@nz.imshealth.com>
  • Loading branch information
mb-nx authored Mar 9, 2021
1 parent 30743b6 commit f13f582
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api/logic/job_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": [
Expand Down
6 changes: 6 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions setup/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions setup/instance/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion setup/module/api/Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "api",
"image": "quintilesims/l0-api:${layer0_version}",
"image": "${docker_registry}/l0-api:${layer0_version}",
"essential": true,
"memory": 500,
"portMappings": [
Expand Down Expand Up @@ -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" }
]
Expand Down
1 change: 1 addition & 0 deletions setup/module/api/deploy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}
2 changes: 2 additions & 0 deletions setup/module/api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ variable "layer0_version" {}

variable "vpc_id" {}

variable "docker_registry" {}

variable "username" {}

variable "password" {}
Expand Down
1 change: 1 addition & 0 deletions setup/module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
Expand Down
6 changes: 6 additions & 0 deletions setup/module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit f13f582

Please sign in to comment.