I have several projects that are built, shipped and deployed by drone. I also manage multiple AWS accounts (dev, stage, prod etc) and Drone runs in a separate account (CI). Drone pushes to ECR and invokes Lambda functions in all other accounts using cross account IAM roles.
At the moment the pipeline configuration for all projects contain three copies of every step, for example, pushing the container to each account is repeated three times with conditionals.
To help keep dron files maintainable I propose to add variable indirection support while substituting variables in drone file.
Lets say I have two variabls
VAR_NAME=Gufran
USER_Gufran=enabled
and an expression:
${USER_${VAR_NAME}}
where value of VAR_NAME
can change across builds (deployment parameter for example) and USER_Gufran
is a build secret.
The expression should first resolve the value of VAR_NAME
and then ${USER_Gufran}. Finally, enabled
should be substituted for the expression.
If this expression is available then I can write each step in the pipeline without conditionals:
pipeline:
push:
image: plugins/ecr
repo: ${ACCOUNT_ID_${DRONE_DEPLOY_TO}}.dkr.ecr.us-east-1.amazonaws.com/app
and put ACCOUNT_ID_PRODUCTION
, ACCOUNT_ID_STAGING
in build secret.
Bash has support for indirect expansion (${!var}
) and variable indirection (\$$var
) but those are quite powerful and complex features. To keep things simple and consistent drone should utilize existing syntax for variable substitution and perform only one pass for secondary substitution.
If this is something acceptable then I can submit a pull request to https://github.com/drone/envsubst