Fix default branch detection #540
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: Docker | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository_owner }}/roshar-map | |
tags: | | |
type=raw,value=latest,enable=${{ github.ref == format('refs/head/{0}', github.event.repository.default_branch) }} | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == format('refs/head/{0}', github.event.repository.default_branch)) | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push release version | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == format('refs/head/{0}', github.event.repository.default_branch)) }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Build and push dev version | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: Dockerfile-dev | |
push: ${{ github.ref == format('refs/head/{0}', github.event.repository.default_branch) }} | |
tags: ghcr.io/${{ github.repository_owner }}/roshar-map:latest-dev | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
PUBLIC_URL=${{ secrets.DOCKER_DEV_PUBLIC_URL }} | |
update-service: | |
runs-on: ubuntu-latest | |
needs: [build] | |
if: github.event_name == 'push' && github.ref == format('refs/head/{0}', github.event.repository.default_branch) && (contains(github.event.head_commit.message, '[deploy-dev]') || contains(github.event.head_commit.message, '[deploy]')) | |
steps: | |
- name: Setup SSH Keys and known_hosts | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan "${{ secrets.DOCKER_HOST }}" >> ~/.ssh/known_hosts | |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null | |
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}" | |
- name: Update Docker service | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
ssh github@${{ secrets.DOCKER_HOST }} 'docker pull ghcr.io/17thshard/roshar-map:latest-dev && docker service update --force --image ghcr.io/17thshard/roshar-map:latest-dev ${{ secrets.DOCKER_DEV_SERVICE_NAME }}' |