Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to provide existing file digest #5589

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/commands/deploy/deploy.mjs
Expand Up @@ -304,6 +304,7 @@ const runDeploy = async ({
deployFolder,
deployTimeout,
deployToProduction,
existingFileDigest,
functionsConfig,
functionsFolder,
silent,
Expand Down Expand Up @@ -338,6 +339,7 @@ const runDeploy = async ({
// @ts-ignore
results = await deploySite(api, siteId, deployFolder, {
configPath,
existingFileDigest,
fnDir: functionDirectories,
functionsConfig,
statusCb: silent ? () => {} : deployProgressCb(),
Expand Down Expand Up @@ -640,6 +642,7 @@ const deploy = async (options, command) => {
deployFolder,
deployTimeout: options.timeout * SEC_TO_MILLISEC || DEFAULT_DEPLOY_TIMEOUT,
deployToProduction,
existingFileDigest: options.existingFileDigest,
functionsConfig,
// pass undefined functionsFolder if doesn't exist
functionsFolder: functionsFolderStat && functionsFolder,
Expand Down Expand Up @@ -780,6 +783,11 @@ Support for package.json's main field, and intrinsic index.js entrypoints are co
'Ignore any functions created as part of a previous `build` or `deploy` commands, forcing them to be bundled again as part of the deployment',
false,
)
.option(
'--existing-file-digest <json>',
'Preload the file digest with known existing assets for incremental deploys',
JSON.parse,
)
.addExamples([
'netlify deploy',
'netlify deploy --site my-first-site',
Expand Down
3 changes: 2 additions & 1 deletion src/utils/deploy/deploy-site.mjs
Expand Up @@ -31,6 +31,7 @@ export const deploySite = async (
deployId: deployIdOpt = null,
deployTimeout = DEFAULT_DEPLOY_TIMEOUT,
draft = false,
existingFileDigest = {},
filter,
fnDir = [],
functionsConfig,
Expand Down Expand Up @@ -122,7 +123,7 @@ For more information, visit https://ntl.fyi/cli-native-modules.`)
let deployParams = cleanDeep({
siteId,
body: {
files,
files: { ...existingFileDigest.files, ...files },
functions,
function_schedules: functionSchedules,
functions_config: fnConfig,
Expand Down
66 changes: 66 additions & 0 deletions tests/integration/incremental-site/README.md
@@ -0,0 +1,66 @@
# Incremental Deploys

In this example, we upload one directory, then we _append_ (incrementally upload) to the deploy with a new directory.
This can be leveraged for build-time "on-demand ISR"-like capabilities with CI/CD caching the previous deploys file
digest.

1. Upload the `base-deploy` directory to a Netlify site

```
netlify deploy -d ./base-deploy
```

> ```
> ...
> ✔ CDN requesting 4 files
> ...
> ```

2. Confirm file `one` exists:

```
curl -I https://$WEBSITE_DRAFT_URL/one
```

> ```
> HTTP/2 200
> ...
> ```

3. Upload the `new-deploy` directory, but pass the existing file digest JSON

```
netlify deploy -d ./new-deploy --existing-file-digest "$(<./base-deploy.json)"
```

> ```
> ...
> ✔ CDN requesting 1 files
> ...
> ```

4. Confirm file `two` exists

```
curl -I https://$WEBSITE_DRAFT_URL/two
```

> ```
> HTTP/2 200
> ...
> ```

5. Confirm file `one` also _still_ exists

```
curl -I https://$WEBSITE_DRAFT_URL/one
```

> ```
> HTTP/2 200
> ...
> ```

```

```
6 changes: 6 additions & 0 deletions tests/integration/incremental-site/base-deploy.json
@@ -0,0 +1,6 @@
{
"files": {
"netlify.toml": "395fc2be95377d1e0f95eec2cd983d7a26e48a39",
"one.html": "9e09cdc8f140342ddc2508380d43aa0447a46478"
}
}
1 change: 1 addition & 0 deletions tests/integration/incremental-site/base-deploy/one.html
@@ -0,0 +1 @@
a1ca9451cd6e8fc01daaa28d4becc997
1 change: 1 addition & 0 deletions tests/integration/incremental-site/new-deploy/two.html
@@ -0,0 +1 @@
952bf0d25bdc98adede3ed91065c7dc8