Documentation Index
Fetch the complete documentation index at: https://docs.bunny.net/llms.txt
Use this file to discover all available pages before exploring further.
This guide walks you through building and deploying an Astro application to Magic Containers with GitHub Container Registry. You’ll need:
- A GitHub account for source code and container registry
Don’t have a bunny.net account yet? Sign up and enable Magic Containers to get started.
Create the Astro app
Create a new Astro project:
npm create astro@latest app-astro
cd app-astro
Add the Node adapter
Astro requires an adapter for server-side rendering. Install the Node adapter:
This updates your astro.config.mjs to include the adapter:
import { defineConfig } from "astro/config";
import node from "@astrojs/node";
export default defineConfig({
output: "server",
adapter: node({
mode: "standalone",
}),
});
Create an API route
Create a simple endpoint to test the deployment:
import type { APIRoute } from "astro";
export const GET: APIRoute = () => {
return new Response(JSON.stringify({ message: "Hello from Bunny 🐰" }));
};
Run locally
Start the development server:
Visit http://localhost:4321 in your browser, or test the API route:
curl http://localhost:4321/index.json
Create the Dockerfile
FROM node:22-alpine AS base
WORKDIR /app
COPY package*.json ./
FROM base AS deps
RUN npm install
FROM deps AS build
COPY . .
RUN npm run build
FROM base AS runtime
COPY package*.json ./
RUN npm install --omit=dev
COPY --from=build /app/dist ./dist
ENV HOST=0.0.0.0
ENV PORT=80
EXPOSE 80
CMD ["node", "./dist/server/entry.mjs"]
Build and push to GitHub Container Registry
GitHub Actions
Docker CLI
Create .github/workflows/build.yml to automatically build and push on every commit to main:.github/workflows/build.yml
name: Build and Push
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Update container image on Magic Containers
uses: BunnyWay/actions/container-update-image@main
with:
app_id: ${{ vars.APP_ID }}
api_key: ${{ secrets.BUNNYNET_API_KEY }}
container: app
image_tag: "${{ github.sha }}"
Push your code to trigger the workflow:git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/YOUR_USERNAME/app-astro.git
git push -u origin main
Build and push manually from your local machine.Create a Personal Access Token
Log in to GitHub Container Registry
export CR_PAT=your_personal_access_token
echo $CR_PAT | docker login ghcr.io -u YOUR_USERNAME --password-stdin
Build the image
docker build --platform linux/amd64 -t ghcr.io/YOUR_USERNAME/{imageName}:latest .
Magic Containers only supports images built for the linux/amd64 architecture. The --platform flag ensures compatibility regardless of your local machine’s architecture.
Push to registry
docker push ghcr.io/YOUR_USERNAME/{imageName}:latest
Deploy to Magic Containers
Create a new app
In the bunny.net dashboard, go to Magic Containers and click Add
App. Enter a name and select your deployment option.
Add a container
Click Add Container, then configure:| Field | Value |
|---|
| Registry | GitHub Container Registry |
| Image | YOUR_USERNAME/{imageName} |
| Tag | latest for Docker CLI, or the commit SHA from your GitHub Actions workflow |
Add an endpoint
Go to the Endpoints tab, click Add New Endpoint, and set the
container port to 80.
Deploy
Click Add Container, then Next Step, and Confirm and Create.
For more details, see the quickstart guide.
Test your app
Visit your container URL in the browser to see your Astro site, or test the API route:
curl https://mc-xxx.bunny.run/index.json
{ "message": "Hello from Bunny 🐰" }
Connect a database
You can connect your app to Bunny Database directly from the dashboard:
- Go to Database > [Your Database] > Access
- Click Generate Tokens
- Click Add Secrets to Magic Container App
- Select your app
The BUNNY_DATABASE_URL and BUNNY_DATABASE_AUTH_TOKEN environment variables are now available in your app:
import type { APIRoute } from "astro";
import { createClient } from "@libsql/client/web";
const client = createClient({
url: import.meta.env.BUNNY_DATABASE_URL,
authToken: import.meta.env.BUNNY_DATABASE_AUTH_TOKEN,
});
export const GET: APIRoute = async () => {
const result = await client.execute("SELECT * FROM users");
return new Response(JSON.stringify(result.rows), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
};
See the TypeScript SDK documentation for more details.
Next steps
- Automate deploys with GitHub Actions
- Add a custom hostname
- Add a persistent volume