Skip to content

Build Docker Images #26

Build Docker Images

Build Docker Images #26

Workflow file for this run

name: Build Docker Images
on:
workflow_dispatch:
inputs:
tag:
description: "The tag version you want to build"
apps:
description: "Comma-separated list of apps to build (e.g., ['sing-box','app'])"
required: true
default: "['app']"
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
matrix:
app: ${{ fromJSON(github.event.inputs.apps)}}
steps:
- name: Get commit to build
id: ref
run: |
if [[ -z "${{ github.event.inputs.tag }}" ]]; then
ref="${{ github.ref_name }}"
else
ref="${{ github.event.inputs.tag }}"
fi
echo "ref=$ref"
echo "ref=$ref" >> $GITHUB_OUTPUT
if [[ $ref == *"-"* ]]; then
latest=latest-beta
else
latest=latest
fi
echo "latest=$latest"
echo "latest=$latest" >> $GITHUB_OUTPUT
- name: Setup environment variables
run: |
if [ "${{ matrix.app }}" == "sing-box" ]; then
IMAGE_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-singbox"
CONTEXT_DIR="sing-box"
else
IMAGE_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app"
CONTEXT_DIR="./controller"
fi
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "CONTEXT_DIR=$CONTEXT_DIR" >> $GITHUB_ENV
- name: Clone repository
if: ${{ matrix.app == 'sing-box' }}
run: |
git clone https://github.com/sagernet/sing-box.git
sed -i 's/with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_clash_api/with_gvisor,with_quic,with_dhcp,with_wireguard,with_ech,with_utls,with_reality_server,with_acme,with_clash_api,with_v2ray_api,with_grpc/' sing-box/Dockerfile
- name: Checkout repository
if: ${{ matrix.app == 'app' }}
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup QEMU for Docker Buildx
if: ${{ matrix.app == 'sing-box'}}
uses: docker/setup-qemu-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_TAG }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64,linux/386,linux/s390x
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: ${{ env.CONTEXT_DIR }}
target: dist
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}