> ## 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.

# 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 (use `GITHUB_TOKEN` for GitHub Container Registry, or personal access tokens 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.

```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 }}"
```

## 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                                                    |
