Skip to content

Add labels to Docker build workflow #6

Add labels to Docker build workflow

Add labels to Docker build workflow #6

Workflow file for this run

name: Build and Push Docker
on:
push:
branches:
- dev
tags:
- "*"
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- 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 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_HUB_USERNAME }}/sub2sing-box
ghcr.io/${{ github.repository }}
- name: Prepare tags and build args
id: prep
run: |
if [[ "${{ github.event_name }}" == 'workflow_dispatch' ]]; then
TAGS="dev"
VERSION="${{ github.sha }}"
fi
if [[ "$GITHUB_REF" == 'refs/heads/dev' ]]; then
TAGS="dev"
VERSION="${{ github.sha }}"
fi
if [[ "$GITHUB_REF" == 'refs/tags/'* ]]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
TAGS="latest,$TAG_NAME"
VERSION=$TAG_NAME
fi
echo "::set-output name=tags::$TAGS"
echo "::set-output name=version::$VERSION"
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image to GHCR and Docker Hub
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
build-args: version=${{ steps.prep.outputs.version }}
push: true
platforms: linux/amd64,linux/arm,linux/arm64
tags: ${{ steps.prep.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}