How to build and publish Docker Image with Terraform and AWS ECR

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024

Комментарии • 40

  • @faustogomez7139
    @faustogomez7139 Год назад +1

    Thanks for the video Pablo!

  • @dhanielr
    @dhanielr 2 года назад +1

    Thanks man! very nice explanation

  • @Владислав-о1у
    @Владислав-о1у 2 года назад +1

    Thanks! You explained it well!

  • @TheConnectcut
    @TheConnectcut 2 года назад +1

    Amazing!!! Thanks for the video!!

  • @pablosspot
    @pablosspot  2 года назад

    If you get X-Registry-Auth error, make sure that the address property inside the registry_auth block inside the provider is set properly and points to ECR. The format is usually ".dkr.ecr..amazonaws.com"

  • @CarimFadil
    @CarimFadil 2 года назад +1

    Thanks Pablo!

  • @rafaelbeckermagazord2174
    @rafaelbeckermagazord2174 2 года назад +1

    Thank you man!

  • @fabien134
    @fabien134 3 года назад +1

    Thank you!!

  • @ZergStylexDD
    @ZergStylexDD 2 года назад +2

    I have the same issue X-Registry-Auth: EOF...
    I double checked anything (username, password, image name, address) and I still get the same error. Here is my code:
    provider "docker" {
    registry_auth {
    address = module.ecr.repository_url
    username = data.aws_ecr_authorization_token.token.user_name
    password = data.aws_ecr_authorization_token.token.password
    }
    }
    resource "docker_registry_image" "backend" {
    name = "${module.ecr.repository_url}:latest"
    build {
    context = "blabla/bla"
    dockerfile = "Dockerfile"
    auth_config {
    auth = "123"
    host_name = module.ecr.repository_url
    }
    }
    }
    I find "auth_config" block in the internet, but i don't know what should i pass into the host_name variable...

    • @ZergStylexDD
      @ZergStylexDD 2 года назад

      please, help me if you can :)

    • @pablosspot
      @pablosspot  2 года назад

      Hi @@ZergStylexDD ,
      Firstly, i would verify what module.ecr.repository_url points to and make sure this is an ECR repository url.
      You dont need the auth_config block inside build. The registry_auth will take care of the connection to ECR.

    • @pablosspot
      @pablosspot  2 года назад +1

      May i know why you are using a module for this property? I would normally build the value of this as a string like "${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.region}.amazonaws.com"

    • @ZergStylexDD
      @ZergStylexDD 2 года назад

      @@pablosspot I fix this, thank you. I don't know why my 2 previous message was deleted, but thank you :)

  • @chris.w391
    @chris.w391 Год назад

    Thanks!

  • @nataliyaleloup2841
    @nataliyaleloup2841 2 года назад +1

    Hi! Thank you for video! I have tried to repeat but I receiver error: Error: Error pushing docker image: Error response from daemon: Bad parameters and missing X-Registry-Auth: EOF.....
    looks like I have to login with docker? shouldn't be registry_auth parameters already enough?? thank you!

    • @pablosspot
      @pablosspot  2 года назад +1

      Hello.
      Thank you for your question.
      When you run terraform, it will take care of the login to AWS ECR using the credentials and address provided inside the registry_auth inside the docker provider block (3:33). Could you check if this is set especially the address property?
      Also check if the name property inside docker_registry_name is set properly (4:54).
      Hope this helps.

    • @nataliyaleloup2841
      @nataliyaleloup2841 2 года назад +1

      @@pablosspot it was a problem with the image name 🙄 thank you for the quick reply!

    • @pablosspot
      @pablosspot  2 года назад

      You are most welcome :)

  • @bacharsaleh6984
    @bacharsaleh6984 Год назад

    nice. but when the source code changes and run terraform apply the new image will not be pushed to the registry with same tag.

    • @pablosspot
      @pablosspot  Год назад

      Thats right. I find it very easy to manage images this way - I can easily correlate an image tag with a git commit. So if a particular image is faulty, i know which commit has the changes that may have caused it to break.

  • @DamienMalakay
    @DamienMalakay 2 года назад

    how would you do outputs for each docker_registry_image which then can be used in another module? 🤔i'm trying to use the same example to refactor a bit of my code but I need the outputs of those images in another module and I keep having issues

    • @pablosspot
      @pablosspot  2 года назад

      You can output the entire object (maybe jsonencode the object so the output becomes a map). Or interpolate on the object to select only the fields you want to output. Ill try to create a quick video on this today hopefully ready by tomorrow. We’ll see :)

    • @DamienMalakay
      @DamienMalakay 2 года назад

      @@pablosspot Yeah i tried to do this-> jsonencode(docker_registry_image.images) and the plan ran but then it failed in the apply with "ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character '{' after object key:value pair" so I think the issue is that i need to pass a specific element but this is a bit beyond my knowledge. let me know if you ever make that video! thanks George

    • @pablosspot
      @pablosspot  2 года назад +1

      New episode on handling outputs coming up. It should become available tomorrow. Not sure if I managed to answer your question or if it even helps. Hopefully it does.

  • @tonycavanagh1929
    @tonycavanagh1929 Год назад

    So once your image is in ecr, how do you move it to your EC2 ?

    • @pablosspot
      @pablosspot  Год назад +1

      Hello. You will need docker installed on your ec2. And then you can run docker pull to pull the image on the EC2.

    • @tonycavanagh1929
      @tonycavanagh1929 Год назад

      @@pablosspot Thanks

  • @muthukumarramu3149
    @muthukumarramu3149 2 года назад +1

    Thanks for the video. Can i get this complete code pls

    • @pablosspot
      @pablosspot  2 года назад

      Thank you! I updated the description with this link to the source code.
      github.com/dyordsabuzo/infrastructure-for-event-driven-system/tree/95df283caabfc767e0364b190f2c5fed5f2176c5/infrastructure

  • @drakonnight
    @drakonnight 2 года назад

    Thanks for the video :) I'm getting this error "Error pushing docker image: Error response from daemon: Bad parameters and missing X-Registry-Auth: EOF", any ideas on how to solve it? (I'm setting all the auth parameters)

    • @pablosspot
      @pablosspot  2 года назад

      Looks like an authorization error to me.
      Try manually running a docker login on a terminal and see if it works.
      docker login -u -p

    • @drakonnight
      @drakonnight 2 года назад

      @@pablosspot I got a Login Suceeded when running that command in the cli

    • @drakonnight
      @drakonnight 2 года назад +1

      @@pablosspot It was my mistake, I was using "name" instead of "repository_url" in the docker_registry_image resource name. Thanks for your answer, keep up the good work

  • @agusavior_channel
    @agusavior_channel 2 года назад +2

    9:30
    Wtf? Really?

    • @pablosspot
      @pablosspot  2 года назад +1

      Yep. I was hoping this is something i could set from the terraform CLI but I have not figured out how to do it if it is possible, I ended up creating an adhoc shell script that makes an API call to update this property in terraform cloud OR the old fashion manual way like what i did here.

  • @user-ek6bf7hz3e
    @user-ek6bf7hz3e Год назад

    its not working, I guess its not working anymore because it is an old version

    • @pablosspot
      @pablosspot  Год назад

      I will have a look when I get the chance. Currently away for a break and don’t have access to a machine. Thank you for pointing this out

  • @davidboucaut8499
    @davidboucaut8499 2 года назад +1

    Mate your gun :)