mirror of
https://github.com/nickrunning/wechat-selkies.git
synced 2026-05-09 00:24:09 +00:00
141 lines
5.1 KiB
YAML
141 lines
5.1 KiB
YAML
name: Build and Publish Docker Image
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
DOCKERHUB_REGISTRY: docker.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-publish:
|
|
runs-on: ubuntu-latest
|
|
environment: DOCKERHUB
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
id-token: write
|
|
attestations: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Login to Docker Hub
|
|
if: vars.ENABLE_DOCKERHUB == 'true'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.DOCKERHUB_REGISTRY }}
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
ghcr.io/${{ github.repository }}
|
|
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }},enable=${{ vars.ENABLE_DOCKERHUB == 'true' }}
|
|
flavor: |
|
|
latest=false
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') || startsWith(github.ref, 'refs/tags/') }}
|
|
|
|
- name: Build and push Docker image
|
|
id: build-image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Generate artifact attestation
|
|
if: github.event_name != 'workflow_dispatch'
|
|
uses: actions/attest-build-provenance@v1
|
|
with:
|
|
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
subject-digest: ${{ steps.build-image.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
- name: Output Docker image information
|
|
run: |
|
|
echo "## 🐳 Docker Images Published" >> $GITHUB_STEP_SUMMARY
|
|
echo "### GitHub Container Registry" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Repository:** ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Digest:** \`${{ steps.build-image.outputs.digest }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
|
|
if [ "${{ vars.ENABLE_DOCKERHUB }}" == "true" ]; then
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### Docker Hub" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Registry:** ${{ env.DOCKERHUB_REGISTRY }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Repository:** ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Digest:** \`${{ steps.build-image.outputs.digest }}\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
|
else
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### Docker Hub" >> $GITHUB_STEP_SUMMARY
|
|
echo "⚠️ **Skipped** - Docker Hub push disabled (set ENABLE_DOCKERHUB=true to enable)" >> $GITHUB_STEP_SUMMARY
|
|
fi
|
|
|
|
- name: Create GitHub Release
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
generate_release_notes: true
|
|
make_latest: true
|
|
body: |
|
|
## 🐳 Docker Images
|
|
|
|
**GitHub Container Registry:**
|
|
```bash
|
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
|
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
|
```
|
|
|
|
**Docker Hub** (if enabled):
|
|
```bash
|
|
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.ref_name }}
|
|
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
|
|
```
|
|
|
|
## 🚀 Quick Start
|
|
**GitHub Container Registry:**
|
|
```bash
|
|
docker run -it -p 3001:3001 -v ./config:/config ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
|
|
```
|
|
|
|
**Docker Hub** (if enabled):
|
|
```bash
|
|
docker run -it -p 3001:3001 -v ./config:/config ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.ref_name }}
|
|
```
|
|
|
|
Then visit: https://localhost:3001 |