Skip to content

Commit fe98ce0

Browse files
committed
feat: build + runtime specification controls for sites and functions
1 parent a90a0ea commit fe98ce0

7 files changed

Lines changed: 122 additions & 36 deletions

File tree

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"dependencies": {
2222
"@ai-sdk/svelte": "^1.1.24",
23-
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@41152f5",
23+
"@appwrite.io/console": "https://pkg.vc/-/@appwrite/@appwrite.io/console@9163640",
2424
"@appwrite.io/pink-icons": "0.25.0",
2525
"@appwrite.io/pink-icons-svelte": "https://pkg.vc/-/@appwrite/@appwrite.io/pink-icons-svelte@bfe7ce3",
2626
"@appwrite.io/pink-legacy": "^1.0.3",

src/routes/(console)/project-[region]-[project]/functions/function-[function]/settings/+page.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ export const load = async ({ params, depends, parent }) => {
55
depends(Dependencies.VARIABLES);
66
depends(Dependencies.FUNCTION);
77

8-
const { runtimesList, specificationsList } = await parent();
8+
const { runtimesList, specificationsList, function: fn } = await parent();
9+
10+
const enabledSpecs = specificationsList?.specifications?.filter((s) => s.enabled) ?? [];
11+
if (!enabledSpecs.some((s) => s.slug === fn.buildSpecification)) {
12+
fn.buildSpecification = enabledSpecs[0]?.slug;
13+
}
14+
if (!enabledSpecs.some((s) => s.slug === fn.runtimeSpecification)) {
15+
fn.runtimeSpecification = enabledSpecs[0]?.slug;
16+
}
917

1018
const [globalVariables, variables] = await Promise.all([
1119
sdk.forProject(params.region, params.project).projectApi.listVariables(),
@@ -36,6 +44,7 @@ export const load = async ({ params, depends, parent }) => {
3644
variables,
3745
globalVariables,
3846
runtimesList,
39-
specificationsList
47+
specificationsList,
48+
function: fn
4049
};
4150
};

src/routes/(console)/project-[region]-[project]/functions/function-[function]/settings/updateResourceLimits.svelte

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import { isValueOfStringEnum } from '$lib/helpers/types';
1010
import { Runtime, type Models, type Scopes } from '@appwrite.io/console';
1111
import Link from '$lib/elements/link.svelte';
12-
import { Alert } from '@appwrite.io/pink-svelte';
12+
import { Alert, Icon, Tooltip } from '@appwrite.io/pink-svelte';
13+
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
1314
import { isStarterPlan, getChangePlanUrl } from '$lib/stores/billing';
1415
import { isCloud } from '$lib/system';
1516
import { organization } from '$lib/stores/organization';
@@ -18,11 +19,19 @@
1819
export let func: Models.Function;
1920
export let specs: Models.SpecificationList;
2021
21-
let specification = func.buildSpecification;
22-
let originalSpecification = func.buildSpecification;
23-
$: originalSpecification = func.buildSpecification;
22+
let buildSpecification = func.buildSpecification;
23+
let runtimeSpecification = func.runtimeSpecification;
24+
let originalBuild = func.buildSpecification;
25+
let originalRuntime = func.runtimeSpecification;
2426
25-
async function updateLogging() {
27+
$: {
28+
buildSpecification = func.buildSpecification;
29+
runtimeSpecification = func.runtimeSpecification;
30+
originalBuild = func.buildSpecification;
31+
originalRuntime = func.runtimeSpecification;
32+
}
33+
34+
async function updateResourceLimits() {
2635
try {
2736
if (!isValueOfStringEnum(Runtime, func.runtime)) {
2837
throw new Error(`Invalid runtime: ${func.runtime}`);
@@ -45,13 +54,12 @@
4554
providerBranch: func.providerBranch || undefined,
4655
providerSilentMode: func.providerSilentMode || undefined,
4756
providerRootDirectory: func.providerRootDirectory || undefined,
48-
buildSpecification: specification || undefined
57+
buildSpecification: buildSpecification || undefined,
58+
runtimeSpecification: runtimeSpecification || undefined
4959
});
5060
5161
await invalidate(Dependencies.FUNCTION);
5262
53-
originalSpecification = specification;
54-
5563
addNotification({
5664
type: 'success',
5765
message: 'Resource limits have been updated'
@@ -73,7 +81,7 @@
7381
}));
7482
</script>
7583

76-
<Form onSubmit={updateLogging}>
84+
<Form onSubmit={updateResourceLimits}>
7785
<CardGrid>
7886
<svelte:fragment slot="title">Resource limits</svelte:fragment>
7987
Define your function's compute specifications, including CPU and memory, to optimize performance
@@ -84,12 +92,33 @@
8492
</Link>.
8593
<svelte:fragment slot="aside">
8694
<InputSelect
87-
label="CPU and memory"
88-
id="resources"
95+
label="Build specification"
96+
id="build-specification"
97+
required
98+
disabled={options.length < 1}
99+
bind:value={buildSpecification}
100+
{options}>
101+
<Tooltip slot="info">
102+
<Icon icon={IconInfo} size="s" />
103+
<span slot="tooltip">
104+
CPU and memory used when building and packaging your function deployment.
105+
</span>
106+
</Tooltip>
107+
</InputSelect>
108+
<InputSelect
109+
label="Runtime specification"
110+
id="runtime-specification"
89111
required
90112
disabled={options.length < 1}
91-
bind:value={specification}
92-
{options} />
113+
bind:value={runtimeSpecification}
114+
{options}>
115+
<Tooltip slot="info">
116+
<Icon icon={IconInfo} size="s" />
117+
<span slot="tooltip">
118+
CPU and memory available to each function execution at runtime.
119+
</span>
120+
</Tooltip>
121+
</InputSelect>
93122

94123
<!-- always show upgrade on starters -->
95124
{@const isStarter = isStarterPlan($organization.billingPlanId)}
@@ -104,7 +133,10 @@
104133
</svelte:fragment>
105134

106135
<svelte:fragment slot="actions">
107-
<Button disabled={originalSpecification === specification} submit>Update</Button>
136+
<Button
137+
disabled={originalBuild === buildSpecification &&
138+
originalRuntime === runtimeSpecification}
139+
submit>Update</Button>
108140
</svelte:fragment>
109141
</CardGrid>
110142
</Form>

src/routes/(console)/project-[region]-[project]/sites/site-[site]/settings/+page.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export const load = async ({ params, depends, parent }) => {
4242
if (!enabledSpecs.some((s) => s.slug === site.buildSpecification)) {
4343
site.buildSpecification = enabledSpecs[0]?.slug;
4444
}
45+
if (!enabledSpecs.some((s) => s.slug === site.runtimeSpecification)) {
46+
site.runtimeSpecification = enabledSpecs[0]?.slug;
47+
}
4548

4649
return {
4750
site,

src/routes/(console)/project-[region]-[project]/sites/site-[site]/settings/updateBuildSettings.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
if (!specs.specifications.some((s) => s.slug === site.buildSpecification)) {
116116
site.buildSpecification = specs.specifications[0].slug;
117117
}
118+
if (!specs.specifications.some((s) => s.slug === site.runtimeSpecification)) {
119+
site.runtimeSpecification = specs.specifications[0].slug;
120+
}
118121
}
119122
}
120123
});
@@ -132,6 +135,10 @@
132135
? site.buildSpecification
133136
: enabledSpecs[0]?.slug;
134137
site.buildSpecification = specToSend;
138+
let runtimeSpecToSend = enabledSpecs.some((s) => s.slug === site.runtimeSpecification)
139+
? site.runtimeSpecification
140+
: enabledSpecs[0]?.slug;
141+
site.runtimeSpecification = runtimeSpecToSend;
135142
try {
136143
await sdk.forProject(page.params.region, page.params.project).sites.update({
137144
siteId: site.$id,
@@ -151,7 +158,8 @@
151158
providerBranch: site.providerBranch || undefined,
152159
providerSilentMode: site.providerSilentMode || undefined,
153160
providerRootDirectory: site.providerRootDirectory || undefined,
154-
buildSpecification: specToSend || undefined
161+
buildSpecification: specToSend || undefined,
162+
runtimeSpecification: runtimeSpecToSend || undefined
155163
});
156164
await invalidate(Dependencies.SITE);
157165
addNotification({

src/routes/(console)/project-[region]-[project]/sites/site-[site]/settings/updateResourceLimits.svelte

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import { sdk } from '$lib/stores/sdk';
99
import { Adapter, BuildRuntime, Framework, type Models } from '@appwrite.io/console';
1010
import Link from '$lib/elements/link.svelte';
11-
import { Alert } from '@appwrite.io/pink-svelte';
11+
import { Alert, Icon, Tooltip } from '@appwrite.io/pink-svelte';
12+
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
1213
import { getChangePlanUrl, isStarterPlan } from '$lib/stores/billing';
1314
import { isCloud } from '$lib/system';
1415
import { organization } from '$lib/stores/organization';
@@ -17,10 +18,19 @@
1718
export let site: Models.Site;
1819
export let specs: Models.SpecificationList;
1920
20-
let specification = site.buildSpecification;
21-
let originalSpecification = site.buildSpecification;
21+
let buildSpecification = site.buildSpecification;
22+
let runtimeSpecification = site.runtimeSpecification;
23+
let originalBuild = site.buildSpecification;
24+
let originalRuntime = site.runtimeSpecification;
2225
23-
async function updateLogging() {
26+
$: {
27+
buildSpecification = site.buildSpecification;
28+
runtimeSpecification = site.runtimeSpecification;
29+
originalBuild = site.buildSpecification;
30+
originalRuntime = site.runtimeSpecification;
31+
}
32+
33+
async function updateResourceLimits() {
2434
try {
2535
await sdk.forProject(page.params.region, page.params.project).sites.update({
2636
siteId: site.$id,
@@ -40,10 +50,10 @@
4050
providerBranch: site?.providerBranch || undefined,
4151
providerSilentMode: site?.providerSilentMode || undefined,
4252
providerRootDirectory: site?.providerRootDirectory || undefined,
43-
buildSpecification: specification || undefined
53+
buildSpecification: buildSpecification || undefined,
54+
runtimeSpecification: runtimeSpecification || undefined
4455
});
4556
await invalidate(Dependencies.SITE);
46-
originalSpecification = specification;
4757
4858
addNotification({
4959
type: 'success',
@@ -66,23 +76,44 @@
6676
}));
6777
</script>
6878

69-
<Form onSubmit={updateLogging}>
79+
<Form onSubmit={updateResourceLimits}>
7080
<CardGrid>
7181
<svelte:fragment slot="title">Resource limits</svelte:fragment>
72-
Define your sites's compute specifications, including CPU and memory, to optimize performance
73-
for your workloads. <Link
74-
href="https://appwrite.io/docs/advanced/platform/compute"
75-
external>
82+
Define your site's compute specifications, including CPU and memory, to optimize performance for
83+
your workloads. <Link href="https://appwrite.io/docs/advanced/platform/compute" external>
7684
Learn more
7785
</Link>.
7886
<svelte:fragment slot="aside">
7987
<InputSelect
80-
label="CPU and memory"
81-
id="resources"
88+
label="Build specification"
89+
id="build-specification"
90+
required
91+
disabled={options.length < 1}
92+
bind:value={buildSpecification}
93+
{options}>
94+
<Tooltip slot="info">
95+
<Icon icon={IconInfo} size="s" />
96+
<span slot="tooltip">
97+
CPU and memory used when installing dependencies and building your site for
98+
deployment.
99+
</span>
100+
</Tooltip>
101+
</InputSelect>
102+
<InputSelect
103+
label="Runtime specification"
104+
id="runtime-specification"
82105
required
83106
disabled={options.length < 1}
84-
bind:value={specification}
85-
{options} />
107+
bind:value={runtimeSpecification}
108+
{options}>
109+
<Tooltip slot="info">
110+
<Icon icon={IconInfo} size="s" />
111+
<span slot="tooltip">
112+
CPU and memory used when your site serves traffic, including server-side
113+
rendering (SSR).
114+
</span>
115+
</Tooltip>
116+
</InputSelect>
86117

87118
<!-- always show upgrade on starters -->
88119
{@const isStarter = isStarterPlan($organization.billingPlanId)}
@@ -97,7 +128,10 @@
97128
</svelte:fragment>
98129

99130
<svelte:fragment slot="actions">
100-
<Button disabled={originalSpecification === specification} submit>Update</Button>
131+
<Button
132+
disabled={originalBuild === buildSpecification &&
133+
originalRuntime === runtimeSpecification}
134+
submit>Update</Button>
101135
</svelte:fragment>
102136
</CardGrid>
103137
</Form>

0 commit comments

Comments
 (0)