Skip to content

Commit 312fc85

Browse files
authored
Merge pull request #417 from DefangLabs/lio/nextjs-static
Add static-files example
2 parents 93e1ec7 + 435ce49 commit 312fc85

File tree

6 files changed

+43
-6
lines changed

6 files changed

+43
-6
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,29 @@ A basic Next.js app with a Dockerfile and compose.yaml ready to deploy to AWS wi
1111
3. (optional) [Authenticate with AWS](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
1212
4. Run `defang compose up` in the root of this project
1313

14+
## Static Files (Experimental)
15+
16+
This example supports deployment to AWS as a static site. Static files will be copied to an S3 bucket. In the _affordable_
17+
deployment mode (the default), the static files will be served over HTTP from an S3 bucket.
18+
19+
:::info
20+
Note that some top-level domains (TLDs), such as `.app`, require HSTS, which will disallow browsers from accessing the site over HTTP. If you want to use such a TLD, you must serve the static files over HTTPS by using either the _balanced_ or _high_availability_ deployment mode.
21+
:::
22+
23+
To serve the static files over HTTPS, use either the _balanced_ or _high_availability_ deployment mode, which will create a CloudFront distribution in front of the S3 bucket.
24+
25+
To deploy this project as a static site, run:
26+
27+
```bash
28+
defang compose up -f compose.static.yaml --provider=aws --mode=balanced
29+
```
30+
1431
---
1532

1633
Title: Next.js
1734

1835
Short Description: A basic Next.js app.
1936

20-
Tags: Next.js, React, Docker, Node.js, TypeScript, JavaScript
37+
Tags: Next.js, React, Docker, Node.js, TypeScript, JavaScript, Static
2138

2239
Languages: nodejs

app/.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
.next
2+
.next
3+
out

app/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ RUN npm install
1414
COPY . .
1515

1616
# Build the Next.js app
17+
ARG NEXT_OUTPUT
1718
RUN npm run build
1819

20+
# If we're doing an export, copy all files from the out directory to /static
21+
# This is a workaround for Next.JS issue https://github.com/vercel/next.js/issues/59988
22+
RUN if [ "$NEXT_OUTPUT" = "export" ]; then \
23+
cp -R out/* /static/; \
24+
fi
25+
1926
# Expose the port that your app runs on
2027
EXPOSE 3000
2128

app/next.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
2+
const nextConfig = {
3+
output: process.env.NEXT_OUTPUT,
4+
};
35

46
export default nextConfig;

compose.static.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
app:
3+
extends:
4+
file: compose.yaml
5+
service: app
6+
build:
7+
args:
8+
NEXT_OUTPUT: export
9+
x-defang-static-files:
10+
folder: /static

compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
app:
33
restart: unless-stopped
4-
# domainname: mydomain.com # if you want to use your own domain
4+
# domainname: www.example.xyz # uncomment if you want to use your own domain
55
build:
66
context: ./app
77
dockerfile: Dockerfile
@@ -17,5 +17,5 @@ services:
1717
deploy:
1818
resources:
1919
reservations:
20-
cpus: '0.50'
21-
memory: 512M
20+
cpus: "0.25"
21+
memory: 256M

0 commit comments

Comments
 (0)