I want to upload a local file in the repository to s3 after it has been processed by a custom docker image with AWS CDK. I don’t want to make the docker image public (Its not a big restriction tho). Also, I don’t want to build the image for each s3 deployment
Since I don’t want to build the docker image for each bucket deployment, I have created a DockerImageAsset
, and tried to give image uri as BucketDeployment
‘s bundle property. Code is below:
const image = new DockerImageAsset(this, "cv-builder-image", {
directory: join(__dirname, "../"),
});
new BucketDeployment(this, "bucket-deployment", {
destinationBucket: bucket,
sources: [
Source.asset(join(__dirname, "../"), {
bundling: {
image: DockerImage.fromRegistry(image.imageUri),
command: [
"bash",
"-c",
'echo "heloo" >> /asset-input/cv.html && cp /asset-input/cv.html /asset-output/cv.html',
],
},
}),
],
});
DockerImageAsset
is deployed fine. But it throw this during BucketDeployment
‘s deployment
docker: invalid reference format: repository name must be lowercase
I can see the image being deployed to AWS.
Any help is appreciated. Have a nice dayy
2
Answers
As far as I understand – to simplify – you have a Docker image which you use to launch a utility container that just takes a file and outputs an artifact (another file).
Then you want to upload the artifact to S3 using the BucketDeployment construct.
This is a common problem when dealing with compiling apps like Java to .jar artifacts or frontend applications (React, Angular) to static output (HTML, CSS, JS) files.
The way I’ve approached this in the past is: Split the artifact generation as a separate step in your pipeline and THEN trigger the "cdk deploy" as a subsequent step.
You would have less headache and you control all parts of the process, including having access to the low level Docker commands like
docker build ...
anddocker run ...
, and in effect, leverage local layer caching in the best possible way. If you rely on CDK to do the bundling for you – there’s a bit of magic behind the scenes that’s not always obvious. I’m not saying it’s impossible, it’s just more "work".This can be done without utilizing DockerImageAsset. In this case the
Dockerfile
is stored at../src/app1
.Here is the sample docker image