Skip to content

Add comprehensive test suite and Docker Hub CI/CD automation #3

Add comprehensive test suite and Docker Hub CI/CD automation

Add comprehensive test suite and Docker Hub CI/CD automation #3

Workflow file for this run

name: Docker Multi-Platform Build and Push
on:
push:
tags:
- "v*.*.*"
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
# 添加权限配置
permissions:
contents: read
packages: write
env:
IMAGE_NAME: docker2compose
jobs:
# 运行测试
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
python run_tests.py
# 构建和推送Docker镜像
build:
runs-on: ubuntu-latest
needs: test
# 只有在推送到master分支或创建tag时才构建镜像
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Ali Registry
uses: docker/login-action@v3
# if: secrets.ALI_REGISTRY != ''
with:
registry: ${{ secrets.ALI_REGISTRY }}
username: ${{ secrets.ALI_USERNAME }}
password: ${{ secrets.ALI_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
${{ secrets.ALI_REGISTRY }}/cherry4nas/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix={{branch}}-
labels: |
maintainer="Jackie264"
org.opencontainers.image.title="docker2compose"
org.opencontainers.image.description="Convert Docker containers to docker-compose files with web UI"
org.opencontainers.image.url="https://github.com/Jackie264/docker2compose"
org.opencontainers.image.source="https://github.com/Jackie264/docker2compose"
org.opencontainers.image.documentation="https://github.com/Jackie264/docker2compose/blob/master/README.md"
- name: Build and push Docker images
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile.github
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v3
if: github.ref == 'refs/heads/master'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
short-description: "Convert Docker containers to docker-compose files with web UI"
readme-filepath: ./README.md