Skip to content

BREAKING - Create build command and drop --noDeploy option #2660

Closed

Description

@flomotlik

This is a Feature Proposal

Description

Some use cases, especially with CI/CD demand the packages to be used for a deployment to be created beforehand. After #2659 is merged we can create a separate build command with its own lifecycle that can then be included by the deployment command.

serverless build without any options will package all artifacts for deployment to Lambda and put them in the .serverless folder

serverless build -f hello will only package the specified function and put it in the .serverless folder.

Both package commands will overwrite the artifact configuration of each function to point to the newly created artifacts so other commands like deploy or deploy function can pick them up and release the artifact. This only works if build runs as a dependency of those other commands.

Future extensions:

``serverless build --output (or -o)` will package all artifacts and put the artifacts into the specified

Similar or dependent issues:

Activity

  1. added this to the 1.4 milestone on Nov 8, 2016
  2. mthenw commented on Nov 8, 2016

    @mthenw
    Contributor

    Dropping --noDeploy is a breaking change so I'm not sure if we can release that in 1.*.

  3. flomotlik commented on Nov 8, 2016

    @flomotlik
    ContributorAuthor

    @mthenw FYI I'm only renaming the milestones once it comes up, basically because before the milestone is planned I don't necessarily know if a breaking change will be happening in it. So in this case it will be renamed and will then be at least 2.0

  4. johncmckim commented on Nov 9, 2016

    @johncmckim
    Contributor

    I think we need to be really clear on the goals and implementation of this issue.
    It will affect how #2659 is implemented.

    The main goal is to support pipeline style deployments. As part of pipelines we need to be able to run a series of steps lint / unit test -> package/build -> integration test -> deploy. The build artefact needs to be consistent between testing and deployment.

    This will also allow us to create temporary environments comprised of multiple services for testing purposes. i.e. I need to run integration testing on service-a which relies on service-b. To do this, I deploy service-a and a pre-packaged version of service-b to a test environment before running my tests.

    It seems to me that there are two distinct options for the implementation of build.

    Option 1 - code + serverless.yml

    This technique will require the user to modify serverless.yml. The user will need to use the package.artifact setting plus options to conditionally set it. For example

    package:
      artifact: ${opt:userArtifactOption}
    

    The first step in the pipeline would execute build. The command will zip the code and serverless.yml into a package. This could then be stored as an artefact in a build system.

    The second step in pipeline would extract the code + serverless.yml and use sls deploy --userArtifactOption /path/to/code.zip. This would create the CF templates on deploy and deploy them to AWS.

    Advantages

    • Uses existing features so it might be easier to implement
    • More configuration options - (this is also a disadvantage)

    Disadvantages

    • Requires user config in serverless.yml
    • CF templates are built on every deploy
    • CF templates could change between deployments - a bug or version change could cause this
    • The package is not independently deployable i.e. you couldn't just upload the CF + code to AWS yourself. (This isn't much of a disadvantage though)

    Option 2 - code + CF templates

    The first step in the pipeline will execute build. The command will zip the contents of .serverless. This will include code + create & update CF stacks.

    The second step in the pipeline would retrieve the artefact and use sls deploy --artifact /path/to/artifact.zip. This would skip the package step, extract the artifacts to .serverless and deploy the existing code + CF templates.

    Advantages

    • Better user experience - no config in serverless.yml
    • CF templates are built only once
    • CF templates won't change between deployments
    • The package not independently deployable

    Disadvantages

    • serverless.yml isn't available to sls which will will require some core changes
    • Support for deploying existing artifacts will have to be added to deploy
    • Plugins that deploy outside of CF wouldn't work i.e. external sns. I personally think they should use custom CF resources and not act outside of CF.

    Summary

    Clearly I'm in favour of option 2. I think it's a better user experience and more consistent. But it's probably a harder change to make. Happy to hear different thoughts on this.

  5. laardee commented on Nov 9, 2016

    @laardee
    Contributor

    @johncmckim, for me, the option 2 would be much better. I'm currently working on a project where I deploy zip + CloudFormation files (using --noDeploy) with Jenkins. Those files are then used later when the whole stack is deployed to AWS with Ansible.

  6. rowanu commented on Nov 10, 2016

    @rowanu
    Contributor

    Not sure if can go with either of your options @johncmckim; Option 2 sounds closer to what I imagined, but I'm confused about your proposal details:

    • Why does deploy require an --artifact argument? Wouldn't it just deploy the (pre-generated) artifacts in .serverless/?
    • Why would serverless.yml not be available to sls? I don't think sls should be doing anything without a serverless.yml, in general...

    I definitely don't think this change should require changes/additions to serverless.yml - it should be as transparent as possible to users who don't care about the build step i.e. they can continue to build and deploy in a single command if they want (which is something I often want to do). Only users who care about the build step need to know/worry about it. There may be advanced options, but there should be enough sensible defaults that no changes are required.

    In my mind I had imagined additional commands to facilitate this:

    sls build ... # builds template and function packages in .serverless/
    sls deploy ... # builds AND deploys the service, just like now
    sls push ... # ONLY deploys the service, based on existing artifacts in .serverless/ (and fails if none present)

    To be clear, I'm not in love with the name push but I'm just putting it out there to differentiate it from the other commands. This would be backwards compatible - you could continue to support deploy --noDeploy to avoid a version bump.

  7. johncmckim commented on Nov 11, 2016

    @johncmckim
    Contributor

    @rowanu that's a pretty interesting solution.

    I was including an --artifact argument so deploy could just take a package. It would be responsible for extracting it and putting it into .serverless if that's what was required.

    I think you're right about .serverless.yml having to be there. My thinking behind that was because the built package needs to remain unmodified by deploy. This means the package, function or resources config in serverless.yml are not used when deploying a built package. Though upon reflection, it might still need to check the provider settings.

    I like the UX of build & push (or another name) and having deploy coordinate those two commands. If #2659 is implemented deploy would just have build as a before command and push as an after command.

  8. 27 remaining items

  9. changed the title [-]Create build command and drop --noDeploy option[/-] [+]BREAKING - Create build command and drop --noDeploy option[/+] on Feb 8, 2017
  10. removed this from the 1.7 milestone on Feb 8, 2017
  11. arabold commented on Mar 2, 2017

    @arabold

    It is worthwhile noting that alias support as outlined above has been implemented by @HyperBrain as standalone plugin. This addresses most of my initial concerns and I'd like to encourage everybody on this thread to help beta testing: #2411 (comment)

    I believe there is still a need for a --build vs --deploy command line option though.

  12. modified the milestones: 1.9, 1.10 on Mar 9, 2017
  13. modified the milestones: 1.11, 1.10 on Mar 29, 2017
  14. modified the milestones: 1.12, 1.11 on Apr 12, 2017
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions