Build and publish Docker image #27
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: Build and publish Docker image # source: https://github.com/TRIGONIM/lua-long-polling/blob/main/.github/workflows/docker-image.yml | |
on: | |
schedule: | |
- cron: "37 13 * * 1" | |
push: | |
branches: [ "main" ] | |
tags: [ "v*.*.*" ] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} # <account>/<repo> | |
jobs: | |
build_and_publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# При обычном коммите делает тег main (ветка) вместо latest. Логично, но некрасиво. Ниже изменения | |
# 1. Применяет тег "latest", если текущий ref является тегом | |
# 2. Применяет тег, основанный на имени ветки | |
# 3. Применяет тег, основанный на хэше коммита | |
# 4. Применяет тег, аналогичный тегу рефа, если текущий ref является тегом | |
# Альтернативный вариант: https://github.com/strato-earth/workflow-task-template/blob/038f51662aff7e1b9fd6cf98c13e0e3ee8c65855/github/build.yml#L34-L44C17 | |
tags: | | |
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
type=ref,event=branch | |
type=sha,format=short | |
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }} | |
- uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |