Build and Push Docker Image #6
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 Push Docker Image | |
on: | |
workflow_dispatch: # Allows manual trigger | |
release: | |
types: | |
- published # Triggers automatically when a new release is published | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Get Git Commit Hash | |
run: echo "GIT_HASH=$(git rev-parse --short=9 HEAD)" >> $GITHUB_ENV | |
- name: Get Latest Release Tag | |
id: get_tag | |
run: | | |
TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) | |
echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: | | |
docker build --platform linux/amd64 \ | |
-t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest \ | |
-t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH \ | |
-t ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$RELEASE_TAG . | |
- name: Push Docker image | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$GIT_HASH | |
docker push ${{ secrets.DOCKER_USERNAME }}/ebook2audiobook:$RELEASE_TAG |