Skip to content

Commit 1c49085

Browse files
farnabazRihanArfanHugoRCD
authored
feat: environments + env sync API (#579)
Co-authored-by: Rihan <[email protected]> Co-authored-by: Hugo Richard <[email protected]>
1 parent a6e737e commit 1c49085

File tree

11 files changed

+2899
-3227
lines changed

11 files changed

+2899
-3227
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
title: Environments & Improved variable management
3+
description: "Create additional deployment environments & revamped environment variable management"
4+
date: 2025-06-06
5+
image: '/images/changelog/nuxthub-environments.png'
6+
authors:
7+
- name: Rihan Arfan
8+
avatar:
9+
src: https://avatars.githubusercontent.com/u/20425781?v=4
10+
to: https://bsky.app/profile/rihan.dev
11+
username: rihan.dev
12+
- name: Ahad Birang
13+
avatar:
14+
src: https://avatars.githubusercontent.com/u/2047945?v=4
15+
to: https://bsky.app/profile/farnabaz.dev
16+
username: farnabaz.dev
17+
---
18+
19+
::tip
20+
This feature is available on both [free and pro plans](/pricing) and in [`@nuxthub/core >= v0.9.0`](https://github.com/nuxt-hub/core/releases/tag/v0.9.0).
21+
::
22+
23+
We've been working hard on closing the gap between Pages and Workers, and improving the experience using NuxtHub. With this release, we've brought preview environments to Workers, and improved environment variables management.
24+
25+
## Environments
26+
27+
When we first introduced Cloudflare Workers support in NuxtHub, we only supported production deployments. Today, we're excited to announce that Workers now has the same powerful environment capabilities as Pages, making it easier than ever to test and deploy your applications. Any deployment from a non-production branch automatically gets deployed to the preview environment with separate resources (database, kv, etc.) than production.
28+
29+
::note
30+
Due to Cloudflare limitations, deployments with the `cloudflare_durable` preset will not receive a unique deployment URL.
31+
::
32+
33+
### Custom Environments
34+
35+
We're taking things a step further and introducing the ability to create additional environments beyond just preview and production, such as staging, testing, etc. All environments in NuxtHub have unique resources, making them perfect for testing. NuxtHub allows configuring the branch patterns on custom environments with exact, prefix and suffix, to enable different workflows.
36+
- Example: The branch `staging` deploys to the staging environment
37+
- Example: All branches starting with `bugfix/` deploys to a testing environment
38+
39+
Get started from the new "Environments" page of NuxtHub Admin.
40+
41+
## Revamped environment variables management
42+
43+
The biggest challenge faced by users since introducing the NuxtHub GitHub Action as the primary method for deployment was syncing environment variables and secrets to GitHub. Our syncing relied on [environments in GitHub](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/managing-environments-for-deployment), which is a paid feature, therefore many NuxtHub users had to manually set environment variables to GitHub. Furthermore, GitHub Actions required specifying every secret used within the workflow which meant there was friction when using secrets, such as `NUXT_UI_PRO_LICENSE`.
44+
45+
We've worked hard to resolve this hurdle and to streamline the experience using NuxtHub. Now we're thrilled to introduce [`nuxt-hub/action@v2`](https://github.com/nuxt-hub/action), which now securely pulls environment variables and secrets from NuxtHub Admin, and builds your Nuxt application. On top of this, you can now scope environment variables to be build or runtime only, allowing you to further protect secrets.
46+
47+
### Migration guide
48+
49+
In order to use the new system, follow our migration guide:
50+
51+
1. Update to [`@nuxthub/core >= v0.9.0`](https://github.com/nuxt-hub/core/releases/tag/v0.9.0) on production and preview
52+
2. Go to Environment Variables within the NuxtHub Admin
53+
3. Click "Migrate environment variables"
54+
55+
#### Migrating to NuxtHub Action v2
56+
57+
1. Remove the `environments:` section
58+
2. Remove the `Build application` section
59+
3. Upgrade from `nuxt-hub/action@v1` to `nuxt-hub/action@v2`
60+
61+
See the updated GitHub Action workflow below:
62+
```diff
63+
name: Deploy to NuxtHub
64+
on: push
65+
66+
jobs:
67+
deploy:
68+
name: "Deploy to NuxtHub"
69+
runs-on: ubuntu-latest
70+
- environment:
71+
- name: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
72+
- url: ${{ steps.deploy.outputs.deployment-url }}
73+
permissions:
74+
contents: read
75+
id-token: write
76+
77+
steps:
78+
- uses: actions/checkout@v4
79+
80+
- name: Install pnpm
81+
uses: pnpm/action-setup@v4
82+
83+
- name: Install Node.js
84+
uses: actions/setup-node@v4
85+
with:
86+
node-version: 22
87+
cache: 'pnpm'
88+
89+
- name: Install dependencies
90+
run: pnpm install
91+
92+
- - name: Ensure NuxtHub module is installed
93+
- run: pnpx nuxthub@latest ensure
94+
-
95+
- - name: Build application
96+
- run: pnpm build
97+
98+
- - name: Deploy to NuxtHub
99+
- uses: nuxt-hub/action@v1
100+
- id: deploy
101+
- with:
102+
- project-key: <YOUR-PROJECT-KEY>
103+
104+
+ - name: Build & Deploy to NuxtHub
105+
+ uses: nuxt-hub/action@v2
106+
+ with:
107+
+ project-key: <YOUR-PROJECT-KEY>
108+
```
109+
110+
4. If your Nuxt app is not within the repository root and `directory:` parameter is provided, remove the trailing `/dist`.
111+
```diff
112+
- - name: Deploy to NuxtHub
113+
- uses: nuxt-hub/action@v1
114+
- with:
115+
- directory: frontend/dist
116+
117+
+ - name: Build & Deploy to NuxtHub
118+
+ uses: nuxt-hub/action@v2
119+
+ with:
120+
+ directory: frontend
121+
```
122+
123+
This release marks a significant milestone in our journey to provide a seamless deployment experience across both Pages and Workers. The introduction of preview environments and improved environment variables management brings feature parity between the two platforms, making it easier than ever to deploy and test your Nuxt applications. We're excited to see how you'll use these new capabilities to streamline your development workflow.

docs/content/docs/1.getting-started/3.deploy.md

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ NUXT_HUB_PROJECT_KEY=<my-project-key> NUXT_HUB_USER_TOKEN=<my-user-token> npx nu
9090

9191
This will authenticate your user and link your NuxtHub project for deployment.
9292

93-
::note
93+
::note
9494
For security, **do not hardcode these values**. Instead, store them as environment variables in your CI/CD pipeline.
9595
::
9696

@@ -130,9 +130,6 @@ jobs:
130130
deploy:
131131
name: "Deploy to NuxtHub"
132132
runs-on: ubuntu-latest
133-
environment:
134-
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
135-
url: ${{ steps.deploy.outputs.deployment-url }}
136133
permissions:
137134
contents: read
138135
id-token: write
@@ -143,23 +140,19 @@ jobs:
143140
- name: Install pnpm
144141
uses: pnpm/action-setup@v4
145142
with:
146-
version: 9
143+
version: 10
147144

148145
- name: Install Node.js
149146
uses: actions/setup-node@v4
150147
with:
151-
node-version: 22
148+
node-version: 24
152149
cache: 'pnpm'
153150

154151
- name: Install dependencies
155152
run: pnpm install
156153

157-
- name: Build application
158-
run: pnpm run build
159-
160-
- name: Deploy to NuxtHub
161-
uses: nuxt-hub/action@v1
162-
id: deploy
154+
- name: Build & Deploy to NuxtHub
155+
uses: nuxt-hub/action@v2
163156
```
164157
::
165158
@@ -170,8 +163,12 @@ jobs:
170163
The following input parameters can be provided to the GitHub Action. Learn more about [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepswith) on GitHub's documentation.
171164
172165
::field-group
173-
::field{name="directory" type="string" default="dist"}
174-
The directory of the built Nuxt application. Defaults to `dist`.
166+
::field{name="directory" type="string" default=""}
167+
The directory of the Nuxt application to build.
168+
::
169+
170+
::field{name="output-directory" default="dist"}
171+
The output directory containing the built Nuxt application to deploy, relative to the directory specified in `directory`.
175172
::
176173

177174
::field{name="project-key" type="string"}
@@ -203,32 +200,21 @@ The GitHub Action provides the following outputs that you can use in subsequent
203200
- https://example.nuxt.dev (main)
204201
- https://feat-example.example.pages.dev (feat/example)
205202
::
206-
::
207203

208-
### Environment Variables & Secrets
204+
::field{name="environment-url" type="string"}
205+
The permanent URL of the environment.
209206

210-
NuxtHub automatically copies all your project's environment variables to your GitHub repository actions environment variables.
211-
212-
When encrypting an environment variable in the NuxtHub Admin, a GitHub actions secret will be created in your repository.
213-
214-
You can view the environment variables and secrets synchronized by NuxtHub by navigating to **Repository Settings -> Secrets and variables -> Actions** on GitHub.
215-
216-
::warning
217-
If you have a private repository on a free GitHub account or organization, NuxtHub won't be able to sync the env variables & secrets as GitHub repository environments (production / preview) are not available. In this case, you must manually set up the environment variables by navigating to **Repository Settings -> Secrets and variables -> Actions** on GitHub.
207+
Examples:
208+
- https://hello-world-staging.example.workers.dev ('staging' environment)
209+
::
218210
::
219211

220-
In order to use GitHub Actions variables and secrets, you need to update your workflow to expose them as environment variables:
212+
### Environment Variables & Secrets
221213

222-
```diff [.github/workflows/nuxthub.yml]
223-
- name: Build application
224-
run: pnpm run build
225-
+ env:
226-
+ NUXT_PUBLIC_VAR: ${{ vars.NUXT_PUBLIC_VAR }}
227-
+ NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_LICENSE }}
228-
```
214+
The NuxtHub GitHub Action builds the Nuxt application using build-time environment variables and secrets specified within NuxtHub Admin.
229215

230-
::note
231-
This is mostly useful for build-time environment variables.
216+
::tip
217+
You can scope variables to only be available during build-time, This is useful in cases such as `NUXT_UI_PRO_LICENSE`.
232218
::
233219

234220
### Setup
@@ -300,8 +286,8 @@ The `NUXT_HUB_PROJECT_KEY` is used later in [Configure Projects for GitLab](#con
300286
workflow:
301287
auto_cancel:
302288
on_job_failure: all
303-
304-
variables:
289+
290+
variables:
305291
APP_PATH: "PATH/TO/YOUR/APP"
306292
NUXT_HUB_PROJECT_KEY: "YOUR_NUXT_HUB_PROJECT_KEY"
307293
@@ -320,11 +306,11 @@ deploy_project:
320306
# you can not use node_modules from cache, since nuxthub needs write access
321307
- bun install
322308
# if you set up your variables correctly this should deploy successfully
323-
- bunx nuxthub deploy
309+
- bunx nuxthub deploy
324310
rules:
325311
# here we configure auto deploy on branch: staging and main
326312
- if: '$CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == "main"'
327-
313+
328314
manual_deploy_project:
329315
stage: deploy
330316
image: "oven/bun:slim"
@@ -394,7 +380,7 @@ trigger_project_b:
394380
strategy: depend
395381
include:
396382
- local: "apps/project-bar/.gitlab-ci.yml"
397-
383+
398384
add_manual_triggers:
399385
stage: trigger_apps
400386
trigger:
@@ -437,7 +423,7 @@ trigger_project_b:
437423
strategy: depend
438424
include:
439425
- local: "apps/project-bar/.gitlab-ci.yml"
440-
426+
441427
callback:
442428
stage: callback
443429
script:

0 commit comments

Comments
 (0)