uffizzi-build.yml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. name: Build PR Image
  2. on:
  3. pull_request:
  4. types: [opened, synchronize, reopened, closed]
  5. jobs:
  6. build-memos:
  7. name: Build and push `Memos`
  8. runs-on: ubuntu-latest
  9. outputs:
  10. tags: ${{ steps.meta.outputs.tags }}
  11. if: ${{ github.event.action != 'closed' }}
  12. steps:
  13. - name: Checkout git repo
  14. uses: actions/checkout@v3
  15. - name: Set up Docker Buildx
  16. uses: docker/setup-buildx-action@v2
  17. - name: Generate UUID image name
  18. id: uuid
  19. run: echo "UUID_WORKER=$(uuidgen)" >> $GITHUB_ENV
  20. - name: Docker metadata
  21. id: meta
  22. uses: docker/metadata-action@v4
  23. with:
  24. images: registry.uffizzi.com/${{ env.UUID_WORKER }}
  25. tags: |
  26. type=raw,value=60d
  27. - name: Build and Push Image to registry.uffizzi.com - Uffizzi's ephemeral Registry
  28. uses: docker/build-push-action@v3
  29. with:
  30. context: ./
  31. file: Dockerfile
  32. tags: ${{ steps.meta.outputs.tags }}
  33. labels: ${{ steps.meta.outputs.labels }}
  34. push: true
  35. cache-from: type=gha
  36. cache-to: type=gha, mode=max
  37. render-compose-file:
  38. name: Render Docker Compose File
  39. # Pass output of this workflow to another triggered by `workflow_run` event.
  40. runs-on: ubuntu-latest
  41. needs:
  42. - build-memos
  43. outputs:
  44. compose-file-cache-key: ${{ steps.hash.outputs.hash }}
  45. steps:
  46. - name: Checkout git repo
  47. uses: actions/checkout@v3
  48. - name: Render Compose File
  49. run: |
  50. MEMOS_IMAGE=${{ needs.build-memos.outputs.tags }}
  51. export MEMOS_IMAGE
  52. # Render simple template from environment variables.
  53. envsubst < docker-compose.uffizzi.yml > docker-compose.rendered.yml
  54. cat docker-compose.rendered.yml
  55. - name: Upload Rendered Compose File as Artifact
  56. uses: actions/upload-artifact@v3
  57. with:
  58. name: preview-spec
  59. path: docker-compose.rendered.yml
  60. retention-days: 2
  61. - name: Upload PR Event as Artifact
  62. uses: actions/upload-artifact@v3
  63. with:
  64. name: preview-spec
  65. path: ${{github.event_path}}
  66. retention-days: 2
  67. delete-preview:
  68. name: Call for Preview Deletion
  69. runs-on: ubuntu-latest
  70. if: ${{ github.event.action == 'closed' }}
  71. steps:
  72. # If this PR is closing, we will not render a compose file nor pass it to the next workflow.
  73. - name: Upload PR Event as Artifact
  74. uses: actions/upload-artifact@v3
  75. with:
  76. name: preview-spec
  77. path: ${{github.event_path}}
  78. retention-days: 2