serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

[serverless-next.js component] new service after every update ?

Open mikdatdogru opened this issue 7 years ago • 7 comments

Hi;

I try to deploy using serverless-next.js component via gitlab-ci. everything is perfect, zero config is a magic :) But there is something i don't understanding.

I push the app to the develop branch and it deployed to aws via Gitlab CI.

when I make a change to the app and push it again to develop branch, i expect to update for existing s3bucket, lambda and cloudfront services. but instead of updating it is creating a new one.

I need your idea on how I need to follow a path to correct this situation.

thanks.

# .gitlab-ci.yml

image: node:latest
stages:
  - deploy
serverless:
  stage: deploy
  only:
    - develop
  script:
    - npm install
    - npm install serverless-next.js --save-dev
    - npm install -g serverless
    - serverless

# serverless.yml
website:
  component: serverless-next.js
package:
  exclude:
    - ./**

image

image

image

mikdatdogru avatar Sep 19 '19 13:09 mikdatdogru

Great question @mikdatdogru !

You will need to commit your application state in source control. You'll find it in the .serverless directory. For example:

image

The serverless team is currently working on remote state storage so this won't be necessary in the future.

danielcondemarin avatar Sep 20 '19 14:09 danielcondemarin

Regarding this issue, I'm just deploying with serverless command and it's creating a new service each time. Is there a way to avoid that?

cristiam86 avatar Nov 19 '19 22:11 cristiam86

@cristiam86 This is a common problem. In the README, Daniel says to include the .serverless folder in your git repo.

On a technical note, it is because serverless components allow one to save state, however all state is saved locally. Until they make a plan to save that state somewhere in the cloud and bring it into the build process, we are forced to include the state (i.e. the .serverless folder) into our git repo.

barrysteyn avatar Nov 19 '19 23:11 barrysteyn

thanks @barrysteyn but I have already included the .serverless folder into the repo. In fact I'm the only one making changes a deploying it.

cristiam86 avatar Nov 20 '19 05:11 cristiam86

Yes, but the thing is that your state has probably changed (I’m guessing you have added resources or just removed your current setup and then put it up again). So do this: delete your state files (.serverless), then deploy again and then recommit the .serverless folder

barrysteyn avatar Nov 20 '19 05:11 barrysteyn

Thank you @barrysteyn, that worked!

cristiam86 avatar Nov 20 '19 16:11 cristiam86

Thank you @barrysteyn, that worked!

Not a problem. This is a problem with the way serverless components are implemented now, however I believe that this issue will be solved kinda soon.

barrysteyn avatar Nov 20 '19 17:11 barrysteyn