sst icon indicating copy to clipboard operation
sst copied to clipboard

Skip web app deployment during `sst deploy`

Open kieranm opened this issue 5 months ago • 10 comments

Sometimes we just want to deploy our backend quickly without deploying our Next/Tanstack start apps which take a few minutes each to build.

Is it possible to request a feature like --skip-sites or something, or perhaps a more fine grained --exclude to exclude deploying certain components?

Apologies if I missed something already!

Thanks

kieranm avatar Jul 08 '25 10:07 kieranm

I've been using --target for only deploying other things but Sites but our 3 Next.js app was still being built which takes pretty long. So have been using the following patch.

https://gist.github.com/nurulhudaapon/dbcadd93acc5109dc49681b0c9cd8a43

I guess the best would be to respect the '--target' and only build, buildable components if they are in the target.

nurulhudaapon avatar Oct 03 '25 12:10 nurulhudaapon

You can always SKIP_SITES=1 sst deploy and just wrap the component with an if.

juxuanu avatar Dec 03 '25 19:12 juxuanu

I really like the Group approach mentioned here: https://github.com/sst/sst/issues/4738#issuecomment-2427575895

EthanShoeDev avatar Dec 03 '25 19:12 EthanShoeDev

@juxuanu Is SKIP_SITES=1 documented anywhere? I cannot find any reference to it.

If we wrap a component in an if, won't it be removed if the if is evaluated to false? I think we are just looking for a way to skip the deploy.

EthanShoeDev avatar Dec 03 '25 19:12 EthanShoeDev

thankfully Pulumi now has a --exclude flag: https://www.pulumi.com/blog/excluding-targets-from-stack-operations/

we need to update the Pulumi version to be able to use it: #5944

we'll need to add the flag to the CLI after that PR gets merged, should be easy

vimtor avatar Dec 03 '25 20:12 vimtor

Awesome @vimtor. Would love to see this feature land. Always having to deploy my web app whenever I do any infra change has been a real pain.

EthanShoeDev avatar Dec 03 '25 21:12 EthanShoeDev

@juxuanu Is SKIP_SITES=1 documented anywhere? I cannot find any reference to it.

I just made that up, anything to check in your if.

If we wrap a component in an if, won't it be removed if the if is evaluated to false? I think we are just looking for a way to skip the deploy.

That is true. You can also use the env var to decide if you want to destroy resources or not (like you probably do for prod). But yeah, a built in solution would be nicer.

juxuanu avatar Dec 03 '25 22:12 juxuanu

You can always SKIP_SITES=1 sst deploy and just wrap the component with an if.

Won't it delete the component?

nurulhudaapon avatar Dec 04 '25 15:12 nurulhudaapon

Won't it delete the component?

yes, it would

vimtor avatar Dec 04 '25 17:12 vimtor

@nurulhudaapon @vimtor I think you can always add }, {retainOnDelete: false}); as 3rd argument to any resource

shmuelhizmi avatar Dec 06 '25 10:12 shmuelhizmi

To avoid rebuilding the static sites when they haven't changed, we use Turborepo for automatic build caching. It is designed for monorepos with dependency-aware task execution and caching.

Using Turborepo, your static site definition would look like this:

new sst.aws.StaticSite('my-site', {
  path: '.',
  dev: { directory: 'apps/my-site', command: 'pnpm dev' },
  build: {
    command: `pnpm turbo run build --filter @org/your-site`,
    output: 'apps/my-site/dist',
  },
});

If there is a cache hit, the static site won't be rebuilt. Instead, the build output will be retrieved from the cache and placed in the output directory.

You can use the Vercel cache for Turborepo as a fully managed solution, or you can host the cache with a simple AWS Lambda function and S3 bucket. Here is an example repository demonstrating the self-hosted version. It's quite straightforward.

https://github.com/anatolzak/sst-static-site-caching/blob/main/sst.config.ts#L29-L43

https://github.com/user-attachments/assets/59b5ee34-362b-4b54-9412-d1166a6df395

anatolzak avatar Dec 13 '25 13:12 anatolzak