Skip to content

Docker

Docker #3071

Workflow file for this run

name: Docker
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
push:
branches:
- main
tags:
- 'v*'
permissions: read-all
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
jobs:
build_and_publish:
name: Publish to ${{ matrix.registry_name }}
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:
include:
- registry_name: GHCR
registry: ghcr.io
image: ghcr.io/endstonemc/endstone
username_secret: github_actor
password_secret: GITHUB_TOKEN
- registry_name: Docker Hub
registry: docker.io
image: endstone/endstone
username_secret: DOCKERHUB_USERNAME
password_secret: DOCKERHUB_TOKEN
tags_only: true
steps:
- name: Check if job should run
id: guard
shell: bash
run: |
if [ "${{ matrix.tags_only }}" = "true" ] && ! [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Checkout Code
if: steps.guard.outputs.skip != 'true'
uses: actions/checkout@v6
with:
fetch-depth: 0
submodules: true
- name: Set up Docker Buildx
if: steps.guard.outputs.skip != 'true'
uses: docker/setup-buildx-action@v3
- name: Login to ${{ matrix.registry_name }}
if: steps.guard.outputs.skip != 'true'
uses: docker/login-action@v4
with:
registry: ${{ matrix.registry }}
username: ${{ matrix.username_secret == 'github_actor' && github.actor || secrets[matrix.username_secret] }}
password: ${{ secrets[matrix.password_secret] }}
- name: Extract Metadata
if: steps.guard.outputs.skip != 'true'
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ matrix.image }}
tags: |
type=raw,value=latest,enable={{ is_default_branch }}
type=pep440,pattern={{version}}
- name: Build and Push
if: steps.guard.outputs.skip != 'true'
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
secrets: |
sentry-auth-token=${{ secrets.SENTRY_AUTH_TOKEN }}