diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3fcc069..f80ce42 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -1,63 +1,69 @@ name: Build and Push Docker Image to Docker Hub on: + # Manual Run + workflow_dispatch: + # Push to branches push: branches: - dev - - master # Assuming this corresponds to the master branch + - main + - master + # Pull Requests pull_request: branches: - dev + - main - master - schedule: - - cron: "0 0 * * *" + # Scheduled runs + # schedule: + # - cron: "0 0 * * *" env: - REGISTRY: docker.io - IMAGE_NAME: alexslx/srt-live-server + DOCKER_REGISTRY: docker.io + DOCKER_IMAGE_NAME: ${{ vars.DOCKER_IMAGE_NAME }} jobs: push_to_registry: name: Push Docker image to Docker Hub runs-on: ubuntu-latest steps: - - name: Check out the repo - uses: actions/checkout@v2 + - name: Checkout git repository + uses: actions/checkout@v4 with: ref: ${{ github.ref }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Set up Docker Buildx CLI plugin + uses: docker/setup-buildx-action@v3 - - name: Log in to Docker Hub - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + - name: Log in to Docker Registry + uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }} - name: Build and push Docker image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v6 with: context: "{{defaultContext}}" push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - name: Update latest tag (for master branch) + - name: Update latest tag (for main/master branches) run: | BRANCH_NAME=${GITHUB_REF#refs/heads/} - if [[ "$BRANCH_NAME" == "master" ]]; then - # Execute commands for master branch + if [[ "$BRANCH_NAME" == "main" || "$BRANCH_NAME" == "master" ]]; then echo "Updating latest tag on Docker Hub" - docker pull "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$BRANCH_NAME" - docker tag "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$BRANCH_NAME" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" - docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" + docker pull "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:$BRANCH_NAME" + docker tag "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:$BRANCH_NAME" "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:latest" + docker push "${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:latest" else echo "Skipped." fi