Skip to content

Build and push yle-dl Docker image #789

Build and push yle-dl Docker image

Build and push yle-dl Docker image #789

Workflow file for this run

name: Build and push new yle-dl version
on:
schedule:
- cron: '0 0 * * *'
push:
branches: [main, master]
workflow_dispatch:
env:
REGISTRY: docker.io
IMAGE_NAME: taskinen/yle-dl
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
latest-version: ${{ steps.version-check.outputs.latest }}
will-build: ${{ steps.version-check.outputs.will-build }}
steps:
- name: Signal start
run: curl -m 10 --retry 5 ${{ vars.YLEDL_SIGNAL_URL }}/start || true
shell: bash
- name: Check if newer yle-dl version is released
id: version-check
run: |
set -euo pipefail
# Get latest version from PyPI
LATEST=$(curl -s "https://pypi.org/pypi/yle-dl/json" | jq -r '.info.version')
echo "latest=${LATEST}" >> $GITHUB_OUTPUT
echo "Latest version for yle-dl is currently ${LATEST}"
# Check if Docker image already exists
if curl --silent --fail --head "https://hub.docker.com/v2/repositories/${IMAGE_NAME}/tags/${LATEST}/" > /dev/null 2>&1; then
echo "Docker image for ${LATEST} already exists. Will not build."
echo "will-build=false" >> "$GITHUB_OUTPUT"
else
echo "Docker image for ${LATEST} does not exist. Will build."
echo "will-build=true" >> "$GITHUB_OUTPUT"
fi
shell: bash
build-and-push:
needs: check-version
if: needs.check-version.outputs.will-build == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ needs.check-version.outputs.latest-version }}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
YLE_DL_VERSION=${{ needs.check-version.outputs.latest-version }}
notify-result:
needs: [check-version, build-and-push]
if: always()
runs-on: ubuntu-latest
steps:
- name: Signal build result
run: |
if [[ "${{ needs.build-and-push.result }}" == "success" || "${{ needs.check-version.outputs.will-build }}" == "false" ]]; then
curl -m 10 --retry 5 ${{ vars.YLEDL_SIGNAL_URL }} || true
else
curl -m 10 --retry 5 ${{ vars.YLEDL_SIGNAL_URL }}/fail || true
fi
shell: bash