Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/self-host-split-domains-static-dynamic/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Whenever a new release is published, publish it to the docker container registry on ghcr.io
name: Publish Docker image

on:
release:
types: [published]

# permissions are needed if pushing to ghcr.io
permissions:
contents: read
packages: write

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
name: Build and Push Docker image to GitHub Packages
runs-on: ubuntu-latest

steps:
# Get the repository's code
- name: Checkout code
uses: actions/checkout@v4
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Extract Publish Info
id: publish_info
run: |
echo "SOURCE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "SOURCE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ steps.publish_info.outputs.SOURCE_TAG }}
24 changes: 24 additions & 0 deletions examples/self-host-split-domains-static-dynamic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# build output
dist/

# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# jetbrains setting folder
.idea/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is just used so you can test out the final changes before this gets merged and published
# You need to comment the ".dockerignore" line for node_modules

FROM oven/bun:1 AS base

# copy production dependencies and source code into final image
FROM base AS runtime
COPY ./node_modules node_modules
COPY ./dist ./dist

# run the app
USER bun
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321/tcp
ENTRYPOINT [ "bun", "run", "./dist/server/entry.mjs" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This is just used so you can test out the final changes before this gets merged and published

FROM nginx:alpine AS runtime
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./dist/client /usr/share/nginx/html
EXPOSE 8080
35 changes: 35 additions & 0 deletions examples/self-host-split-domains-static-dynamic/Dockerfile-dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM oven/bun:1 AS base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

ENV NODE_ENV=production
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS runtime
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/dist ./dist

# run the app
USER bun
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321/tcp
ENTRYPOINT [ "bun", "run", "./dist/server/entry.mjs" ]
28 changes: 28 additions & 0 deletions examples/self-host-split-domains-static-dynamic/Dockerfile-static
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM oven/bun:1 AS base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

ENV NODE_ENV=production
RUN bun run build

FROM nginx:alpine AS runtime
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY --from=prerelease /usr/src/app/dist/client /usr/share/nginx/html
EXPOSE 8080
57 changes: 57 additions & 0 deletions examples/self-host-split-domains-static-dynamic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Astro Starter Kit: Self Host Split Domains Static Dynamic

```sh
npm create astro@latest -- --template self-host-split-domains-static-dynamic
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/self-host-split-domains-static-dynamic)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/self-host-split-domains-static-dynamic)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!

![just-the-basics](https://github.com/withastro/astro/assets/2244813/a0a5533c-a856-4198-8470-2d67b1d7c554)

This example shows how to build a site with two separate domains. One for serving static content and one for dynamic.

Both are bundled up in a Dockerfile. The static site can be deployed to a CDN, and the dynamic can be accessed directly.

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```text
/
├── public/
│ └── favicon.svg
├── src/
│ ├── components/
│ │ └── Card.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ └── index.astro
└── package.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.

Any static assets, like images, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :------------------------ | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:4321` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro -- --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
16 changes: 16 additions & 0 deletions examples/self-host-split-domains-static-dynamic/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import node from "@astrojs/node";
import astroDynamicStaticSplitDomain from "astro-dynamic-static-split-domain"
// @ts-check
import { defineConfig } from "astro/config";

// https://astro.build/config
export default defineConfig({
adapter: node({
mode: "standalone",
}),
integrations: [astroDynamicStaticSplitDomain(
{
serverIslandDynamicBase: "https://api.mysite.com",
}
)],
});
31 changes: 31 additions & 0 deletions examples/self-host-split-domains-static-dynamic/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
worker_processes 1;

events {
worker_connections 1024;
}

http {
server {
listen 8080;
server_name _;

root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;

gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}

location / {
try_files $uri $uri/index.html =404;
}
}
}
19 changes: 19 additions & 0 deletions examples/self-host-split-domains-static-dynamic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@example/self-host-split-domains-static-dynamic",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.9.4",
"@astrojs/node": "^9.0.0-alpha.1",
"astro": "^5.0.0-beta.5",
"typescript": "^5.6.2",
"astro-dynamic-static-split-domain": "0.0.1"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

await wait(5000);
---

<div>Slow avatar finally loaded</div>
Loading
Loading