Gitlab CI: Build & push Docker image to AWS ECR (Elastic Container Registry)

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

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

  • @vdespa
    @vdespa  4 года назад +2

    👉 Want to learn more about CI/CD and DevOps? Check my Gitlab CI online course.
    vdespa.com/courses/

    • @zembelallan5768
      @zembelallan5768 3 года назад

      My Image is already in ECR, how can I update my Image🤣

    • @vdespa
      @vdespa  3 года назад

      @@zembelallan5768 Use the same process as shown here.

  • @anthonycollins2669
    @anthonycollins2669 3 года назад +5

    Excellent tutorial, Valentin. Everything explained very clearly and concisely. And I really liked how you showed how the .gitlab-ci.yml evolved and why it evolved that way. Nicely done!

    • @vdespa
      @vdespa  3 года назад

      Thanks, Anthony!

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

    man! the order you explains is perfect! thank you very much! you dont just start writing, you have an order and excellent way to teach us, thanks

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

      You're welcome 😁

  • @davidpccode
    @davidpccode 4 года назад +3

    This is amazing. Actually I just bougth your Udemy course... you explain things in a very clear way.. Thanks

    • @vdespa
      @vdespa  4 года назад

      Thanks, David!

  • @rafaelmariotti778
    @rafaelmariotti778 4 года назад +3

    great video! and just to update one thing that is missing nowadays:we also have to configure inside the variables the TLS certificate: DOCKER_TLS_CERTDIR: "". otherwise, docker will be available through port 2736 and not 2735. Well, at least I run into this issue with gitlab and that was how I fixed it :) But thanks for your video! really helped me!

    • @vdespa
      @vdespa  4 года назад

      Thanks for mentioning that.

    • @chiragkanhasoft2597
      @chiragkanhasoft2597 4 года назад +2

      Its, failing for port 2736, 2735 even i set DOCKER_TLS_CERTDIR: "" in variables. Any suggestion ??

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

    my friend is excellent better than many pied training.

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

      Great to hear that. Thank you!

  • @jfgomez0912
    @jfgomez0912 3 года назад +2

    Really appreciate the content and the knowledge that you share with us in this video. It is very helpful and probably I will implement it for my projects.
    Thank you!

    • @vdespa
      @vdespa  3 года назад

      Glad it was helpful!

  • @gopalbugad
    @gopalbugad 12 дней назад

    Great It works for me, I was facing issue with pipeline build - getting error like "docker and aws command not found". But now it's going smooth without error. Thanks..!

    • @vdespa
      @vdespa  3 дня назад

      Thanks for sharing. You are welcome. Thank you for leaving a comment.

  • @xiaopang254
    @xiaopang254 3 года назад +5

    If you can't get past the AWS CLI Login..
    First, check if you're running against a "Protected" branch. If you're not, that is probably the reason.
    By default when setting the Variable, the "Protected" tagged is checked.
    As defined by GitLab, Protected variables are only exposed to protected branches or tags.
    The solution to this is to either include that branch with the "Protected" tag or uncheck the "Protected" tag in the variable.
    Master branches have a "Protected" tag by default.

    • @vdespa
      @vdespa  3 года назад

      Thanks for sharing.

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

    excellent one, thanks for sharing , can u share if u have done same with Kaniko in place of docker deamon .

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

      Thanks. No, I did not use Kaniko yet.

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

    Thanks for the explanation

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

      You are welcome. Thank you for leaving a comment.

  • @mayureshpatilvlogs
    @mayureshpatilvlogs 4 года назад +9

    Please make video on automatically deployment on AWS ECS fargat using gitlab cicd

    • @vdespa
      @vdespa  4 года назад +4

      Will do, thanks for the suggestion.

    • @bluseisthe
      @bluseisthe 4 года назад

      @@vdespa waiting for it.

    • @rotembuhbut
      @rotembuhbut 4 года назад +2

      Great video waiting for it too

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

    I keep failed to follow gitlab official document, but finally I did work from your video!
    Thanks a lot!
    looks like gitlab-ci 's deploy image is outdated or something wrong with official doc :/

    • @vdespa
      @vdespa  3 года назад

      Glad it helped

  • @idouxda
    @idouxda 9 месяцев назад

    Great Job. I was able to follow along. I just had to add the variable DOCKER_TLS_CERTDIR. Could you use docker:dind as the base image and install aws-cli in it?

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

    Thanks a lot for this video!

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

      Glad it was helpful!

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

    cool job bro, thanks for your time

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

      No problem 👍! You are welcome. Thank you for leaving a comment.

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

    you have a the video with a example with docker-compose push to ecr from pipeline gitlab?

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

      Not yet, but it is coming soon. Thanks for your comment.

  • @vladimirvrab2323
    @vladimirvrab2323 4 года назад +1

    Thank you, helped a lot :)

    • @vdespa
      @vdespa  4 года назад

      Glad it helped!

  • @rajashekhar433
    @rajashekhar433 4 года назад +1

    where did you run the command in gitlab for running the project??

    • @vdespa
      @vdespa  4 года назад

      All commands are executed by a Gitlab Runner. Was this your question?

    • @rajashekhar433
      @rajashekhar433 4 года назад

      @@vdespa right, but Have you created git-runner in this video.
      Thanks

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

    I got some issues running gitlabCI where the company forces to use their private registry for the images (they use jfrog). I would really appreciate if you could make tutorial video for gitlabCI using private registry

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

      Sure, thanks for the suggestion. Why did you have issues pushing to the private registry?

  • @maladil
    @maladil 4 года назад

    Did you include how you specify with gitlab runner is used, where that gitlab runner is running, and how that runner has to be setup? I might have missed it.

    • @vdespa
      @vdespa  4 года назад

      Good point. Any Gitlab CI runner with Docker will do. For this example, I have used the shared runners from GitLab.com

  • @andrewpopenko1087
    @andrewpopenko1087 4 года назад +1

    Great video, thx!

    • @vdespa
      @vdespa  4 года назад

      Thanks for watching.

  • @null1564
    @null1564 4 года назад +1

    Hi Valentin, what's the purpose of setting docker host to tcp://docker:2375? Nice vid btw!

    • @vdespa
      @vdespa  4 года назад

      This is needed so that the docker client can connect to the docker deamon. I think I have mentioned this in the video.

    • @null1564
      @null1564 4 года назад +1

      I was experiencing error where it's fixed by removing that line when I was using a shared runner. Figured that the docker host is already defined inside the shared runner. Thank you for your further explanation. Cheers!

    • @vdespa
      @vdespa  4 года назад

      @@null1564 thanks for letting me know. Was the shared runner from Gitlab or your own infrastructure?

    • @null1564
      @null1564 4 года назад

      @@vdespa it's from my own infrastructure

  • @luis_illo
    @luis_illo 4 года назад +1

    Thank you!

    • @vdespa
      @vdespa  4 года назад

      You are welcome!

  • @quinglover3520
    @quinglover3520 3 года назад

    Hi, Thank you for the video. I have a production and a development account and using one gitlab runner for both. It determines which to build and deploy to depending on the branch. How would I store the AWS Access and and Private Key for both in the same repo and use them in the runner?

    • @quinglover3520
      @quinglover3520 3 года назад

      Actually I think I found a solution
      - export AWS_ACCESS_KEY=$DEV_AWS_ACCESS_KEY
      - export AWS_SECRET_ACCESS_KEY=$DEV_SECRET_ACCESS_KEY
      Unless there's an easier way

    • @xiaopang254
      @xiaopang254 3 года назад

      @@quinglover3520
      You can set it this way for each job!
      for job 1:
      - aws configure set aws_access_key_id $DEV_AWS_ACCESS_KEY_ID
      - aws configure set aws_secret_access_key $DEV_AWS_SECRET_ACCESS_KEY
      - aws configure set region $DEV_AWS_DEFAULT_REGION
      for job2:
      - aws configure set aws_access_key_id $STAGING_AWS_ACCESS_KEY_ID
      - aws configure set aws_secret_access_key $STAGING_AWS_SECRET_ACCESS_KEY
      - aws configure set region $STAGING_AWS_DEFAULT_REGION
      for job3:
      - aws configure set aws_access_key_id $PROD_AWS_ACCESS_KEY_ID
      - aws configure set aws_secret_access_key $PROD_AWS_SECRET_ACCESS_KEY
      - aws configure set region $PROD_AWS_DEFAULT_REGION

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

    This is good!!

    • @vdespa
      @vdespa  3 года назад

      I am glad it helped.

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

    Is it possible to use aws S3 for pushing Docker images?

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

      No, it is not possible.

  • @ahmedhormal9831
    @ahmedhormal9831 3 года назад

    Thanks Valentin for this tuto, I am trying to push my docker image using jib, I used the same logic and I added a new step to launch the "mvn clean compile jib:build" but I have a 401 http code, must I combine these two steps, if yes how can I use two images in the same step (docker + maven) ?

    • @vdespa
      @vdespa  3 года назад

      401 indicates some missing credentials. Did you define the right variables to ensure you are authenticated?

  • @omarsuriel1112
    @omarsuriel1112 3 года назад

    Thanks brother! Now i need to find how to use the pipeline to grab it from the registry and deploy it to AWS ECS FARGATE.

  • @danilodenadaisicari4630
    @danilodenadaisicari4630 4 года назад +1

    Nice!! Thanksss

    • @vdespa
      @vdespa  4 года назад

      Thank you too!

  • @halilulrahamane8798
    @halilulrahamane8798 3 года назад

    how to CD GitLab over EKS? Thx for the good starter one.

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

      I am working on a tutorial. Thanks for your comment.

  • @abhijeetsamanta8390
    @abhijeetsamanta8390 4 года назад

    Hi Valentin, Thanks for save my time I was looking same thing It solved my issue partially could you please tell me how can this AWS ECR image will deploy on k8s aws cluster automatically with new version everytime?

    • @vdespa
      @vdespa  4 года назад +1

      nothing really happens automatically as ECR is not directly connected to k8s. Use kubectl set image to update the container version.

    • @abhijeetsamanta8390
      @abhijeetsamanta8390 4 года назад

      @@vdespa ​ Thanks for reply I am also doing same however is there any way to setup in pipeline its self so whenever pipeline completed it will deploy new deployment in aws k8s cluster?

  • @vipul338
    @vipul338 4 года назад

    Great video and really helpful.
    Just a concern, we are restricted using AWS Access Keys anywhere and advised to use IAM instance roles on our self runners.
    It would be really helpful if you can create a video to build and push images using IAM instance profile without using AWS Acces keys.
    Thanks in advance.

    • @vdespa
      @vdespa  4 года назад

      Thanks. So your runner is running in shell mode and not using Docker? Please clarify.

    • @vipul338
      @vipul338 4 года назад

      @@vdespa So, basically we've installed a self managed Gitlab runner on our EC2 instance and have installed the same following docs.gitlab.com/runner/install/linux-manually.html and registered the same on our Linux instance following the docs.gitlab.com/runner/register/
      Let me know if this helps and any further information required. Thanks for your time.

    • @vdespa
      @vdespa  4 года назад

      @@vipul338 Did you register the runner as a shell runner or are you using Docker?

    • @vipul338
      @vipul338 4 года назад

      @@vdespa Registered as shell runner.

  • @obinnaezedei856
    @obinnaezedei856 10 месяцев назад

    Wouldn't this mean that anyone that knows our docker registry can easily use aws erc get-login-password to deploy anything to our registry?

    • @vdespa
      @vdespa  10 месяцев назад

      No, it won't work. To use get-login-password you need to provide auth.

  • @aliabbasmerchant6212
    @aliabbasmerchant6212 4 года назад

    Thanks!

    • @vdespa
      @vdespa  4 года назад

      You bet!

  • @onepointb9758
    @onepointb9758 4 года назад

    The link to access the yml file is not working. thks

    • @vdespa
      @vdespa  4 года назад

      Thanks for reporting. I have updated the link.

  • @Hendrix312002
    @Hendrix312002 4 года назад

    I am getting the following error: Error: Cannot perform an interactive login from a non TTY device. i have setup the correct env variables.

    • @vdespa
      @vdespa  4 года назад

      Can you make your project public and share a link here?

    • @Hendrix312002
      @Hendrix312002 4 года назад +1

      @@vdespa I figured it out. I had an extra space at the end of one of my keys... doh! All set now. I also bought your Udemy course and I am looking forward to it. Cheers

    • @vdespa
      @vdespa  4 года назад

      @@Hendrix312002 thanks for letting me know.

  • @berndhuber8023
    @berndhuber8023 3 года назад

    Hello, i wanted to ask if you have a video or course about following specific use-case:
    - step 1. deploying multiple microservices as docker-images to AWS ECR within a Gitlab-Pipeline (this video is a good start!)
    - step 2. publishing specific versions of those docker-images from the AWS ECR to a multi-container elastic-beanstalk instance (maybe with help of a Dockerrun.aws.json file and help of AWS Codebuild ? )
    If you have any other good example to deploy multiple separate microservices (separate gitlab-projects) to one elastic-beanstalk instance (preferrable multi-docker-container) this would also be of great help!
    thx for this great video, and looking forward for any response :)

    • @vdespa
      @vdespa  3 года назад

      Hi, unfortunately I don't have further content that deals with your use-case. Try breaking down the problem into smaller steps and let me know where you got stuck.

  • @Pubg_mobile_shots
    @Pubg_mobile_shots 3 года назад

    I am getting this error --> Unable to locate credentials. You can configure credentials by running "aws configure"

    • @vdespa
      @vdespa  3 года назад

      Are you running this on the main branch?

  • @ashisbharadwaj9888
    @ashisbharadwaj9888 3 года назад

    How can I create a Windows Image in Gitlab CI and push it to AWS ECR ?

    • @vdespa
      @vdespa  3 года назад

      It is the same process. You just need to use one of the Windows base images.

  • @zappa8888
    @zappa8888 3 года назад

    I am getting amazon-linux-extras: command not found .... does anyone face the same problem ?

  • @pigrebanto
    @pigrebanto 3 года назад

    very good. but this is not covering the deployment part..!

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

    Hey Valentin, thanks for the great tutorial! Everything works for me apart from the last step which is connecting to AWS ECR. Is this method still valid? I am getting multiple retries and after around 20-30 the pipeline fails. Not really sure how can I TSHOOT the connection between GitLab and AWS? I have created the user in IAM, variables are added in CI/CD section of GitLAb. I am not getting any prompt like: Incorrect password etc.

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

      Hey, the method is still valid. What is the error you're getting?

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

      @@patrykbambo7247 What do you mean it is timing out? After 60 minutes or what?

  • @jnscollier
    @jnscollier 3 года назад

    $(aws ecr get-login --no-include-email --region ) returns command, then executes

    • @vdespa
      @vdespa  3 года назад

      Thanks for sharing. What is the advantage for using this?

  • @iandavidson9761
    @iandavidson9761 3 года назад

    if you need to name your access and secret keys different on the outside. You can do this in your script before the `aws ecr ...` command
    export AWS_ACCESS_KEY_ID=
    export AWS_SECRET_ACCESS_KEY=

    • @vdespa
      @vdespa  3 года назад

      Thanks for sharing.

  • @hendisantika
    @hendisantika 4 года назад

    Nice tutorial. But, I have this error:
    $ aws ecr get-login-password | docker login --username AWS --password-stdin $DOCKER_REGISTRY
    Unable to locate credentials. You can configure credentials by running "aws configure".
    Error: Cannot perform an interactive login from a non TTY device

    • @vdespa
      @vdespa  4 года назад

      Make sure you have defined the AWS credentials as environment variables.

    • @hendisantika
      @hendisantika 4 года назад

      @@vdespa Done.

    • @aleksey9442
      @aleksey9442 3 года назад

      @@vdespa Hi. I set up variables but still have same issue

    • @vdespa
      @vdespa  3 года назад +2

      @@aleksey9442 If you are in a branch, make sure the variables are not protected.

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

    Why don't you safe API id and API secret in GitLab secrets and use it?

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

    hi, your video and explanation is very nice. but when i try the docker build command, it saying "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ". i've tried DOCKER_HOST: tcp://docker:2375, DOCKER_HOST: tcp://localhost:2375 and without DOCKER_HOST

    • @1212412124
      @1212412124 6 дней назад

      Hey, did you ever solve this?

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

    we facing this error how to slove
    An HTTP Client raised an unhandled exception: Invalid header value b'AWS4-HMAC-SHA256 Credential=AKIAZVRYDK32OW27DJHO
    /20230509/us-east-1/ecr-public/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=c3164e06ba23f93eeb5677abfcee25d7cca686c71b7003ce5b6c266307394806'
    Error: Cannot perform an interactive login from a non TTY device

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

      It it hard to tell just from this error, but make sure that your AWS credentials are correctly set up.

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

    Thanks again Valentine! Guys a quick warning for all. Please copy your variables with one line, do not press enter. Otherwise you'll get sth like ```An HTTP Client raised an unhandled exception: Invalid header value b'AWS4-HMAC-SHA256 Credential=secret-id blah blah
    /20210424/us-west-2/ecr/aws4_request``` bla bla bla. See, Credential has
    which crashes our pipeline.

    • @vdespa
      @vdespa  3 года назад +2

      Thanks for sharing this!

    • @berkesenturk6188
      @berkesenturk6188 3 года назад

      @@vdespa You're welcome Valentin thank you :)