mirror of https://github.com/telemt/telemt.git
Compare commits
18 Commits
cb877c2bc3
...
c43de1bd2a
| Author | SHA1 | Date |
|---|---|---|
|
|
c43de1bd2a | |
|
|
101efe45b7 | |
|
|
11df61c6ac | |
|
|
08684bcbd2 | |
|
|
744fb4425f | |
|
|
80cb1bc221 | |
|
|
8461556b02 | |
|
|
cfd516edf3 | |
|
|
803c2c0492 | |
|
|
b762bd029f | |
|
|
761679d306 | |
|
|
41668b153d | |
|
|
1d2f88ad29 | |
|
|
80917f5abc | |
|
|
dc61d300ab | |
|
|
ae16080de5 | |
|
|
b8ca1fc166 | |
|
|
f9986944df |
|
|
@ -5,27 +5,69 @@ on:
|
||||||
tags:
|
tags:
|
||||||
- '[0-9]+.[0-9]+.[0-9]+'
|
- '[0-9]+.[0-9]+.[0-9]+'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Release tag (example: 3.3.15)'
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: release-${{ github.ref }}
|
group: release-${{ github.ref_name }}-${{ github.event.inputs.tag || 'auto' }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
BINARY_NAME: telemt
|
BINARY_NAME: telemt
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ==========================
|
prepare:
|
||||||
# GNU / glibc
|
name: Prepare
|
||||||
# ==========================
|
|
||||||
build-gnu:
|
|
||||||
name: GNU ${{ matrix.target }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.vars.outputs.version }}
|
||||||
|
prerelease: ${{ steps.vars.outputs.prerelease }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Resolve version
|
||||||
|
id: vars
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
|
||||||
|
VERSION="${{ github.event.inputs.tag }}"
|
||||||
|
else
|
||||||
|
VERSION="${GITHUB_REF#refs/tags/}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION="${VERSION#refs/tags/}"
|
||||||
|
|
||||||
|
if [ -z "${VERSION}" ]; then
|
||||||
|
echo "Release version is empty" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${VERSION}" == *-* ]]; then
|
||||||
|
PRERELEASE=true
|
||||||
|
else
|
||||||
|
PRERELEASE=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
|
||||||
|
echo "prerelease=${PRERELEASE}" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
# ==========================
|
||||||
|
# GNU / glibc
|
||||||
|
# ==========================
|
||||||
|
build-gnu:
|
||||||
|
name: GNU ${{ matrix.asset }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: prepare
|
||||||
|
|
||||||
container:
|
container:
|
||||||
image: rust:slim-bookworm
|
image: rust:slim-bookworm
|
||||||
|
|
||||||
|
|
@ -35,8 +77,15 @@ jobs:
|
||||||
include:
|
include:
|
||||||
- target: x86_64-unknown-linux-gnu
|
- target: x86_64-unknown-linux-gnu
|
||||||
asset: telemt-x86_64-linux-gnu
|
asset: telemt-x86_64-linux-gnu
|
||||||
|
cpu: baseline
|
||||||
|
|
||||||
|
- target: x86_64-unknown-linux-gnu
|
||||||
|
asset: telemt-x86_64-v3-linux-gnu
|
||||||
|
cpu: v3
|
||||||
|
|
||||||
- target: aarch64-unknown-linux-gnu
|
- target: aarch64-unknown-linux-gnu
|
||||||
asset: telemt-aarch64-linux-gnu
|
asset: telemt-aarch64-linux-gnu
|
||||||
|
cpu: generic
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
@ -62,64 +111,88 @@ jobs:
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cargo/registry
|
/usr/local/cargo/registry
|
||||||
~/.cargo/git
|
/usr/local/cargo/git
|
||||||
target
|
target
|
||||||
key: gnu-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
|
key: gnu-${{ matrix.asset }}-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
gnu-${{ matrix.asset }}-
|
||||||
|
gnu-
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then
|
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then
|
||||||
export CC=aarch64-linux-gnu-gcc
|
export CC=aarch64-linux-gnu-gcc
|
||||||
export CXX=aarch64-linux-gnu-g++
|
export CXX=aarch64-linux-gnu-g++
|
||||||
export RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc"
|
export RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc -C lto=fat -C panic=abort"
|
||||||
else
|
else
|
||||||
export CC=clang
|
export CC=clang
|
||||||
export CXX=clang++
|
export CXX=clang++
|
||||||
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=lld"
|
|
||||||
|
if [ "${{ matrix.cpu }}" = "v3" ]; then
|
||||||
|
CPU_FLAGS="-C target-cpu=x86-64-v3"
|
||||||
|
else
|
||||||
|
CPU_FLAGS="-C target-cpu=x86-64"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=lld -C lto=fat -C panic=abort ${CPU_FLAGS}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cargo build --release --target ${{ matrix.target }}
|
cargo build --release --target ${{ matrix.target }} -j "$(nproc)"
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/telemt
|
cp "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" dist/telemt
|
||||||
|
|
||||||
cd dist
|
cd dist
|
||||||
tar -czf ${{ matrix.asset }}.tar.gz \
|
tar -czf "${{ matrix.asset }}.tar.gz" \
|
||||||
--owner=0 --group=0 --numeric-owner \
|
--owner=0 --group=0 --numeric-owner \
|
||||||
telemt
|
telemt
|
||||||
|
|
||||||
sha256sum ${{ matrix.asset }}.tar.gz > ${{ matrix.asset }}.sha256
|
sha256sum "${{ matrix.asset }}.tar.gz" > "${{ matrix.asset }}.tar.gz.sha256"
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.asset }}
|
name: ${{ matrix.asset }}
|
||||||
path: dist/*
|
path: dist/*
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# MUSL
|
# MUSL
|
||||||
# ==========================
|
# ==========================
|
||||||
build-musl:
|
build-musl:
|
||||||
name: MUSL ${{ matrix.target }}
|
name: MUSL ${{ matrix.asset }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: prepare
|
||||||
|
|
||||||
container:
|
container:
|
||||||
image: rust:slim-bookworm
|
image: rust:slim-bookworm
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- target: x86_64-unknown-linux-musl
|
- target: x86_64-unknown-linux-musl
|
||||||
asset: telemt-x86_64-linux-musl
|
asset: telemt-x86_64-linux-musl
|
||||||
|
cpu: baseline
|
||||||
|
|
||||||
|
- target: x86_64-unknown-linux-musl
|
||||||
|
asset: telemt-x86_64-v3-linux-musl
|
||||||
|
cpu: v3
|
||||||
|
|
||||||
- target: aarch64-unknown-linux-musl
|
- target: aarch64-unknown-linux-musl
|
||||||
asset: telemt-aarch64-linux-musl
|
asset: telemt-aarch64-linux-musl
|
||||||
|
cpu: generic
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
|
|
@ -127,89 +200,104 @@ jobs:
|
||||||
musl-tools \
|
musl-tools \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
curl
|
curl
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v4
|
||||||
if: matrix.target == 'aarch64-unknown-linux-musl'
|
if: matrix.target == 'aarch64-unknown-linux-musl'
|
||||||
with:
|
with:
|
||||||
path: ~/.musl-aarch64
|
path: ~/.musl-aarch64
|
||||||
key: musl-toolchain-aarch64-v1
|
key: musl-toolchain-aarch64-v1
|
||||||
|
|
||||||
- name: Install aarch64 musl toolchain
|
- name: Install aarch64 musl toolchain
|
||||||
if: matrix.target == 'aarch64-unknown-linux-musl'
|
if: matrix.target == 'aarch64-unknown-linux-musl'
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
TOOLCHAIN_DIR="$HOME/.musl-aarch64"
|
TOOLCHAIN_DIR="$HOME/.musl-aarch64"
|
||||||
ARCHIVE="aarch64-linux-musl-cross.tgz"
|
ARCHIVE="aarch64-linux-musl-cross.tgz"
|
||||||
URL="https://github.com/telemt/telemt/releases/download/toolchains/$ARCHIVE"
|
URL="https://github.com/telemt/telemt/releases/download/toolchains/${ARCHIVE}"
|
||||||
|
|
||||||
if [ -x "$TOOLCHAIN_DIR/bin/aarch64-linux-musl-gcc" ]; then
|
if [ -x "${TOOLCHAIN_DIR}/bin/aarch64-linux-musl-gcc" ]; then
|
||||||
echo "✅ MUSL toolchain cached"
|
echo "MUSL toolchain cached"
|
||||||
else
|
else
|
||||||
echo "⬇️ Downloading MUSL toolchain..."
|
|
||||||
|
|
||||||
curl -fL \
|
curl -fL \
|
||||||
--retry 5 \
|
--retry 5 \
|
||||||
--retry-delay 3 \
|
--retry-delay 3 \
|
||||||
--connect-timeout 10 \
|
--connect-timeout 10 \
|
||||||
--max-time 120 \
|
--max-time 120 \
|
||||||
-o "$ARCHIVE" "$URL"
|
-o "${ARCHIVE}" "${URL}"
|
||||||
|
|
||||||
mkdir -p "$TOOLCHAIN_DIR"
|
mkdir -p "${TOOLCHAIN_DIR}"
|
||||||
tar -xzf "$ARCHIVE" --strip-components=1 -C "$TOOLCHAIN_DIR"
|
tar -xzf "${ARCHIVE}" --strip-components=1 -C "${TOOLCHAIN_DIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$TOOLCHAIN_DIR/bin" >> $GITHUB_PATH
|
echo "${TOOLCHAIN_DIR}/bin" >> "${GITHUB_PATH}"
|
||||||
|
|
||||||
- name: Add rust target
|
- name: Add rust target
|
||||||
run: rustup target add ${{ matrix.target }}
|
run: rustup target add ${{ matrix.target }}
|
||||||
|
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
/usr/local/cargo/registry
|
/usr/local/cargo/registry
|
||||||
/usr/local/cargo/git
|
/usr/local/cargo/git
|
||||||
target
|
target
|
||||||
key: musl-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
|
key: musl-${{ matrix.asset }}-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
musl-${{ matrix.asset }}-
|
||||||
|
musl-
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-musl" ]; then
|
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-musl" ]; then
|
||||||
export CC=aarch64-linux-musl-gcc
|
export CC=aarch64-linux-musl-gcc
|
||||||
export CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
|
export CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
|
||||||
export RUSTFLAGS="-C target-feature=+crt-static -C linker=aarch64-linux-musl-gcc"
|
export RUSTFLAGS="-C target-feature=+crt-static -C linker=aarch64-linux-musl-gcc -C lto=fat -C panic=abort"
|
||||||
else
|
else
|
||||||
export CC=musl-gcc
|
export CC=musl-gcc
|
||||||
export CC_x86_64_unknown_linux_musl=musl-gcc
|
export CC_x86_64_unknown_linux_musl=musl-gcc
|
||||||
export RUSTFLAGS="-C target-feature=+crt-static"
|
|
||||||
|
if [ "${{ matrix.cpu }}" = "v3" ]; then
|
||||||
|
CPU_FLAGS="-C target-cpu=x86-64-v3"
|
||||||
|
else
|
||||||
|
CPU_FLAGS="-C target-cpu=x86-64"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export RUSTFLAGS="-C target-feature=+crt-static -C lto=fat -C panic=abort ${CPU_FLAGS}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cargo build --release --target ${{ matrix.target }}
|
cargo build --release --target ${{ matrix.target }} -j "$(nproc)"
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/telemt
|
cp "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" dist/telemt
|
||||||
|
|
||||||
cd dist
|
cd dist
|
||||||
tar -czf ${{ matrix.asset }}.tar.gz \
|
tar -czf "${{ matrix.asset }}.tar.gz" \
|
||||||
--owner=0 --group=0 --numeric-owner \
|
--owner=0 --group=0 --numeric-owner \
|
||||||
telemt
|
telemt
|
||||||
|
|
||||||
sha256sum ${{ matrix.asset }}.tar.gz > ${{ matrix.asset }}.sha256
|
sha256sum "${{ matrix.asset }}.tar.gz" > "${{ matrix.asset }}.tar.gz.sha256"
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.asset }}
|
name: ${{ matrix.asset }}
|
||||||
path: dist/*
|
path: dist/*
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Release
|
# Release
|
||||||
# ==========================
|
# ==========================
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build-gnu, build-musl]
|
needs: [prepare, build-gnu, build-musl]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
@ -219,73 +307,99 @@ jobs:
|
||||||
with:
|
with:
|
||||||
path: artifacts
|
path: artifacts
|
||||||
|
|
||||||
- name: Flatten
|
- name: Flatten artifacts
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
mkdir dist
|
set -euo pipefail
|
||||||
|
mkdir -p dist
|
||||||
find artifacts -type f -exec cp {} dist/ \;
|
find artifacts -type f -exec cp {} dist/ \;
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create GitHub Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
|
tag_name: ${{ needs.prepare.outputs.version }}
|
||||||
|
target_commitish: ${{ github.sha }}
|
||||||
files: dist/*
|
files: dist/*
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
prerelease: ${{ contains(github.ref, '-') }}
|
prerelease: ${{ needs.prepare.outputs.prerelease == 'true' }}
|
||||||
|
overwrite_files: true
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Docker
|
# Docker
|
||||||
# ==========================
|
# ==========================
|
||||||
docker:
|
docker:
|
||||||
name: Docker (${{ matrix.platform }})
|
name: Docker
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build-gnu, build-musl]
|
needs: [prepare, release]
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- platform: linux/amd64
|
|
||||||
artifact: telemt-x86_64-linux-musl
|
|
||||||
- platform: linux/arm64
|
|
||||||
artifact: telemt-aarch64-linux-musl
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: ${{ matrix.artifact }}
|
|
||||||
path: dist
|
|
||||||
|
|
||||||
- name: Extract binary
|
|
||||||
run: |
|
|
||||||
tar -xzf dist/${{ matrix.artifact }}.tar.gz -C dist
|
|
||||||
chmod +x dist/telemt
|
|
||||||
|
|
||||||
- uses: docker/setup-qemu-action@v3
|
- uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- uses: docker/setup-buildx-action@v3
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- uses: docker/login-action@v3
|
- uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Extract version
|
- name: Probe release assets
|
||||||
id: vars
|
shell: bash
|
||||||
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
env:
|
||||||
|
VERSION: ${{ needs.prepare.outputs.version }}
|
||||||
- name: Build & Push (per arch)
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
for asset in \
|
||||||
|
telemt-x86_64-linux-musl.tar.gz \
|
||||||
|
telemt-x86_64-linux-musl.tar.gz.sha256 \
|
||||||
|
telemt-aarch64-linux-musl.tar.gz \
|
||||||
|
telemt-aarch64-linux-musl.tar.gz.sha256
|
||||||
|
do
|
||||||
|
curl -fsIL \
|
||||||
|
--retry 10 \
|
||||||
|
--retry-delay 3 \
|
||||||
|
"https://github.com/${GITHUB_REPOSITORY}/releases/download/${VERSION}/${asset}" \
|
||||||
|
> /dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Compute image tags
|
||||||
|
id: meta
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
VERSION: ${{ needs.prepare.outputs.version }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
IMAGE="$(echo "ghcr.io/${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
TAGS="${IMAGE}:${VERSION}"
|
||||||
|
|
||||||
|
if [[ "${VERSION}" != *-* ]]; then
|
||||||
|
TAGS="${TAGS}"$'\n'"${IMAGE}:latest"
|
||||||
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "tags<<EOF"
|
||||||
|
printf '%s\n' "${TAGS}"
|
||||||
|
echo "EOF"
|
||||||
|
} >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
- name: Build & Push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
platforms: ${{ matrix.platform }}
|
pull: true
|
||||||
tags: |
|
platforms: linux/amd64,linux/arm64
|
||||||
ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.VERSION }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
ghcr.io/${{ github.repository }}:latest
|
|
||||||
build-args: |
|
build-args: |
|
||||||
BINARY=dist/telemt
|
TELEMT_REPOSITORY=${{ github.repository }}
|
||||||
|
TELEMT_VERSION=${{ needs.prepare.outputs.version }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
|
||||||
|
|
@ -54,14 +54,20 @@ jobs:
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
|
~/.cargo/bin
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
target
|
target
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-nextest-${{ hashFiles('**/Cargo.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-nextest-
|
||||||
${{ runner.os }}-cargo-
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
- run: cargo test --verbose
|
- name: Install cargo-nextest
|
||||||
|
run: cargo install --locked cargo-nextest || true
|
||||||
|
|
||||||
|
- name: Run tests with nextest
|
||||||
|
run: cargo nextest run -j "$(nproc)"
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Clippy
|
# Clippy
|
||||||
|
|
@ -88,11 +94,13 @@ jobs:
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
target
|
target
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-clippy-
|
||||||
${{ runner.os }}-cargo-
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
- run: cargo clippy -- --cap-lints warn
|
- name: Run clippy
|
||||||
|
run: cargo clippy -j "$(nproc)" -- --cap-lints warn
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Udeps
|
# Udeps
|
||||||
|
|
@ -108,20 +116,24 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
components: rust-src
|
||||||
|
|
||||||
- name: Cache cargo
|
- name: Cache cargo
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
|
~/.cargo/bin
|
||||||
~/.cargo/registry
|
~/.cargo/registry
|
||||||
~/.cargo/git
|
~/.cargo/git
|
||||||
target
|
target
|
||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-udeps-${{ hashFiles('**/Cargo.lock') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
|
${{ runner.os }}-cargo-udeps-
|
||||||
${{ runner.os }}-cargo-
|
${{ runner.os }}-cargo-
|
||||||
|
|
||||||
- name: Install cargo-udeps
|
- name: Install cargo-udeps
|
||||||
run: cargo install cargo-udeps || true
|
run: cargo install --locked cargo-udeps || true
|
||||||
|
|
||||||
# тоже не валит билд
|
- name: Run udeps
|
||||||
- run: cargo udeps || true
|
run: cargo udeps -j "$(nproc)" || true
|
||||||
|
|
|
||||||
|
|
@ -2793,7 +2793,7 @@ checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "telemt"
|
name = "telemt"
|
||||||
version = "3.3.30"
|
version = "3.3.31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "telemt"
|
name = "telemt"
|
||||||
version = "3.3.30"
|
version = "3.3.31"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
60
Dockerfile
60
Dockerfile
|
|
@ -1,52 +1,62 @@
|
||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
ARG BINARY
|
ARG TELEMT_REPOSITORY=telemt/telemt
|
||||||
ARG TARGETARCH
|
ARG TELEMT_VERSION=latest
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Stage: minimal
|
# Minimal Image
|
||||||
# ==========================
|
# ==========================
|
||||||
FROM debian:12-slim AS minimal
|
FROM debian:12-slim AS minimal
|
||||||
|
|
||||||
ARG TARGETARCH
|
ARG TARGETARCH
|
||||||
ARG BINARY
|
ARG TELEMT_REPOSITORY
|
||||||
|
ARG TELEMT_VERSION
|
||||||
|
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apt-get update; \
|
apt-get update; \
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
binutils \
|
binutils \
|
||||||
|
ca-certificates \
|
||||||
curl \
|
curl \
|
||||||
xz-utils \
|
tar; \
|
||||||
ca-certificates; \
|
rm -rf /var/lib/apt/lists/*
|
||||||
rm -rf /var/lib/apt/lists/*; \
|
|
||||||
\
|
RUN set -eux; \
|
||||||
case "${TARGETARCH}" in \
|
case "${TARGETARCH}" in \
|
||||||
amd64) UPX_ARCH="amd64" ;; \
|
amd64) ASSET="telemt-x86_64-linux-musl.tar.gz" ;; \
|
||||||
arm64) UPX_ARCH="arm64" ;; \
|
arm64) ASSET="telemt-aarch64-linux-musl.tar.gz" ;; \
|
||||||
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
|
*) echo "Unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
|
||||||
esac; \
|
esac; \
|
||||||
\
|
VERSION="${TELEMT_VERSION#refs/tags/}"; \
|
||||||
|
if [ -z "${VERSION}" ] || [ "${VERSION}" = "latest" ]; then \
|
||||||
|
BASE_URL="https://github.com/${TELEMT_REPOSITORY}/releases/latest/download"; \
|
||||||
|
else \
|
||||||
|
BASE_URL="https://github.com/${TELEMT_REPOSITORY}/releases/download/${VERSION}"; \
|
||||||
|
fi; \
|
||||||
curl -fL \
|
curl -fL \
|
||||||
--retry 5 \
|
--retry 5 \
|
||||||
--retry-delay 3 \
|
--retry-delay 3 \
|
||||||
--connect-timeout 10 \
|
--connect-timeout 10 \
|
||||||
--max-time 120 \
|
--max-time 120 \
|
||||||
-o /tmp/upx.tar.xz \
|
-o "/tmp/${ASSET}" \
|
||||||
"https://github.com/telemt/telemt/releases/download/toolchains/upx-${UPX_ARCH}_linux.tar.xz"; \
|
"${BASE_URL}/${ASSET}"; \
|
||||||
\
|
curl -fL \
|
||||||
tar -xf /tmp/upx.tar.xz -C /tmp; \
|
--retry 5 \
|
||||||
install -m 0755 /tmp/upx*/upx /usr/local/bin/upx; \
|
--retry-delay 3 \
|
||||||
rm -rf /tmp/upx*
|
--connect-timeout 10 \
|
||||||
|
--max-time 120 \
|
||||||
COPY ${BINARY} /telemt
|
-o "/tmp/${ASSET}.sha256" \
|
||||||
|
"${BASE_URL}/${ASSET}.sha256"; \
|
||||||
RUN set -eux; \
|
cd /tmp; \
|
||||||
test -f /telemt; \
|
sha256sum -c "${ASSET}.sha256"; \
|
||||||
|
tar -xzf "${ASSET}" -C /tmp; \
|
||||||
|
test -f /tmp/telemt; \
|
||||||
|
install -m 0755 /tmp/telemt /telemt; \
|
||||||
strip --strip-unneeded /telemt || true; \
|
strip --strip-unneeded /telemt || true; \
|
||||||
upx --best --lzma /telemt || true
|
rm -f "/tmp/${ASSET}" "/tmp/${ASSET}.sha256" /tmp/telemt
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Debug image
|
# Debug Image
|
||||||
# ==========================
|
# ==========================
|
||||||
FROM debian:12-slim AS debug
|
FROM debian:12-slim AS debug
|
||||||
|
|
||||||
|
|
@ -71,7 +81,7 @@ ENTRYPOINT ["/app/telemt"]
|
||||||
CMD ["config.toml"]
|
CMD ["config.toml"]
|
||||||
|
|
||||||
# ==========================
|
# ==========================
|
||||||
# Production (distroless, for static MUSL binary)
|
# Production Distroless on MUSL
|
||||||
# ==========================
|
# ==========================
|
||||||
FROM gcr.io/distroless/static-debian12 AS prod
|
FROM gcr.io/distroless/static-debian12 AS prod
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use std::sync::Arc;
|
||||||
use std::sync::{Mutex, OnceLock};
|
use std::sync::{Mutex, OnceLock};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
|
||||||
use tracing::{debug, trace, warn};
|
use tracing::{debug, info, trace, warn};
|
||||||
use zeroize::{Zeroize, Zeroizing};
|
use zeroize::{Zeroize, Zeroizing};
|
||||||
|
|
||||||
use crate::config::{ProxyConfig, UnknownSniAction};
|
use crate::config::{ProxyConfig, UnknownSniAction};
|
||||||
|
|
@ -28,6 +28,8 @@ use rand::RngExt;
|
||||||
|
|
||||||
const ACCESS_SECRET_BYTES: usize = 16;
|
const ACCESS_SECRET_BYTES: usize = 16;
|
||||||
static INVALID_SECRET_WARNED: OnceLock<Mutex<HashSet<(String, String)>>> = OnceLock::new();
|
static INVALID_SECRET_WARNED: OnceLock<Mutex<HashSet<(String, String)>>> = OnceLock::new();
|
||||||
|
const UNKNOWN_SNI_WARN_COOLDOWN_SECS: u64 = 5;
|
||||||
|
static UNKNOWN_SNI_WARN_NEXT_ALLOWED: OnceLock<Mutex<Option<Instant>>> = OnceLock::new();
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
const WARNED_SECRET_MAX_ENTRIES: usize = 64;
|
const WARNED_SECRET_MAX_ENTRIES: usize = 64;
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
|
|
@ -86,6 +88,24 @@ fn auth_probe_saturation_state_lock()
|
||||||
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unknown_sni_warn_state_lock() -> std::sync::MutexGuard<'static, Option<Instant>> {
|
||||||
|
UNKNOWN_SNI_WARN_NEXT_ALLOWED
|
||||||
|
.get_or_init(|| Mutex::new(None))
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_emit_unknown_sni_warn(now: Instant) -> bool {
|
||||||
|
let mut guard = unknown_sni_warn_state_lock();
|
||||||
|
if let Some(next_allowed) = *guard
|
||||||
|
&& now < next_allowed
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*guard = Some(now + Duration::from_secs(UNKNOWN_SNI_WARN_COOLDOWN_SECS));
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn normalize_auth_probe_ip(peer_ip: IpAddr) -> IpAddr {
|
fn normalize_auth_probe_ip(peer_ip: IpAddr) -> IpAddr {
|
||||||
match peer_ip {
|
match peer_ip {
|
||||||
IpAddr::V4(ip) => IpAddr::V4(ip),
|
IpAddr::V4(ip) => IpAddr::V4(ip),
|
||||||
|
|
@ -412,6 +432,25 @@ fn auth_probe_test_lock() -> &'static Mutex<()> {
|
||||||
TEST_LOCK.get_or_init(|| Mutex::new(()))
|
TEST_LOCK.get_or_init(|| Mutex::new(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn unknown_sni_warn_test_lock() -> &'static Mutex<()> {
|
||||||
|
static TEST_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
|
||||||
|
TEST_LOCK.get_or_init(|| Mutex::new(()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn clear_unknown_sni_warn_state_for_testing() {
|
||||||
|
if UNKNOWN_SNI_WARN_NEXT_ALLOWED.get().is_some() {
|
||||||
|
let mut guard = unknown_sni_warn_state_lock();
|
||||||
|
*guard = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn should_emit_unknown_sni_warn_for_testing(now: Instant) -> bool {
|
||||||
|
should_emit_unknown_sni_warn(now)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn clear_warned_secrets_for_testing() {
|
fn clear_warned_secrets_for_testing() {
|
||||||
if let Some(warned) = INVALID_SECRET_WARNED.get()
|
if let Some(warned) = INVALID_SECRET_WARNED.get()
|
||||||
|
|
@ -658,12 +697,25 @@ where
|
||||||
if client_sni.is_some() && matched_tls_domain.is_none() && preferred_user_hint.is_none() {
|
if client_sni.is_some() && matched_tls_domain.is_none() && preferred_user_hint.is_none() {
|
||||||
auth_probe_record_failure(peer.ip(), Instant::now());
|
auth_probe_record_failure(peer.ip(), Instant::now());
|
||||||
maybe_apply_server_hello_delay(config).await;
|
maybe_apply_server_hello_delay(config).await;
|
||||||
debug!(
|
let sni = client_sni.as_deref().unwrap_or_default();
|
||||||
peer = %peer,
|
let log_now = Instant::now();
|
||||||
sni = ?client_sni,
|
if should_emit_unknown_sni_warn(log_now) {
|
||||||
action = ?config.censorship.unknown_sni_action,
|
warn!(
|
||||||
"TLS handshake rejected by unknown SNI policy"
|
peer = %peer,
|
||||||
);
|
sni = %sni,
|
||||||
|
unknown_sni = true,
|
||||||
|
unknown_sni_action = ?config.censorship.unknown_sni_action,
|
||||||
|
"TLS handshake rejected by unknown SNI policy"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
peer = %peer,
|
||||||
|
sni = %sni,
|
||||||
|
unknown_sni = true,
|
||||||
|
unknown_sni_action = ?config.censorship.unknown_sni_action,
|
||||||
|
"TLS handshake rejected by unknown SNI policy"
|
||||||
|
);
|
||||||
|
}
|
||||||
return match config.censorship.unknown_sni_action {
|
return match config.censorship.unknown_sni_action {
|
||||||
UnknownSniAction::Drop => HandshakeResult::Error(ProxyError::UnknownTlsSni),
|
UnknownSniAction::Drop => HandshakeResult::Error(ProxyError::UnknownTlsSni),
|
||||||
UnknownSniAction::Mask => HandshakeResult::BadClient { reader, writer },
|
UnknownSniAction::Mask => HandshakeResult::BadClient { reader, writer },
|
||||||
|
|
|
||||||
|
|
@ -1643,6 +1643,32 @@ fn auth_probe_capacity_fresh_full_map_still_tracks_newcomer_with_bounded_evictio
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unknown_sni_warn_cooldown_first_event_is_warn_and_repeated_events_are_info_until_window_expires()
|
||||||
|
{
|
||||||
|
let _guard = unknown_sni_warn_test_lock()
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|poisoned| poisoned.into_inner());
|
||||||
|
clear_unknown_sni_warn_state_for_testing();
|
||||||
|
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
should_emit_unknown_sni_warn_for_testing(now),
|
||||||
|
"first unknown SNI event must be eligible for WARN emission"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
!should_emit_unknown_sni_warn_for_testing(now + Duration::from_secs(1)),
|
||||||
|
"events inside cooldown window must be demoted from WARN to INFO"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
should_emit_unknown_sni_warn_for_testing(
|
||||||
|
now + Duration::from_secs(UNKNOWN_SNI_WARN_COOLDOWN_SECS)
|
||||||
|
),
|
||||||
|
"once cooldown expires, next unknown SNI event must be WARN-eligible again"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stress_auth_probe_full_map_churn_keeps_bound_and_tracks_newcomers() {
|
fn stress_auth_probe_full_map_churn_keeps_bound_and_tracks_newcomers() {
|
||||||
let _guard = auth_probe_test_lock()
|
let _guard = auth_probe_test_lock()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue