You want to build a Docker image from Python in CI and push it to ECR. What does the script need?
IntermediateScenarioKubernetes, Docker, SSH & fleet automation
Answer
Situation read → Auth to ECR plus build and push.
What I'd do →
- Get a token:
ecr.get_authorization_token()returns base64AWS:<password>and the proxy endpoint. docker.from_env().login(username="AWS", password=pw, registry=endpoint).- Build with
images.build(path=".", tag=f"{repo}:{sha}")(or shell out todocker buildx buildfor BuildKit features), thenimages.push(repo, tag=sha, stream=True, decode=True)and check each line forerror. - In GitHub Actions, the official
aws-actions/amazon-ecr-loginplusdocker/build-push-actionis simpler.
Why → The push stream reports errors inline; ignoring it hides failures.
Interview tip → Mention checking the push stream for errorDetail.
More on Kubernetes, Docker, SSH & fleet automation
You need a report of every pod in the cluster with no CPU or memory limits. How do you write it?BeginnerYou are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?AdvancedYou need to restart all Deployments in a namespace that reference a rotated Secret. How?AdvancedYour CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.IntermediateYou need to run `df -h` on 300 Linux hosts and list any above 85%. Python or Ansible?BeginnerA Python script SSHes to hosts with `AutoAddPolicy`. Security says that is unacceptable. What do you change?Intermediate