feat: add GitHub Actions workflow for building and publishing Docker images with multi-platform support
This commit is contained in:
80
.github/workflows/publish-docker.yml
vendored
Normal file
80
.github/workflows/publish-docker.yml
vendored
Normal file
@@ -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
|
||||
68
GITHUB_ACTIONS.md
Normal file
68
GITHUB_ACTIONS.md
Normal file
@@ -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
|
||||
```
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user