You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cleanly separate Packaging and Deployment phases #8499
Derived from #8364 which was narrowed down to other processing flow improvements refactor
Currently internal flow of processing commands is convoluted and confusing in many places. In result there's a dependency between parts for which there is no reason to depend on each other (e.g. we cannot do sls deploy --package outside of service context, while after all outcome doesn't depend in any way on the current working directory context).
Additionally we should cleanly separate Packing and Deployment phase, taking into account case reported at #3528 where's there's reported need for builds that can be reused for any stage or region.
Ideally internal handling should be as follows
Packaging step, should package binaries and store resolved state of service configuration, but we should not generate CloudFormation template to be deployed at that stage.
Deployment should consist of:
Generation of ready to deploy CloudFormation template
Upload artifacts
Deployment of CloudFormation stack
In this context it'll be good to also address #2202 (provide a mean to run sls remove --name <service-name> outside of service context
Proposed solution
TBA
Reacted by Cory Dorning, João Dias, Bryant Biggs, Michael Heyns, Domas Lasauskas, Gidon Kremer, Brian G. Shacklett, CliffJumper, Ronny Roeller, lcy and 9 more
As written in #10170: For us it would be at this point in time quite desirable to have a step produce a final cloudformation template, so we can use cfn-lint on it to check for errors caused by serverless.yml/local plugin changes.
Thanks @ankon for the input. That's a very good point. I believe we should keep ability to generate the final CF template without deploying, and/or allowing to hook in a process after the template is generated but before deployment is initialized
My use case is to have separate build and deploy stages in CI. The build stage would have access to source tree, but not to AWS secrets. The deploy stage would have access to AWS, but neither to the full source repo nor to the full set of build tools, such as a C++ compiler to build native deps.
At the moment it's possible to realize this scenario, but only sometimes.
The build phase runs yarn, tsc, lint, test and whatnot, and finally it runs sls package and creates .serverless folder without a need for any credentials whatsoever, and it's passed to the next CI stage.
The deploy stage just needs the serverless.yml and the .serverless folder to perform a deployment.
This works fine, but some plugins break this nice model, collecting various state and configuration data from AWS during sls package.
I wonder if this use case deserves a separate issue.
Hello @nponeccop - that's what this issue is partially about (separating steps), but ensuring that sls package does not access AWS ever is not an easy task and cannot really be ensured on Framework level in a reasonable manner, as users by adding certain variables to serverless configuration e.g. cf, aws or ssm automatically enforce the packaging step to also reach for them to AWS which makes it impossible to make that process "offline".
The idea is to change the workflow, so network interaction is delayed, and it is only performed during the deployment phase.
A good example of such delay is the S3 bucket creation. It isn't created during packaging. Instead, the necessary check is performed during deployment.
I guess it's easier to understand the need for languages with clear separation of build time and run time dependencies. If I write a Go function in Lambda, I must be able to compile my executable entirely offline (at least without AWS access). And then pass it for deployment.
The build time code doesn't need to access AWS secrets, and the run time code doesn't need to access source code.
I guess the best course of action now is to forget about sls package as it's useless and just always use sls deploy. And the artefacts can be passed by the build system, which is out of scope of Serverless.
Hello @nponeccop - I understand the reasoning and I can see how ensuring offline build step might be a great benefit. If the issue would be addressed, then it will be easier to achieve that, however, in some cases, it still might become an online process, if user explicitly uses variables that reach e.g. ssm service during variable resolution step.
I understand that currently variable resolution step is performed during sls package, so essentially Serverless generates a dynamic CloudFormation file based on the SSM data during the packaging phase.
My idea is to change the process so that packaging and name resolution are separated. So as long as my project build artefacts don't depend on data stored at SSM, there is no need to connect. The variable resolution, CloudFormation generation etc are only performed during the deployment step.
A more important change is to make the plugin architecture aware of this phase separation, so that plugins authors plan accordingly what is permitted at what stage. Some plugins may choose to work offline, some during deployment, and some both.
Reacted by Domas Lasauskas, Brian G. Shacklett, Andreas Kohn, Gidon Kremer, Kat Lim Ruiz, dongj-woodside and Mike Lohmeier
Activity
ankon commentedon Nov 2, 2021
As written in #10170: For us it would be at this point in time quite desirable to have a step produce a final cloudformation template, so we can use
cfn-linton it to check for errors caused by serverless.yml/local plugin changes.medikoo commentedon Nov 2, 2021
Thanks @ankon for the input. That's a very good point. I believe we should keep ability to generate the final CF template without deploying, and/or allowing to hook in a process after the template is generated but before deployment is initialized
nponeccop commentedon Feb 7, 2022
My use case is to have separate
buildanddeploystages in CI. The build stage would have access to source tree, but not to AWS secrets. Thedeploystage would have access to AWS, but neither to the full source repo nor to the full set of build tools, such as a C++ compiler to build native deps.At the moment it's possible to realize this scenario, but only sometimes.
buildphase runsyarn,tsc,lint,testand whatnot, and finally it runssls packageand creates.serverlessfolder without a need for any credentials whatsoever, and it's passed to the next CI stage.deploystage just needs theserverless.ymland the.serverlessfolder to perform a deployment.This works fine, but some plugins break this nice model, collecting various state and configuration data from AWS during
sls package.I wonder if this use case deserves a separate issue.
pgrzesik commentedon Feb 8, 2022
Hello @nponeccop - that's what this issue is partially about (separating steps), but ensuring that
sls packagedoes not access AWS ever is not an easy task and cannot really be ensured on Framework level in a reasonable manner, as users by adding certain variables to serverless configuration e.g.cf,awsorssmautomatically enforce the packaging step to also reach for them to AWS which makes it impossible to make that process "offline".nponeccop commentedon Feb 10, 2022
The idea is to change the workflow, so network interaction is delayed, and it is only performed during the deployment phase.
A good example of such delay is the S3 bucket creation. It isn't created during packaging. Instead, the necessary check is performed during deployment.
I guess it's easier to understand the need for languages with clear separation of build time and run time dependencies. If I write a Go function in Lambda, I must be able to compile my executable entirely offline (at least without AWS access). And then pass it for deployment.
The build time code doesn't need to access AWS secrets, and the run time code doesn't need to access source code.
I guess the best course of action now is to forget about
sls packageas it's useless and just always usesls deploy. And the artefacts can be passed by the build system, which is out of scope of Serverless.pgrzesik commentedon Feb 11, 2022
Hello @nponeccop - I understand the reasoning and I can see how ensuring offline build step might be a great benefit. If the issue would be addressed, then it will be easier to achieve that, however, in some cases, it still might become an online process, if user explicitly uses variables that reach e.g.
ssmservice during variable resolution step.nponeccop commentedon Feb 11, 2022
I understand that currently variable resolution step is performed during
sls package, so essentially Serverless generates a dynamic CloudFormation file based on the SSM data during the packaging phase.My idea is to change the process so that packaging and name resolution are separated. So as long as my project build artefacts don't depend on data stored at SSM, there is no need to connect. The variable resolution, CloudFormation generation etc are only performed during the deployment step.
A more important change is to make the plugin architecture aware of this phase separation, so that plugins authors plan accordingly what is permitted at what stage. Some plugins may choose to work offline, some during deployment, and some both.
bgshacklett commentedon Mar 28, 2022
The resulting CloudFormation template should, ideally, resolve parameters/secrets directly from the appropriate service, anyway:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html. Using dynamic references removes the requirement for the CI software to be able to read the data within AWS.