> ## Documentation Index
> Fetch the complete documentation index at: https://bunny.net/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy with GitHub Actions

> Automate container image updates on Magic Containers with GitHub Actions.

Automate your deployments by integrating Magic Containers with GitHub Actions. When you push changes to your repository, your workflow can build a Docker image, push it to a container registry, and trigger a rolling update on Magic Containers.

## Prerequisites

* An application already deployed on the Magic Containers platform
* A GitHub repository containing a Dockerfile or valid build context
* Container registry credentials (`GITHUB_TOKEN` for GitHub Container Registry, your bunny.net API key for the [Bunny Container Registry](https://bunny.net/docs/magic-containers/bunny-container-registry.md), or a personal access token for DockerHub)

## Quickstart

Add a step to your GitHub Actions workflow with the following inputs: `app_id`, `api_key`, `container`, and `image_tag`. This triggers a rolling update whenever a new image is built and pushed.

> [tab] GitHub Container Registry
>
> ```yml theme={null}
> name: Update container image when pushing to main
>
> on:
>   push:
>     branches:
>       - "main"
>
> jobs:
>   build:
>     name: Build and deploy
>     runs-on: ubuntu-latest
>     steps:
>       - uses: actions/checkout@v4
>
>       - name: docker login
>         uses: docker/login-action@v3
>         with:
>           registry: ghcr.io
>           username: ${{ github.actor }}
>           password: ${{ secrets.GITHUB_TOKEN }}
>
>       - name: docker build and push
>         uses: docker/build-push-action@v5
>         with:
>           context: .
>           push: true
>           tags: ghcr.io/${{ github.repository }}:${{ 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 }}"
> ```

> [tab] Bunny Container Registry
>
> > [!NOTE]
> >
> > The [Bunny Container Registry](https://bunny.net/docs/magic-containers/bunny-container-registry.md) is in **Closed Preview**. See [Product Release Stages](https://bunny.net/docs/product-release-stages.md) for details.
>
> Push with the [bunny.net CLI](https://bunny.net/docs/cli.md): it authenticates the push and namespaces the image under your account, so the workflow needs no registry login step and no account ID variable. The same API key secret authenticates both the registry push and the Magic Containers update.
>
> ```yml theme={null}
> name: Update container image when pushing to main
>
> on:
>   push:
>     branches:
>       - "main"
>
> jobs:
>   build:
>     name: Build and deploy
>     runs-on: ubuntu-latest
>     steps:
>       - uses: actions/checkout@v4
>
>       - name: Install the bunny.net CLI
>         run: npm install -g @bunny.net/cli
>
>       - name: docker build
>         run: docker build --platform linux/amd64 --tag my-app:${{ github.sha }} .
>
>       - name: Push to the Bunny Container Registry
>         run: bunny registry push my-app:${{ github.sha }}
>         env:
>           BUNNYNET_API_KEY: ${{ secrets.BUNNYNET_API_KEY }}
>
>       - 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 }}"
> ```

## Inputs

| Input | Required | Description |
| - | - | - |
| `app_id` | Yes | The App ID for your Magic Containers application |
| `api_key` | Yes | The API Key for your Bunny account (sub-user accounts not supported) |
| `container` | Yes | The name of the container within the application |
| `image_tag` | Yes | The new image tag |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.