build-web-image.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. name: Build and Push WEB Image
  2. on:
  3. push:
  4. branches:
  5. - 'main'
  6. - 'deploy/dev'
  7. release:
  8. types: [published]
  9. jobs:
  10. build-and-push:
  11. runs-on: ubuntu-latest
  12. if: github.event.pull_request.draft == false
  13. steps:
  14. - name: Set up QEMU
  15. uses: docker/setup-qemu-action@v3
  16. - name: Set up Docker Buildx
  17. uses: docker/setup-buildx-action@v3
  18. - name: Login to Docker Hub
  19. uses: docker/login-action@v2
  20. with:
  21. username: ${{ secrets.DOCKERHUB_USER }}
  22. password: ${{ secrets.DOCKERHUB_TOKEN }}
  23. - name: Extract metadata (tags, labels) for Docker
  24. id: meta
  25. uses: docker/metadata-action@v5
  26. with:
  27. images: langgenius/dify-web
  28. tags: |
  29. type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
  30. type=ref,event=branch
  31. type=sha,enable=true,priority=100,prefix=,suffix=,format=long
  32. type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
  33. - name: Build and push
  34. uses: docker/build-push-action@v5
  35. with:
  36. context: "{{defaultContext}}:web"
  37. platforms: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
  38. build-args: |
  39. COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
  40. push: true
  41. tags: ${{ steps.meta.outputs.tags }}
  42. labels: ${{ steps.meta.outputs.labels }}
  43. cache-from: type=gha
  44. cache-to: type=gha,mode=max
  45. - name: Deploy to server
  46. if: github.ref == 'refs/heads/deploy/dev'
  47. uses: appleboy/ssh-action@v0.1.8
  48. with:
  49. host: ${{ secrets.SSH_HOST }}
  50. username: ${{ secrets.SSH_USER }}
  51. key: ${{ secrets.SSH_PRIVATE_KEY }}
  52. script: |
  53. ${{ secrets.SSH_SCRIPT }}