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

104 lines
4.1 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"
2023-11-21 12:38:03 +00:00
repository_dispatch:
types: [build-release]
2023-05-04 18:08:53 +00:00
jobs:
build:
2023-05-05 11:21:00 +00:00
strategy:
fail-fast: true
matrix:
buildType: [full]
distro: [alpine]
2023-05-04 18:08:53 +00:00
runs-on: ubuntu-latest
2023-11-21 12:44:17 +00:00
env:
TAG: ${{ github.event.client_payload.tag || github.event.inputs.tag}}
2023-05-04 18:08:53 +00:00
steps:
2023-11-21 12:44:17 +00:00
- name: Get Build Tags
run: |
echo "Version: ${{env.TAG}}"
2023-05-04 18:08:53 +00:00
- name: Checkout Source Code of 'SagerNet/sing-box'
uses: actions/checkout@v3
with:
repository: 'SagerNet/sing-box'
2023-11-21 12:44:17 +00:00
ref: ${{env.TAG}}
2023-05-04 18:08:53 +00:00
submodules: true
2023-05-05 11:32:35 +00:00
- name: Checkout Action Repo
uses: actions/checkout@v3
with:
path: action
2023-05-04 18:08:53 +00:00
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Setup QEMU for Docker Buildx
uses: docker/setup-qemu-action@v2
2023-05-05 11:39:27 +00:00
- 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
2023-05-04 18:08:53 +00:00
- name: Select Dockerfile
2023-05-05 11:43:44 +00:00
id: dockerfile
2023-05-04 18:08:53 +00:00
run: |
2023-05-05 11:21:00 +00:00
if [[ "${{ matrix.buildType }}" == "full" ]]; then
if [[ "${{ matrix.distro }}" == "distroless" ]]; then
2023-05-05 11:39:27 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.full" "$GITHUB_WORKSPACE/Dockerfile"
2023-05-05 11:43:44 +00:00
echo "tagpost=full-distroless" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
else
2023-05-05 11:39:27 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.full" "$GITHUB_WORKSPACE/Dockerfile"
2023-08-08 15:44:35 +00:00
# echo "tagpost=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-05 11:39:27 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.minimized" "$GITHUB_WORKSPACE/Dockerfile"
2023-05-05 11:43:44 +00:00
echo "tagpost=mini-distroless" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
else
2023-05-05 11:39:27 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.minimized" "$GITHUB_WORKSPACE/Dockerfile"
2023-05-05 11:43:44 +00:00
echo "tagpost=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-05 11:39:27 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.distroless.standard" "$GITHUB_WORKSPACE/Dockerfile"
2023-05-05 11:43:44 +00:00
echo "tagpost=distroless" >> $GITHUB_OUTPUT
2023-05-04 18:08:53 +00:00
else
2023-05-05 11:39:27 +00:00
cp "$GITHUB_WORKSPACE/action/dockerfiles/Dockerfile.standard" "$GITHUB_WORKSPACE/Dockerfile"
2023-05-04 18:08:53 +00:00
fi
fi
- name: Get tag to build
id: tag
run: |
if [[ "${{ matrix.distro }}" == "alpine" && "${{ matrix.buildType }}" == "full" ]]; then
2023-05-05 14:18:05 +00:00
echo "latest=etnperlong/sing-box:latest" >> $GITHUB_OUTPUT
fi
if [[ "${{ matrix.distro }}" == "distroless" && "${{ matrix.buildType }}" == "full" ]]; then
2023-05-05 14:18:05 +00:00
echo "latest=etnperlong/sing-box:distroless" >> $GITHUB_OUTPUT
2023-05-05 11:57:03 +00:00
fi
2023-11-21 12:44:17 +00:00
if [[ -z "${{env.TAG}}" ]]; then
2023-05-04 18:08:53 +00:00
echo "versioned=etnperlong/sing-box:${{ github.ref_name }}" >> $GITHUB_OUTPUT
else
2023-05-05 11:57:03 +00:00
if [[ -n "${{ steps.dockerfile.outputs.tagpost }}" ]]; then
2023-11-21 12:44:17 +00:00
echo "versioned=etnperlong/sing-box:${{env.TAG}}-${{ steps.dockerfile.outputs.tagpost }}" >> $GITHUB_OUTPUT
2023-05-05 11:21:00 +00:00
else
2023-11-21 12:44:17 +00:00
echo "versioned=etnperlong/sing-box:${{env.TAG}}" >> $GITHUB_OUTPUT
2023-05-05 11:21:00 +00:00
fi
2023-05-04 18:08:53 +00:00
fi
- name: Build and release Docker images
uses: docker/build-push-action@v4
with:
2023-05-05 11:43:44 +00:00
context: .
2023-05-05 12:11:10 +00:00
platforms: linux/amd64,linux/arm64,linux/arm/v7
2023-05-04 18:08:53 +00:00
target: dist
tags: |
${{ steps.tag.outputs.latest }}
${{ steps.tag.outputs.versioned }}
push: true