cdk-pipelines-github
cdk-pipelines-github copied to clipboard
Script for publishing assets should be stage specific
I have a pipeline that consists of two stages (staging and prod) deploying the same stack to different accounts depending on the branch. This correctly generates two independent workflows but the problem comes with the publish-Assets-FileAsset1-step.sh. As the asset ID is the same in both stages the file ends up with whatever the last stage wrote there, thus pointing to the wrong account/region.
I can confirm this is an issue I just ran into when attempting to add a second pipeline.
Any thoughts @kaizencc on when this PR might be able to be reviewed and released?
Hi @svyatogor + @mmoulton, thanks for your patience, sorry I wasn't able to get to this sooner.
Let me just make sure I have the issue right: the file that gets created in jobForAssetPublish is unique to the jobId. However, in your use case, you have two stages deploying the same stack, and since the stages have the same jobId, the file gets overwritten and consists of only what the second stage asks for.
If that's right, then it sounds like your solution is to have path.dirname(relativeToAssembly(assetManifestPath)) added to the file path to ensure uniqueness. This confuses me -- if the stacks are identical, won't the assetManifestPath be identical as well? At any rate, the PR changes would need a test to ensure that it works in this use case.
I think it would make more sense to do one of the following options instead:
- hash the contents of the file and add it to the filename
- add the stage name to the filename
Both of these would ensure uniqueness in the situation you've described, I think. If we can get the stage name, it would be best because that would be the most descriptive way of distinguishing between files.
@kaizencc sorry for taking long to reply, it is a vacation period here.
The stack are identical, but different stages are deployed to different accounts/regions, as the publish script along with the contents hash includes this information as well:
npx cdk-assets --path "cdk.out/assembly-production/productionmyapp2b5CD2881B.assets.json" --verbose publish "CONTENT_HAS:AWS_ACCOUNT-eu-central-1"
By adding path.dirname(relativeToAssembly(assetManifestPath)) I move the script from the root of cdk.out to the assembly (assembly-production in this case) ensuring that one stage doesn't overwrite the other.