Skip to content

OwnTone Container

OwnTone Container #33

name: OwnTone Container
on:
push:
branches:
- main
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
env:
NAME: ${{ vars.NAME }}
NAMESPACE: ${{ vars.NAMESPACE }}
REPOSITORY_BRANCH: ${{ vars.REPOSITORY_BRANCH }}
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
jobs:
preparation:
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.next-stages.outputs.commit }}
version: ${{ steps.next-stages.outputs.version }}
steps:
- name: Determine run of next stages
id: next-stages
run: |
registry=https://hub.docker.com/v2/namespaces/$NAMESPACE/repositories/$NAME/tags
git clone -q -b $REPOSITORY_BRANCH $REPOSITORY_URL source
cd source
commit=$(git log --branches -1 --pretty=format:"%h")
[[ $(curl -LI ${registry}/${commit} -o /dev/null -w '%{http_code}\n' -s) = "200" ]] && commit=
echo "commit=${commit}" >> $GITHUB_OUTPUT
version=$(git describe --tags $(git rev-list --tags --max-count=1))
[[ $(curl -LI ${registry}/${version} -o /dev/null -w '%{http_code}\n' -s) = "200" ]] && version=
echo "version=${version}" >> $GITHUB_OUTPUT
staging:
needs: preparation
runs-on: ubuntu-latest
if: needs.preparation.outputs.commit
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Sign into Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
build-args: |
REPOSITORY_URL=${{ env.REPOSITORY_URL }}
REPOSITORY_BRANCH=${{ env.REPOSITORY_BRANCH }}
REPOSITORY_COMMIT=${{ needs.preparation.outputs.commit }}
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.NAMESPACE }}/${{ env.NAME }}:staging
${{ env.NAMESPACE }}/${{ env.NAME }}:${{ needs.preparation.outputs.commit }}
production:
needs: preparation
runs-on: ubuntu-latest
if: needs.preparation.outputs.version
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Sign into Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
build-args: |
REPOSITORY_URL=${{ env.REPOSITORY_URL }}
REPOSITORY_BRANCH=${{ env.REPOSITORY_BRANCH }}
REPOSITORY_TAG=${{ needs.preparation.outputs.version }}
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.NAMESPACE }}/${{ env.NAME }}:latest
${{ env.NAMESPACE }}/${{ env.NAME }}:${{ needs.preparation.outputs.version }}