automation of creating docker images and sending to dockerhub

This commit is contained in:
2025-03-17 09:36:31 +03:00
parent 50ed083712
commit 703bfb1b38
2 changed files with 46 additions and 1 deletions

45
.github/workflows/docker-image.yml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: Docker Image CI
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
jobs:
build:
runs-on: ubuntu-latest
env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/yandexmusicdiscordbot
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get short SHA
id: vars
run: echo "short_sha=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }}
- name: Set the latest tag for the main branch
if: github.ref == 'refs/heads/main'
run: |
docker pull $IMAGE_NAME:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }}
docker tag $IMAGE_NAME:${{ github.ref_name }}-${{ steps.vars.outputs.short_sha }} $IMAGE_NAME:latest
docker push $IMAGE_NAME:latest