Skip to content

Commit 5fe92f9

Browse files
committed
Make it easy to build docker image.
1 parent 8110392 commit 5fe92f9

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ---------- Build stage ----------
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install pnpm (repo uses pnpm in its scripts)
7+
RUN npm install -g pnpm
8+
9+
# Install deps
10+
COPY package.json pnpm-lock.yaml ./
11+
RUN pnpm install --frozen-lockfile
12+
13+
# Build static-browser-server outputs
14+
COPY . .
15+
RUN npm run build # this runs build-relay and friends, generating out/preview
16+
17+
# ---------- Runtime stage ----------
18+
FROM nginx:alpine
19+
20+
# This is crucial: serve the *preview* directory as web root
21+
COPY --from=builder /app/out/preview /usr/share/nginx/html
22+
23+
# Nginx already listens on 0.0.0.0:80
24+
EXPOSE 80
25+
26+
CMD ["nginx", "-g", "daemon off;"]
27+

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
# Static browser server
22

33
A simple service worker used for the static template in sandpack, allowing users to develop websites like they would locally in the browser.
4+
5+
# Docker Build
6+
7+
Build docker image using the follow build command
8+
9+
```
10+
docker buildx build --platform linux/amd64 -t static-browser-server:0.1.0 .
11+
```
12+
13+
Run the docker image as follows
14+
```
15+
docker run --rm -p 8080:80 athenaintel/sandpack-static-server:0.1.0
16+
```
17+
18+
Test by visiting the following address, you should see some HTML.
19+
```
20+
curl http://localhost:8080
21+
```
22+
23+
In production you need to put this service behind a wildcard DNS record so dynamic URLs can be generated, that is beyond the scope of this doc.

servers/demo-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import fastifyStatic from "@fastify/static";
55
import path from "path";
66

77
const PORT = +(process.env.PORT || "4000");
8+
const HOST = process.env.HOST || "0.0.0.0";
89

910
const app = fastify({ logger: true });
1011

@@ -20,7 +21,7 @@ app.register(fastifyStatic, {
2021
});
2122

2223
// Run the server!
23-
app.listen({ port: PORT }, function (err, address) {
24+
app.listen({ port: PORT, host: HOST }, function (err, address) {
2425
if (err) {
2526
app.log.error(err);
2627
process.exit(1);

0 commit comments

Comments
 (0)