π Building docker image sunlei/sing-box by @sunlei #741
This file contains 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: sunlei/sing-box | |
run-name: π Building docker image ${{ github.workflow }} by @${{ github.actor }} | |
on: | |
schedule: | |
- cron: "0 5 * * *" | |
push: | |
branches: | |
- master | |
paths: | |
- "sing-box/Dockerfile" | |
- ".github/workflows/sing-box.yml" | |
workflow_dispatch: | |
inputs: | |
trigger: | |
description: "Manually trigger" | |
required: true | |
type: choice | |
options: | |
- build | |
env: | |
REGISTRY: ghcr.io | |
# IMAGE_NAME: ${{ github.repository }} | |
# FORCE_COLOR: 1 | |
# DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
# DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
jobs: | |
sing-box: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
steps: | |
- run: echo "π The job was automatically triggered by a ${{ github.event_name }} event." | |
- run: echo "π§ This job is now running on a ${{ runner.os }} server hosted by GitHub!" | |
- run: echo "π The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Extract metadata (tags, labels) for Docker | |
# id: meta | |
# uses: docker/metadata-action@v4 | |
# with: | |
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# flavor: | | |
# latest=true | |
# https://stackoverflow.com/a/75770668 | |
# LATEST_VERSION=$(curl -sfL "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r 'first(.[] | select(.tag_name | contains("beta"))) | .tag_name') | |
- name: Get latest version | |
run: | | |
JQ_SEMVER_CMP=' | |
def opt(f): | |
. as $in | try f catch $in; | |
def semver_cmp: | |
sub("\\+.*$"; "") | |
| capture("^(?<v>[^-]+)(?:-(?<p>.*))?$") | [.v, .p // empty] | |
| map(split(".") | map(opt(tonumber))) | |
| .[1] |= (. // {});' | |
# LATEST_VERSION=$(curl -sfL "https://api.github.com/repos/SagerNet/sing-box/releases" | jq --raw-output "$JQ_SEMVER_CMP"'sort_by(.tag_name|semver_cmp) | last | .tag_name') | |
# latest stable | |
LATEST_VERSION_STABLE=$(curl -sfL "https://api.github.com/repos/SagerNet/sing-box/releases/latest" | jq --raw-output '.tag_name') | |
# latest release | |
LATEST_VERSION_RELEASE=$(curl -sfL "https://api.github.com/repos/SagerNet/sing-box/releases" | jq --raw-output '.[0].tag_name') | |
# latest tag | |
# curl -sfL "https://api.github.com/repos/SagerNet/sing-box/tags" | jq --raw-output '.[0].name' | |
echo "LATEST_VERSION_STABLE=$LATEST_VERSION_STABLE" >> $GITHUB_ENV | |
echo "LATEST_VERSION_RELEASE=$LATEST_VERSION_RELEASE" >> $GITHUB_ENV | |
- name: Build and push docker image | STABLE | ${{ env.LATEST_VERSION_STABLE }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./${{ github.job }} | |
platforms: linux/amd64,linux/arm64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
push: true | |
build-args: | | |
VERSION=${{ env.LATEST_VERSION_STABLE }} | |
tags: | | |
${{ env.REGISTRY }}/${{ github.workflow }}:stable | |
# tags: ${{ steps.meta.outputs.tags }} | |
# labels: ${{ steps.meta.outputs.labels }} | |
- name: Build and push docker image | LATEST | ${{ env.LATEST_VERSION_RELEASE }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./${{ github.job }} | |
platforms: linux/amd64,linux/arm64 | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
push: true | |
build-args: | | |
VERSION=${{ env.LATEST_VERSION_RELEASE }} | |
tags: | | |
${{ env.REGISTRY }}/${{ github.workflow }}:latest | |
- run: echo "π This job's status is ${{ job.status }}." |