2024-02-13 23:57:45 +00:00
|
|
|
name: Build and Publish Docker Image
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2024-02-14 00:16:12 +00:00
|
|
|
branches: [main]
|
|
|
|
tag_push:
|
|
|
|
paths:
|
|
|
|
- '*/' # Include all tags in any directory
|
2024-02-13 23:57:45 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-and-publish:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2024-02-14 00:16:12 +00:00
|
|
|
- name: Checkout repository
|
2024-02-13 23:57:45 +00:00
|
|
|
uses: actions/checkout@v2
|
2024-02-14 00:16:12 +00:00
|
|
|
|
|
|
|
- name: Setup Docker Buildx
|
|
|
|
uses: docker-actions/setup-buildx-action@v1
|
2024-02-13 23:57:45 +00:00
|
|
|
with:
|
2024-02-14 00:16:12 +00:00
|
|
|
context: ${{ github.workspace }}
|
|
|
|
|
|
|
|
- name: Login to Docker Hub
|
|
|
|
uses: actions/docker/login@v2
|
|
|
|
with:
|
|
|
|
registry: ${{ secrets.DOCKERHUB_USERNAME }}
|
2024-02-13 23:57:45 +00:00
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
2024-02-14 00:16:12 +00:00
|
|
|
|
|
|
|
- name: Build image
|
|
|
|
id: build
|
|
|
|
uses: docker-buildx-action@v1
|
|
|
|
with:
|
|
|
|
context: ${{ github.workspace }}
|
|
|
|
push: false
|
|
|
|
dockerfile: Dockerfile
|
|
|
|
|
|
|
|
- name: Tag and publish image (main branch)
|
|
|
|
if: github.ref == 'refs/heads/main'
|
|
|
|
uses: docker-actions/push-image@v2
|
|
|
|
with:
|
|
|
|
context: ${{ github.workspace }}
|
|
|
|
registry: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
tag: latest
|
|
|
|
|
|
|
|
- name: Tag and publish image (git tags)
|
|
|
|
if: startsWith(github.event.ref, 'refs/tags/')
|
|
|
|
uses: docker-actions/tag-image@v1
|
|
|
|
with:
|
|
|
|
context: ${{ github.workspace }}
|
|
|
|
registry: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
image: ${{ steps.build.outputs.image }}
|
|
|
|
tag: ${{ github.event.ref.replace('refs/tags/', '') }}
|
|
|
|
|
|
|
|
- name: Publish tagged image
|
|
|
|
uses: docker-actions/push-image@v2
|
|
|
|
with:
|
|
|
|
context: ${{ github.workspace }}
|
|
|
|
registry: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
tag: ${{ github.event.ref.replace('refs/tags/', '') }}
|
|
|
|
|
|
|
|
- name: Set output image name
|
|
|
|
uses: actions/set-output@v1
|
|
|
|
with:
|
|
|
|
name: image_name
|
|
|
|
value: ${{ steps.build.outputs.image }}
|
|
|
|
|
|
|
|
- name: Save image to GitHub Container Registry (optional)
|
|
|
|
if: github.event.action == 'push' && github.ref == 'refs/heads/main'
|
|
|
|
uses: actions/create-github-container-registry-image@v1
|
|
|
|
with:
|
|
|
|
name: sami/brudi-rclone
|
|
|
|
image: ${{ steps.build.outputs.image }}
|
2024-02-13 23:57:45 +00:00
|
|
|
|