Skip to content

Merge pull request #6 from Jackie264/dependabot/github_actions/action… #25

Merge pull request #6 from Jackie264/dependabot/github_actions/action…

Merge pull request #6 from Jackie264/dependabot/github_actions/action… #25

name: Docker Multi-Platform Build and Push
on:
push:
tags:
- "v*.*.*"
branches:
- dev
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@v5
- 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@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
# 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 }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/dev' }}
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