Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Deploy Stage Optional #116

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

pcartas
Copy link
Contributor

@pcartas pcartas commented Jul 24, 2023

what

I create a new variable called deploy_stage_enabled, and then make dynamic the deploy stage of aws_codepipeline bitbucket and aws_codepipeline default

why

It allows you to create images without deploying them, which could be useful for creating dummy images. However, there's a catch-22 situation: when you create a service, you need an initial image that at least responds to the health path. But first, you need to run a pipeline, and the pipeline is not created before the service. Moreover, ECS (specially if you are using EC2) tends to cache images/references to those images, and if you always use the image with the 'latest' tag, you risk using an old image. To avoid this, it's good practice to tag your image twice (with 'latest' and a random tag). The idea behind this was to create a dummy image, pull it from my service module, and then push it with the correct tags to the ECR of the service (thereby making it the base image of the service). Then I would define my container as follows:

data "aws_ecr_image" "service_image" {
  repository_name = module.ecr.repository_name
  image_tag       = "${var.environment}-latest"

  depends_on = [
    module.ecr
  ]
}

module "container_definition" {
  source                       = "cloudposse/ecs-container-definition/aws"
  version                      = "0.58.1"
  container_name               = var.container_name
  container_image              = "${var.aws_account_id}.dkr.ecr.${var.region}.amazonaws.com/${var.project_name}:${data.aws_ecr_image.service_image.image_tags[1]}"
  #container_image              = "${var.aws_account_id}.dkr.ecr.${var.region}.amazonaws.com/${var.project_name}:${var.environment}-latest"
  container_memory             = var.container_memory
  container_memory_reservation = var.container_memory_reservation
  docker_security_options      = var.docker_security_options
  container_cpu                = var.container_cpu
  essential                    = var.container_essential
  readonly_root_filesystem     = var.container_readonly_root_filesystem
  environment                  = var.task_environment_variables
  secrets                      = var.task_environment_secret_variables
  port_mappings                = var.container_port_mappings
  log_configuration            = {
                                  "logDriver": "awslogs",
                                  "options": {
                                      "awslogs-group": "/ecs/${var.container_name}",
                                      "awslogs-region": "${var.region}",
                                      "awslogs-create-group": "true",
                                      "awslogs-stream-prefix": "ecs"
                                  }
                                  secretOptions = []
                                }
  depends_on = [
    module.ecr
  ]
}

@pcartas pcartas requested review from a team as code owners July 24, 2023 14:53
@hans-d
Copy link

hans-d commented Mar 2, 2024

/terratest

@hans-d hans-d added the stale This PR has gone stale label Mar 2, 2024
@hans-d
Copy link

hans-d commented Mar 3, 2024

@pcartas Hi, can you update the pr so that it passes the tests? otherwise, it is likely to be closed due to staleness.

@mergify mergify bot added triage Needs triage and removed stale This PR has gone stale labels Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants