I use CDK to generate a CloudFormation stack.
When I run cdk synth and cdk deploy, the ECR image and the Task definition don't get updated. In order to force the update, I have to:
- delete the built images from my local computer;
- delete the latest ECR image.
Deleting cdk.out/ does not seem to have positive effects.
I can't be sure, but it appears that it started happening after a while on this project.
[An LLM suggested to use const gitHash = execSync('git rev-parse HEAD').toString().trim(); as an extra hash; it doesn't always solve the problem though.]
The folder structure is a bit convoluted. This is because I want api/ to be a plug-in to the core code in my_module.py.
- src/
- my_module.py
- api/ # the cdk folder
- lib/
- api-stack.ts
- src
- main.py
- Dockerfile
This is the relevant snippet from api-stack.ts:
const asset = new ecrAssets.DockerImageAsset(
this,
`MyDockerImage`,
{
file: api/Dockerfile,
directory: path.join(__dirname, "..", ".."),
platform: ecrAssets.Platform.LINUX_AMD64
ignoreMode: cdk.IgnoreMode.DOCKER,
buildSecrets: buildSecrets,
buildSsh: buildSsh,
},
);
Structure of Dockerfile:
FROM ghcr.io/astral-sh/uv:0.9.8-debian
RUN apt update && apt install -y openssh-client git
COPY ...
COPY api/src/main.py /app/
WORKDIR /app
RUN --mount=type=ssh,required=true \
mkdir -p /root/.ssh && \
ssh-keyscan -t ed25519,rsa github.com >> /root/.ssh/known_hosts 2>/dev/null && \
uv sync
ENTRYPOINT ["uv", "run", "main.py"]