diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..580aeb4 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,53 @@ +name: Docker Build and Push + +on: + push: + tags: [ "v*" ] + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ${{ secrets.DOCKER_HUB_USERNAME }}/streamcap:latest + ${{ secrets.DOCKER_HUB_USERNAME }}/streamcap:${{ github.sha }} + ${{ github.ref == 'refs/heads/main' && format('{0}/streamcap:edge', secrets.DOCKER_HUB_USERNAME) || '' }} + ${{ startsWith(github.ref, 'refs/tags/') && format('{0}/streamcap:{1}', secrets.DOCKER_HUB_USERNAME, github.ref_name) || '' }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Notify build status + if: always() + uses: actions/github-script@v7 + with: + script: | + const status = ${{ job.status }} + const message = status === 'success' ? + 'Docker image built successfully!' : + 'Docker image build failed, please check logs.' + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: message + }) \ No newline at end of file