docker-sing-box/.github/workflows/build-singbox-docker.yml

90 lines
3.6 KiB
YAML
Raw Normal View History

2023-05-05 11:21:00 +00:00
name: Build Docker Images (Release)
2023-05-04 18:08:53 +00:00
on:
workflow_dispatch:
inputs:
tag:
2023-05-05 11:21:00 +00:00
description: "The tag version you want to build"
2023-05-04 18:08:53 +00:00
required: true
default: "main"
jobs:
build:
2023-05-05 11:21:00 +00:00
strategy:
fail-fast: true
matrix:
buildType: [standard, minimized, full]
distro: [alpine, distroless]
2023-05-04 18:08:53 +00:00
runs-on: ubuntu-latest
steps:
- name: Checkout Action Repo
uses: actions/checkout@v3
with:
path: action
- name: Checkout Source Code of 'SagerNet/sing-box'
uses: actions/checkout@v3
with:
repository: 'SagerNet/sing-box'
2023-05-05 11:21:00 +00:00
ref: ${{ github.event.inputs.tag }}
2023-05-04 18:08:53 +00:00
submodules: true
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Setup QEMU for Docker Buildx
uses: docker/setup-qemu-action@v2
- name: Select Dockerfile
run: |
2023-05-05 11:21:00 +00:00
if [[ "${{ matrix.buildType }}" == "full" ]]; then
if [[ "${{ matrix.distro }}" == "distroless" ]]; then
2023-05-04 18:08:53 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.full" > Dockerfile
2023-05-05 11:21:00 +00:00
echo "tag_postfix=full-distroless" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
else
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.full" > Dockerfile
2023-05-05 11:21:00 +00:00
echo "tag_postfix=full" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
fi
2023-05-05 11:21:00 +00:00
elif [[ "${{ matrix.buildType }}" == "minimized" ]]; then
if [[ "${{ matrix.distro }}" == "distroless" ]]; then
2023-05-04 18:08:53 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.minimized" > Dockerfile
2023-05-05 11:21:00 +00:00
echo "tag_postfix=mini-distroless" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
else
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.minimized" > Dockerfile
2023-05-05 11:21:00 +00:00
echo "tag_postfix=mini" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
fi
else
2023-05-05 11:21:00 +00:00
if [[ "${{ matrix.distro }}" == "distroless" ]]; then
2023-05-04 18:08:53 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.standard" > Dockerfile
2023-05-05 11:21:00 +00:00
echo "tag_postfix=distroless" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
else
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.standard" > Dockerfile
fi
fi
- name: Login to Docker Hub Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: etnperlong/sing-box
- name: Get tag to build
id: tag
run: |
echo "latest=etnperlong/sing-box:latest" >> $GITHUB_OUTPUT
if [[ -z "${{ github.event.inputs.tag }}" ]]; then
echo "versioned=etnperlong/sing-box:${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
2023-05-05 11:21:00 +00:00
if [[ -z ${{ steps.tag.outputs.tag_postfix }} ]]; then
echo "versioned=etnperlong/sing-box:${{ github.event.inputs.tag }}-${{ steps.tag.outputs.tag_postfix }}" >> $GITHUB_OUTPUT
else
echo "versioned=etnperlong/sing-box:${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
fi
2023-05-04 18:08:53 +00:00
fi
- name: Build and release Docker images
uses: docker/build-push-action@v4
with:
platforms: linux/386,linux/amd64,linux/arm64,linux/arm/v7,linux/s390x
target: dist
tags: |
${{ steps.tag.outputs.latest }}
${{ steps.tag.outputs.versioned }}
push: true