Publish Docker Image (GPR) #6346
This file contains 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: Publish Docker Image (GPR) | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '*/5 * * * *' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
APP_ID: 232250 | |
REMOTE_BUILDID: 0 | |
TAG_EXISTS: 'false' | |
TAG: null | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 45 | |
strategy: | |
matrix: | |
tag: [latest, slim] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Fetch depot JSON file | |
run: | | |
curl -L -f -o depot.json https://github.com/doctor-server/app-depots/raw/main/depots/${{ env.APP_ID }}.json | |
- name: Extract buildid | |
id: extract_buildid | |
run: | | |
buildid=$(jq -r '.branches.public.buildid' depot.json) | |
echo "REMOTE_BUILDID=$buildid" >> $GITHUB_ENV | |
if [ "${{ matrix.tag }}" == "latest" ]; then | |
echo "TAG=$buildid" >> $GITHUB_ENV | |
else | |
echo "TAG=$buildid-${{ matrix.tag }}" >> $GITHUB_ENV | |
fi | |
- name: Check if tag exists | |
if: github.event_name != 'workflow_dispatch' | |
id: tag-exists | |
run: | | |
if docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}; then | |
echo "TAG_EXISTS=true" >> $GITHUB_ENV | |
fi | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Free up disk space | |
run: | | |
sudo rm -rf /usr/local/lib/android || true | |
sudo rm -rf /usr/share/dotnet || true | |
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true | |
- name: Log in to the Container registry | |
if: env.TAG_EXISTS == 'false' || github.event_name == 'workflow_dispatch' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
if: env.TAG_EXISTS == 'false' || github.event_name == 'workflow_dispatch' | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=${{ matrix.tag }} | |
type=raw,value=${{ env.TAG }} | |
- name: Push Docker image | |
if: env.TAG_EXISTS == 'false' || github.event_name == 'workflow_dispatch' | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
provenance: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
build-args: | | |
TAG=${{ matrix.tag }} | |
REMOTE_BUILDID=${{ env.REMOTE_BUILDID }} |