Merge pull request #4 from Jackie264/dependabot/github_actions/action… #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: d2c | |
jobs: | |
# 运行测试 | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
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@v5 | |
- 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 | |
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="可爱的小cherry" | |
org.opencontainers.image.title="d2c" | |
org.opencontainers.image.description="Convert Docker containers to docker-compose files with web UI" | |
org.opencontainers.image.url="https://github.com/coracoo/docker2compose" | |
org.opencontainers.image.source="https://github.com/coracoo/docker2compose" | |
org.opencontainers.image.documentation="https://github.com/coracoo/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 |