Skip to content

Build & Push Docker #835

Build & Push Docker

Build & Push Docker #835

name: Build & Push Docker
on:
workflow_dispatch:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
schedule:
- cron: '0 13-21/2 * * *' # every 2 hours during US Eastern daytime
jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.1
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 9.12.3
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Build server
run: pnpm turbo typecheck --filter=@tunarr/server
- name: Build web
run: pnpm turbo build --filter=@tunarr/web
build_and_push:
needs: typecheck
runs-on: ubuntu-latest
continue-on-error: true
strategy:
max-parallel: 2
matrix:
builds:
- base_tag: '7.0'
platform: linux/amd64
suffix:
- base_tag: 7.0-nvidia
platform: linux/amd64
suffix: -nvidia
- base_tag: 7.0-vaapi
platform: linux/amd64
suffix: -vaapi
- base_tag: 7.0-arm64
platform: linux/arm64
suffix: -arm64
- base_tag: 7.0-arm
platform: linux/arm/v7
suffix: -arm
steps:
- uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
suffix=${{ matrix.builds.suffix }},onlatest=true
images: |
chrisbenincasa/tunarr
ghcr.io/chrisbenincasa/tunarr
tags: |
# Update edge tag on the scheduled build
type=schedule,pattern=edge
# Update version tags on proper releases
type=semver,pattern={{version}}
# Update edge tag when we manually trigger the release
type=raw,value=edge,enable=${{github.ref == format('refs/heads/{0}', 'dev') && github.event_name == 'workflow_dispatch'}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v4 # Cache previous HEAD SHA
with:
path: previous_head_sha
key: ${{ runner.os }}-edge-build-${{ github.sha }}
restore-keys: | # Check for previous SHA in cache
${{ runner.os }}-edge-build-
- name: Check for HEAD commit changes
run: |
git fetch origin main
HEAD_SHA=$(git rev-parse HEAD)
if [[ -z "$PREVIOUS_HEAD_SHA" ]]; then
echo "No previous HEAD SHA found (first run). Building image."
elif [[ "$HEAD_SHA" != "$PREVIOUS_HEAD_SHA" ]]; then
echo "Head commit has changed. Building and pushing image."
else
echo "Head commit hasn't changed. Skipping build."
exit 0 # Exit without pushing the image
fi
echo "PREVIOUS_HEAD_SHA=$HEAD_SHA" >> previous_head_sha # Save current SHA for next run
if: github.event_name == 'schedule'
- name: Generate Version Number
run: |
echo "TUNARR_VERSION=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: ${{matrix.builds.platform}}
build-args: |
base_image_tag=${{ matrix.builds.base_tag }}
is_edge_build=${{github.ref == format('refs/heads/{0}', 'dev') && github.event_name == 'schedule'}}
tunarr_build="${{ env.TUNARR_VERSION }}"
target: full-stack
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max