build-api-image.yml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. name: Build and Push API 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@v2
  16. - name: Set up Docker Buildx
  17. uses: docker/setup-buildx-action@v2
  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@v4
  26. with:
  27. images: langgenius/dify-api
  28. tags: |
  29. type=raw,value=latest,enable={{is_default_branch}}
  30. type=ref,event=branch
  31. type=semver,pattern={{major}}.{{minor}}.{{patch}}
  32. type=semver,pattern={{major}}.{{minor}}
  33. type=semver,pattern={{major}}
  34. - name: Build and push
  35. uses: docker/build-push-action@v4
  36. with:
  37. context: "{{defaultContext}}:api"
  38. platforms: linux/amd64,linux/arm64
  39. build-args: |
  40. COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
  41. push: true
  42. tags: ${{ steps.meta.outputs.tags }}
  43. labels: ${{ steps.meta.outputs.labels }}
  44. - name: Deploy to server
  45. if: github.ref == 'refs/heads/deploy/dev'
  46. uses: appleboy/ssh-action@v0.1.8
  47. with:
  48. host: ${{ secrets.SSH_HOST }}
  49. username: ${{ secrets.SSH_USER }}
  50. key: ${{ secrets.SSH_PRIVATE_KEY }}
  51. script: |
  52. ${{ secrets.SSH_SCRIPT }}