tg-ws-proxy-rs 1.4.0

Telegram MTProto WebSocket Bridge Proxy — Rust port of Flowseal/tg-ws-proxy
Documentation
name: Docker

on:
  pull_request:
  push:
    branches:
      - main
      - master
      - feature/**
    tags:
      - v[0-9]+.*
  workflow_dispatch:
    inputs:
      tag:
        description: Docker tag to publish for a manual run
        default: latest
        required: true

permissions:
  contents: read

env:
  IMAGE_NAME: valnesfjord/tg-ws-proxy-rs

jobs:
  build:
    name: Build ${{ matrix.platform }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: linux/amd64
            arch: amd64
            runner: ubuntu-24.04
          - platform: linux/arm64
            arch: arm64
            runner: ubuntu-24.04-arm
    env:
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v6

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to Docker Hub
        if: github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        uses: docker/login-action@v3
        with:
          username: ${{ env.DOCKERHUB_USERNAME }}
          password: ${{ env.DOCKERHUB_TOKEN }}

      - name: Build image for PR
        if: github.event_name == 'pull_request'
        uses: docker/build-push-action@v6
        with:
          context: .
          platforms: ${{ matrix.platform }}
          push: false
          cache-from: |
            type=gha,scope=docker-${{ matrix.arch }}
            type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }}
          cache-to: type=gha,scope=docker-${{ matrix.arch }},mode=max

      - name: Build and push image by digest
        id: build
        if: github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        uses: docker/build-push-action@v6
        with:
          context: .
          platforms: ${{ matrix.platform }}
          labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
          outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
          cache-from: |
            type=gha,scope=docker-${{ matrix.arch }}
            type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }}
          cache-to: |
            type=gha,scope=docker-${{ matrix.arch }},mode=max
            type=registry,ref=${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max

      - name: Export digest
        if: steps.build.outputs.digest != ''
        shell: bash
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.build.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"

      - name: Upload digest
        if: steps.build.outputs.digest != ''
        uses: actions/upload-artifact@v4
        with:
          name: digest-${{ matrix.arch }}
          path: /tmp/digests/*
          if-no-files-found: error
          retention-days: 1

  merge:
    name: Publish multi-arch manifest
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-24.04
    needs: build
    env:
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
    steps:
      - name: Log in to Docker Hub
        if: env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        uses: docker/login-action@v3
        with:
          username: ${{ env.DOCKERHUB_USERNAME }}
          password: ${{ env.DOCKERHUB_TOKEN }}

      - name: Download digests
        if: env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        uses: actions/download-artifact@v4
        with:
          path: /tmp/digests
          pattern: digest-*
          merge-multiple: true

      - name: Docker metadata
        if: env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.IMAGE_NAME }}
          tags: |
            type=raw,value=latest,enable=${{ github.ref_type == 'tag' || github.ref_name == github.event.repository.default_branch }}
            type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
            type=ref,event=branch
            type=ref,event=tag
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}

      - name: Create and push manifest list
        if: env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        shell: bash
        working-directory: /tmp/digests
        run: |
          mapfile -t tags < <(jq -r '.tags[]' <<< '${{ steps.meta.outputs.json }}')

          tag_args=()
          for tag in "${tags[@]}"; do
            tag_args+=("-t" "$tag")
          done

          digest_args=()
          for digest in *; do
            digest_args+=("${IMAGE_NAME}@sha256:${digest}")
          done

          docker buildx imagetools create "${tag_args[@]}" "${digest_args[@]}"

      - name: Inspect image
        if: env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != ''
        run: docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}