From 2ecf46a40cd4afbf47bfdbc19865798104348775 Mon Sep 17 00:00:00 2001 From: angel Date: Wed, 2 Jul 2025 19:41:25 +0000 Subject: [PATCH] feat: add GitHub Actions workflow for building and publishing Docker images with multi-platform support --- .github/workflows/publish-docker.yml | 80 ++++++++++++++++++++++++++++ GITHUB_ACTIONS.md | 68 +++++++++++++++++++++++ package-lock.json | 4 +- 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish-docker.yml create mode 100644 GITHUB_ACTIONS.md diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000..58e839e --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,80 @@ +name: Publish Docker Image + +on: + workflow_dispatch: + push: + branches: + - main + - master + tags: + - '[0-9][0-9][0-9][0-9].[0-9]*.[0-9]*' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push_to_registry: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Get version from package.json + id: app_version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + + - name: Docker metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }} + type=raw,value=${{ steps.app_version.outputs.version }} + type=raw,value=${{ github.sha }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: | + linux/amd64 + linux/arm64/v8 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true diff --git a/GITHUB_ACTIONS.md b/GITHUB_ACTIONS.md new file mode 100644 index 0000000..8708de4 --- /dev/null +++ b/GITHUB_ACTIONS.md @@ -0,0 +1,68 @@ +# GitHub Actions Docker Publishing Setup + +This repository includes a GitHub Actions workflow that automatically builds and publishes Docker images to GitHub Container Registry (GHCR). + +## Workflow Overview + +The workflow (`/.github/workflows/publish-docker.yml`) automatically: + +1. **Builds** the Docker image using multi-platform support (AMD64 and ARM64) +2. **Publishes** to `ghcr.io/sillyangel/mice` +3. **Tags** images appropriately based on git refs +4. **Caches** layers for faster subsequent builds +5. **Generates** build provenance attestations for security + +## Trigger Conditions + +The workflow runs on: + +- **Push to main/master branch** → Creates `latest` tag +- **Push tags** (e.g., `2025.07.02`) → Creates date-based version tags +- **Pull requests** → Creates PR-specific tags for testing +- **Manual dispatch** → Can be triggered manually from GitHub UI + +## Image Tags Generated + +Based on different triggers, the workflow creates these tags: + +### Main Branch Push + +- `ghcr.io/sillyangel/mice:latest` + +### Tag Push (e.g., `2025.07.02`) + +- `ghcr.io/sillyangel/mice:2025.07.02` +- `ghcr.io/sillyangel/mice:latest` + +### Pull Request + +- `ghcr.io/sillyangel/mice:pr-123` + +## Multi-Platform Support + +The workflow builds for multiple architectures: + +- `linux/amd64` (Intel/AMD 64-bit) +- `linux/arm64` (ARM 64-bit, Apple Silicon, etc.) + +## Usage After Setup + +Once the workflow is set up: + +1. **Push to main** → New `latest` image published +2. **Create a release** → Versioned images published +3. **Users can pull**: `docker pull ghcr.io/sillyangel/mice:latest` + +## Manual Image Building + +You can also build and push manually: + +```bash +# Build for multiple platforms +docker buildx build --platform linux/amd64,linux/arm64 \ + -t ghcr.io/sillyangel/mice:latest \ + --push . + +# Login first (if needed) +echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin +``` diff --git a/package-lock.json b/package-lock.json index 7918176..37debd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mice-reworked", - "version": "1.0.0", + "version": "2025.7.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mice-reworked", - "version": "1.0.0", + "version": "2025.07.02", "dependencies": { "@hookform/resolvers": "^3.9.1", "@radix-ui/react-alert-dialog": "^1.1.14",