uffizzi-build.yml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: Serialize PR Event to File
  62. run: |
  63. cat << EOF > event.json
  64. ${{ toJSON(github.event) }}
  65. EOF
  66. - name: Upload PR Event as Artifact
  67. uses: actions/upload-artifact@v3
  68. with:
  69. name: preview-spec
  70. path: event.json
  71. retention-days: 2
  72. delete-preview:
  73. name: Call for Preview Deletion
  74. runs-on: ubuntu-latest
  75. if: ${{ github.event.action == 'closed' }}
  76. steps:
  77. # If this PR is closing, we will not render a compose file nor pass it to the next workflow.
  78. - name: Serialize PR Event to File
  79. run: |
  80. cat << EOF > event.json
  81. ${{ toJSON(github.event) }}
  82. EOF
  83. - name: Upload PR Event as Artifact
  84. uses: actions/upload-artifact@v3
  85. with:
  86. name: preview-spec
  87. path: event.json
  88. retention-days: 2