Merge pull request #337 from euzu/feature/enhance_epg_smart_match #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: all | |
- 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/cross | |
~/.cargo/bin/trunk | |
~/.cargo/bin/wasm-bindgen | |
key: ${{ runner.os }}-cargo-tools-${{ hashFiles('**/Cargo.lock') }}-v2 | |
restore-keys: | | |
${{ runner.os }}-cargo-tools- | |
- name: Install cross | |
if: steps.cache-tools.outputs.cache-hit != 'true' | |
run: cargo install cross --git https://github.com/cross-rs/cross | |
- name: Install trunk and wasm-bindgen-cli | |
if: steps.cache-tools.outputs.cache-hit != 'true' | |
run: | | |
cargo install trunk | |
cargo install wasm-bindgen-cli | |
- 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 | |
uses: actions/cache@v4 | |
with: | |
path: | | |
resources/*.ts | |
key: ${{ runner.os }}-resources-${{ hashFiles('resources/*.jpg') }}-v1 | |
restore-keys: | | |
${{ runner.os }}-resources- | |
- name: Install ffmpeg | |
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 |