build-and-push-stable-image.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. name: build-and-push-stable-image
  2. on:
  3. push:
  4. tags:
  5. # Match stable and rc versions, such as 'v1.0.0' or 'v0.23.0-rc.0'
  6. - "v*.*.*"
  7. - "v*.*.*-rc.*"
  8. jobs:
  9. build-and-push-stable-image:
  10. runs-on: ubuntu-latest
  11. permissions:
  12. contents: read
  13. packages: write
  14. steps:
  15. - uses: actions/checkout@v4
  16. - name: Set up QEMU
  17. uses: docker/setup-qemu-action@v3
  18. - name: Extract build args
  19. # Extract version number and check if it's an rc version
  20. run: |
  21. if [[ "${GITHUB_REF_NAME}" =~ -rc ]]; then
  22. echo "PRE_RELEASE=true" >> $GITHUB_ENV
  23. else
  24. echo "PRE_RELEASE=false" >> $GITHUB_ENV
  25. fi
  26. echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  27. - name: Login to Docker Hub
  28. uses: docker/login-action@v3
  29. with:
  30. username: stevenlgtm
  31. password: ${{ secrets.DOCKER_HUB_TOKEN }}
  32. - name: Login to GitHub Container Registry
  33. uses: docker/login-action@v3
  34. with:
  35. registry: ghcr.io
  36. username: ${{ github.actor }}
  37. password: ${{ github.token }}
  38. - name: Set up Docker Buildx
  39. id: buildx
  40. uses: docker/setup-buildx-action@v3
  41. with:
  42. install: true
  43. version: v0.9.1
  44. # Metadata for stable versions
  45. - name: Docker meta for stable
  46. id: meta-stable
  47. if: env.PRE_RELEASE == 'false'
  48. uses: docker/metadata-action@v5
  49. with:
  50. images: |
  51. neosmemo/memos
  52. ghcr.io/usememos/memos
  53. tags: |
  54. type=semver,pattern={{version}},value=${{ env.VERSION }}
  55. type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }}
  56. type=raw,value=stable
  57. flavor: |
  58. latest=true
  59. labels: |
  60. org.opencontainers.image.version=${{ env.VERSION }}
  61. # Metadata for rc versions
  62. - name: Docker meta for rc
  63. id: meta-rc
  64. if: env.PRE_RELEASE == 'true'
  65. uses: docker/metadata-action@v5
  66. with:
  67. images: |
  68. neosmemo/memos
  69. ghcr.io/usememos/memos
  70. tags: |
  71. type=raw,value=${{ env.VERSION }}
  72. labels: |
  73. org.opencontainers.image.version=${{ env.VERSION }}
  74. - name: Build and Push
  75. id: docker_build
  76. uses: docker/build-push-action@v6
  77. with:
  78. context: ./
  79. file: ./Dockerfile
  80. platforms: linux/amd64,linux/arm64
  81. push: true
  82. tags: ${{ steps.meta-stable.outputs.tags || steps.meta-rc.outputs.tags }}
  83. labels: ${{ steps.meta-stable.outputs.labels || steps.meta-rc.outputs.labels }}