Skip to content

Cleanly separate Packaging and Deployment phases #8499

Open

Description

@medikoo

Use case description

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

  1. 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.
  2. Deployment should consist of:
    1. Generation of ready to deploy CloudFormation template
    2. Upload artifacts
    3. 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

Activity

  1. ankon commented on Nov 2, 2021

    @ankon
    Contributor

    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.

  2. medikoo commented on Nov 2, 2021

    @medikoo
    ContributorAuthor

    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

  3. nponeccop commented on Feb 7, 2022

    @nponeccop

    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.

  4. pgrzesik commented on Feb 8, 2022

    @pgrzesik
    Contributor

    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".

  5. nponeccop commented on Feb 10, 2022

    @nponeccop

    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.

  6. pgrzesik commented on Feb 11, 2022

    @pgrzesik
    Contributor

    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.

  7. nponeccop commented on Feb 11, 2022

    @nponeccop

    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.

  8. bgshacklett commented on Mar 28, 2022

    @bgshacklett
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions