Skip to content

Commit 5cfd1f7

Browse files
authored
Merge pull request #190 from DefangLabs/d3-website
Deploying Defang with Defang - Part 2
2 parents 7f8b2e5 + d38166b commit 5cfd1f7

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
slug: deploying-defang-with-defang-part-2
3+
title: "Deploying Defang with Defang: Part 2"
4+
author: Defang Team
5+
tags: [defang-with-defang, deployment, defang-website]
6+
---
7+
8+
![Defang Compose Update](/img/defang-on-defang/part-2/header.png)
9+
10+
When we refreshed the Defang brand, we knew our website needed more than just a fresh coat of paint. It needed to become a more dynamic part of our stack. We needed some parts to be more flexible, some parts to be more interactive, and better aligned with how modern apps are organized and deployed. And what better way to take it there than to deploy it with Defang itself?
11+
12+
This is part of our ongoing "Defang on Defang" series, where we show how we're using our own tool to deploy all the services that power Defang. In this post, we're diving into how we turned our own website into a project to better understand how Defang can be used to deploy a dynamic Next.js apps and how we can improve the experience for developers.
13+
14+
---
15+
16+
## From S3 + CloudFront to Dynamic, Containerized Deployments
17+
18+
Our original site was a Next.js app using [static exports](https://nextjs.org/docs/pages/building-your-application/deploying/static-exports) deployed via S3 and fronted by CloudFront. That setup worked for a while—it was fast and simple. But with our brand refresh, we added pages and components where it made sense to use (and test for other developers) some Next.js features that we couldn't use with the static export:
19+
20+
- [React Server Components](https://nextjs.org/docs/app/building-your-application/rendering/server-components)
21+
- [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations)
22+
- [ISR](https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration)
23+
24+
That meant static hosting wouldn't cut it. So we decided to run the site as an app in a container.
25+
26+
That being said, our learnings from the previous setup *are* being used to develop the capabilities of Defang. We're using the experience to make sure that Defang can handle the deployment of static sites as well as dynamic ones. We'll keep you updated when that's ready.
27+
28+
---
29+
30+
## Deploying with Defang (and Why It Was Easy)
31+
32+
We already deploy our other services with Defang using Compose files. In fact, the static website actually already used a Dockerfile and Compose file to manage the build process. So we just had to make some minor changes to the Compose file to take into account new environment variables for features we're adding and make a few small changes to the Dockerfile to handle the new build process.
33+
34+
Some things we had to change:
35+
36+
**Adding [ports](https://docs.defang.io/docs/concepts/compose#ports) to the Compose file**:
37+
```yaml
38+
ports:
39+
- mode: ingress
40+
target: 3000
41+
published: 3000
42+
```
43+
44+
**Adding [domain](https://docs.defang.io/docs/concepts/domains) info the Composer file**:
45+
```yaml
46+
domainname: defang.io
47+
networks:
48+
public:
49+
aliases:
50+
- www.defang.io
51+
```
52+
53+
One other hiccup was that we used to do www to non-www redirects using S3. There are a few ways to switch that up, but for the time being we decided to use Next.js middleware.
54+
55+
Pretty soon after that, the site was up and running in an AWS account—with TLS, DNS, and both the `www` and root domains automatically configured. Pretty straightfoward!
56+
57+
---
58+
59+
## Real-World Lessons That Are Shaping Defang
60+
61+
Deploying the website wasn't just a checkbox—it helped surface real-world pain points and ideas for improvement.
62+
63+
### 1. Static Assets Still Need CDNs
64+
Even though the site is dynamic now, we still want assets like `/_next/static` to load quickly from a CDN. This made it clear that CDN support—like CloudFront integration—should be easier to configure in Defang. That’s now on our roadmap. That's also going to be useful for other frameworks that use similar asset paths, like Django.
65+
66+
### 2. Next.js Env Vars Can Be Tricky in Containers
67+
Next.js splits env vars between build-time and runtime, and the rules aren’t always obvious. Some need to be passed as build args, and others as runtime envs. That made us think harder about how Defang could help clarify or streamline this for developers—even if we can’t change that aspect of Next.js itself.
68+
69+
### 3. Redirects and Rewrites
70+
We had to add a middleware to handle www to non-www redirects. This is a common need, so we're keeping an eye on how we can make this easier to deal with in Defang projects.
71+
72+
These are the kinds of things we only notice by using Defang on real-world projects.
73+
74+
---
75+
76+
## The Takeaway
77+
78+
Our site now runs like the rest of our infrastructure:
79+
80+
- Fully containerized
81+
- Deployed to our own AWS account
82+
- Managed with a Compose file
83+
- Deployed with Defang
84+
85+
Stay tuned for the next post in the series—because this is just one piece of the puzzle.
86+
144 KB
Loading

0 commit comments

Comments
 (0)