-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to use environment variables in command #5501
Comments
Hello @vc0sta 👋
|
yes, the environment overrides should work as well, but the bucket name would be hardcoded. My goal is to get them dynamically, this is why I'm using cloudformation overrides. Regarding the latest tag, I'll try to make it clearer: We have 2 containers for the same application, first one is using a pre-built image and its expected for the tag to come from CI/CD. image:
location: myApplication:${TAG} for the sidecars, I was building the image from the Dockerfile sidecars:
startup:
image:
build:
dockerfile: copilot/sidecars/startup/Dockerfile The deploy command I'm using is I'll try with edit: |
Hello @vc0sta ! In your case main container should be tagged as |
In my interpretation there's one improvement possibility here: the ability of escaping dollar signs in the manifest. At the moment this manifest doesn't work and cannot be fixed (AFAIK): image:
# ...
command: echo "Hello ${name}"
variables:
name: world because Copilot will try to substitute If there was a way to escape the Copilot variable substitution syntax, @vc0sta could write a command shared across all environments and would only need to provide the environment variable with a cfn override:
sidecars:
startup:
image: public.ecr.aws/aws-cli/aws-cli:2.13.37
command:
"s3 sync s3://\\${BUCKET_NAME} \\${TARGET}"
variables:
TARGET: /var/data
- op: add
path: /Resources/TaskDefinition/Properties/ContainerDefinitions/1/Environment/-
value:
Name: BUCKET_NAME
Value: !Sub s3://${AddonsStack.Outputs.configurationfilesNameBucketName} |
it was showing :latest |
@vc0sta um, that's unexpected. Just to share - I tried the same thing: image:
location: some-image-locator:${TAG} and ran What baffles me is that, even if Copilot had failed to substitute the I know you've shared some manifest snippets - I'm sorry to ask for this again. Can you share the entire |
@Lou1415926 Sure. Here is the manifest: name: vcosta-test
type: Backend Service
image:
location: public.ecr.aws/nginx/nginx:${TAG}
depends_on:
startup: success
sidecars:
startup:
image:
build:
dockerfile: copilot/vcosta-test/Dockerfile
essential: false The Dockerfile is just a placeholder: FROM public.ecr.aws/aws-cli/aws-cli:2.13.37 This generates the following parameters: {
"Parameters": {
"ContainerImage": ":latest",
}
} If I comment out the startup container, or if I change it to a pre-built image, then the TAG is correctly evaluated: {
"Parameters": {
"ContainerImage": "public.ecr.aws/nginx/nginx:develop",
}
} |
Addresses: #5501 (comment) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
@vc0sta Thanks for sharing!! What you said helped a ton - the comment of "If I comment out the startup container, or if I change it to a pre-built image..." made me realize what the bug may have been. If you use I've sent out a fix #5555! Sorry for the trouble and the back and forth! |
oh, that was actually pretty quick solution! thank you very much! |
Hello! The fix is now released in v1.32.1: https://github.com/aws/copilot-cli/releases/tag/v1.32.1 |
I have one application that needs some files to be present during startup, as this files changes depending on the environment, the idea is to populate the service container whenever the container starts.
so I created an S3 bucket to store those files and the plan is to use a sidecar container:
This initially worked, the problem is that we have different buckets depending on the environment, how should I do this properly?
1. Using environment variables
The first option was to use env vars for the sidecar container, but I couldnt find the proper way to do that:
These variables are evaluated by copilot during deployment and I didn't found a way to properly scape them, is it possible?
2. Creating my own image
Second solution would be to create my own image, there I can define the entrypoint to do what I want.
To keep all files related to this deployment in the same place, I've defined a simple Dockerfile and pointed to it in the manifest:
That part worked flawlessly, the issue then was that the main container is not using the provided ${TAG} anymore, but it's trying to use ":latest" instead. Is it a known issue? should I open a ticket only for that?
3. Overrides
We finally found a working solution, by using overrides and changing the cloudformation template directly:
Keeping it like this is totally fine for us, but still looks like a workaround, please let me know if there is a better way to achieve this.
The text was updated successfully, but these errors were encountered: