76 lines
2.7 KiB
YAML
76 lines
2.7 KiB
YAML
name: Build and Push Docker Image (Local Registry)
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Tag for the Docker image'
|
|
required: false
|
|
default: 'latest'
|
|
|
|
env:
|
|
# Замените на ваш локальный registry URL
|
|
REGISTRY: registry.example.com
|
|
IMAGE_NAME: salvagedb/salvagedb-bot
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Local Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Generate tags
|
|
id: tags
|
|
run: |
|
|
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
|
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
|
|
tag=${GITHUB_REF#refs/tags/}
|
|
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${tag},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ github.ref_name }}" == "main" ]]; then
|
|
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main" >> $GITHUB_OUTPUT
|
|
else
|
|
branch_name=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9]/-/g')
|
|
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${branch_name}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
platforms: linux/amd64
|
|
push: true
|
|
tags: ${{ steps.tags.outputs.tags }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
labels: |
|
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
|
|
|
|
- name: Summary
|
|
run: |
|
|
echo "## Docker Build Summary" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Image:** ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Tags:** ${{ steps.tags.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY |