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

Additional container in task definition #56

Closed
marcossantiago opened this issue Nov 19, 2018 · 4 comments
Closed

Additional container in task definition #56

marcossantiago opened this issue Nov 19, 2018 · 4 comments

Comments

@marcossantiago
Copy link

Hi there,

Congrats for the project. Quite impressive.

It's quite common to have a sidecar container where the image is built on every deploy. Is there a way to build/deploy 2 containers on a single task definition ? I am looking for way to deploy nginx + app containers but couldn't find a way to specify the second Dockerfile.

Thanks in advance.

@tongueroo
Copy link
Collaborator

@marcossantiago Thanks for the kind words.

Yup, this is one of the benefits of ufo. It allows you to fully customize the ECS task definition. The sidecar configuration is something I've had to do before. Hope this example helps. It's 2 containers, 1 apache and one app server. The apache server proxies to the app server.

Example below:

.ufo/templates/main.json.erb:

{
  "family": "<%= @family %>",
  "containerDefinitions": [
    {
      "name": "apache",
      "image": "<%= @apache_image %>",
      "memory": <%= @apache_memory %>,
      "cpu": <%= @apache_cpu %>,
      "essential": true,
      "portMappings": [
        {
          "containerPort": "<%= @apache_port %>",
          "protocol": "tcp"
        }
      ],
      "links": [
        "web"
      ]
    },
    {
      "name": "<%= @name %>",
      "image": "<%= @image %>",
      "cpu": <%= @cpu %>,
      <% if @memory %>
      "memory": <%= @memory %>,
      <% end %>
      <% if @memory_reservation %>
      "memoryReservation": <%= @memory_reservation %>,
      <% end %>
      <% if @container_port %>
      "portMappings": [
        {
          "containerPort": "<%= @container_port %>",
          "protocol": "tcp"
        }
      ],
      <% end %>
      "command": <%= @command.to_json %>,
      <% if @environment %>
      "environment": <%= @environment.to_json %>,
      <% end %>
      <% if @awslogs_group %>
      "logConfiguration": {
        "logDriver": "awslogs",
        "options": {
          "awslogs-group": "<%= @awslogs_group %>",
          "awslogs-region": "<%= @awslogs_region || 'us-west-2' %>",
          "awslogs-stream-prefix": "<%= @awslogs_stream_prefix %>"
        }
      },
      <% end %>
      "essential": true
    }
  ]
}

.ufo/variables/base.rb:

@image = helper.full_image_name # includes the git sha tongueroo/hi:ufo-[sha].
@cpu = 512
@memory_reservation = 1536
@environment = helper.env_file(".env")

# apache container settings
@apache_image = "1122334455.dkr.ecr.us-west-2.amazonaws.com/apache:2.4-2018-08-08-08-08"
@apache_memory = "256"
@apache_cpu = "256"
@apache_port = "443"

Closing out.

@marcossantiago
Copy link
Author

Thanks for the quick response. I understand it's possible to modify the task definition template, but I was actually asking for the build/push process.

In the example you sent, I would need to build and push the apache image beforehand, then specify in the task definition.

I am looking to build both images (the apache and the app) at the same time in a single ufo ship, however, as far as I can see you can only build the app Dockerfile at root of the project.

@tongueroo tongueroo reopened this Nov 20, 2018
@tongueroo
Copy link
Collaborator

@marcossantiago Ah I see! It is not possible build 2 separate Dockerfiles for 2 separate projects with one ufo ship command.

One approach is to have 2 separate projects with a top-level build.sh script that calls ufo within in each project folder. Use ufo on each project to build and push the Docker image individually. For example:

  • nginx/Dockerfile - the web server
  • demo/Dockerfile - the app server
  • build.sh - top-level script

The build.sh script would look something like this:

cd nginx # cd into the nginx project
ufo ship
NGINX_IMAGE=$(ufo docker name) # use to grab the name

cd .. # return to top level
cd demo # cd into the demo project
update-image.sh $NGINX_IMAGE # script updates the `@nginx_image` var in `.ufo/variables/base.rb`
ufo ship # deploys the demo Docker image with the most recent $NGINX_IMAGE

Might not be what you're looking for. 2 Dockerfiles in 2 different projects feels a little bit better IMHO.

Also, another approach if you're building and pushing the nginx image to ECR with ufo is to use some ruby to always look up the latest ECR image timestamped image dynamically using the API. Hope that helps.

@marcossantiago
Copy link
Author

Thanks for the input ! I think having a script to build the additional Docker image would do trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants