1

I have an application that I need to deploy in AWS.

The application has default properties which should be overridden for each env (qa/prd etc.) using overrides.properties file.

Source code of the application is composed to docker image and sent to GPR.

I have a CDK repo which takes docker image from GPR, stores it in ECR and creates a Fargate service with AutoScaling Group.

Here somehow I have to override default properties to the specific ones for different environments.

Is there an option in CDK to add a file (overrides.properties) to docker image or to pass it to ec2 instances before running the docker container?

wmel
  • 11
  • 3
  • Which properties are you referring to? Container environment variables? If it's just a config file, you can change your container code to use environment variables and pass them to the container - consult the ECS CDK docs on how to do that. – gshpychka Nov 03 '21 at 16:24
  • @gshpychka yes, it's a config file for the app. I've tried using environment variables, but it didn't work since the framework I have to use doesn't use env variables, and nothing I can do about it. Although it uses system properties but I didn't find a way to set system properties using CDK. – wmel Nov 03 '21 at 16:36
  • You can generate the config file from environment variables using a custom script in the container at startup. – gshpychka Nov 03 '21 at 16:57
  • @gshpychka good idea, thank you! tried it and it worked. The downside of this approach, of course, is that I'm setting the properties as environment variables, which seems a bit redundant, but hey, it works :) – wmel Nov 04 '21 at 14:13

1 Answers1

0

If someone finds themselves in the similar situation - posting a workaround'ish solution prorposed by @gshpychka

It's possible to set required properties as environment variables and add the script to store env variables to specific file to the Dockerfile for your image.

Sample script:

env | while IFS= read -r line; do
  echo "$line" >> /your/file/here
done
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
wmel
  • 11
  • 3