mirror of
https://github.com/euzu/tuliprox.git
synced 2026-09-22 00:52:27 +02:00
154 lines
4.8 KiB
YAML
154 lines
4.8 KiB
YAML
name: Docker Build and Push
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- develop
|
|
|
|
jobs:
|
|
docker-build:
|
|
runs-on: ubuntu-latest
|
|
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
- name: Create and use multi-platform builder
|
|
run: |
|
|
docker buildx create --name multiarch --use --bootstrap
|
|
docker buildx inspect multiarch
|
|
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
targets: x86_64-unknown-linux-musl,aarch64-unknown-linux-musl,wasm32-unknown-unknown
|
|
|
|
- name: Cache cargo tools
|
|
id: cache-tools
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cargo/bin
|
|
~/.cargo/registry
|
|
~/.cargo/git
|
|
key: ${{ runner.os }}-cargo-tools-v1
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-tools-
|
|
|
|
- name: Install cross
|
|
run: |
|
|
if ! command -v cross &> /dev/null; then
|
|
cargo install cross --git https://github.com/cross-rs/cross
|
|
fi
|
|
|
|
- name: Install trunk
|
|
run: |
|
|
if ! command -v trunk &> /dev/null; then
|
|
cargo install trunk
|
|
fi
|
|
|
|
- name: Install wasm-bindgen-cli
|
|
run: |
|
|
if ! command -v wasm-bindgen &> /dev/null; then
|
|
cargo install wasm-bindgen-cli
|
|
fi
|
|
|
|
- name: Cache cargo registry and dependencies
|
|
id: cache-cargo-deps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cargo/registry/index
|
|
~/.cargo/registry/cache
|
|
~/.cargo/git/db
|
|
target
|
|
backend/target
|
|
frontend/target
|
|
shared/target
|
|
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/Cargo.toml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-cargo-deps-${{ hashFiles('**/Cargo.lock') }}-
|
|
${{ runner.os }}-cargo-deps-
|
|
|
|
- name: Cache Docker buildx
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ runner.os }}-buildx-
|
|
|
|
- name: Cache frontend dist
|
|
id: cache-frontend
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: frontend/dist
|
|
key: ${{ runner.os }}-frontend-${{ hashFiles('frontend/**/*', 'shared/**/*') }}-${{ hashFiles('frontend/Cargo.toml', 'frontend/Trunk.toml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-frontend-
|
|
|
|
- name: Cache cross-compilation tools
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cross
|
|
~/.rustup/toolchains/*/lib/rustlib/x86_64-unknown-linux-musl
|
|
~/.rustup/toolchains/*/lib/rustlib/aarch64-unknown-linux-musl
|
|
key: ${{ runner.os }}-cross-${{ hashFiles('**/Cargo.lock') }}-v2
|
|
restore-keys: |
|
|
${{ runner.os }}-cross-
|
|
|
|
- name: Cache built resources
|
|
id: cache-resources
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
resources/*.ts
|
|
key: ${{ runner.os }}-resources-${{ hashFiles('resources/*.jpg') }}-v1
|
|
restore-keys: |
|
|
${{ runner.os }}-resources-
|
|
|
|
- name: Install ffmpeg (only if resources not cached)
|
|
if: steps.cache-resources.outputs.cache-hit != 'true'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y ffmpeg
|
|
|
|
- name: Extract branch name
|
|
shell: bash
|
|
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
|
|
id: extract_branch
|
|
|
|
- name: Create GHCR token file
|
|
run: |
|
|
mkdir -p $HOME
|
|
echo "GHCR_IO_TOKEN=${{ secrets.GHCR_IO_TOKEN }}" > $HOME/.ghcr.io
|
|
|
|
- name: Make build script executable
|
|
run: chmod +x ./bin/build_docker.sh
|
|
|
|
- name: Build and push Docker images
|
|
env:
|
|
FRONTEND_CACHE_HIT: ${{ steps.cache-frontend.outputs.cache-hit }}
|
|
CARGO_DEPS_CACHE_HIT: ${{ steps.cache-cargo-deps.outputs.cache-hit }}
|
|
BUILDX_CACHE_FROM: type=local,src=/tmp/.buildx-cache
|
|
BUILDX_CACHE_TO: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
|
run: ./bin/build_docker.sh ${{ steps.extract_branch.outputs.branch }}
|
|
|
|
- name: Move buildx cache
|
|
run: |
|
|
rm -rf /tmp/.buildx-cache
|
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache || true
|