release.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. name: release
  2. on:
  3. push:
  4. branches:
  5. - 'master'
  6. workflow_dispatch:
  7. jobs:
  8. build:
  9. runs-on: ubuntu-latest
  10. steps:
  11. - name: Checkout
  12. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
  13. with:
  14. fetch-depth: '0'
  15. - name: Set env variables
  16. run: |
  17. echo "GITHUB_DATE=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
  18. echo "GITHUB_SHA=${{ github.sha }}" >> $GITHUB_ENV
  19. - name: Get latest Webapp release version
  20. run: |
  21. WEBAPP_RELEASE=$(curl -sX GET "https://api.github.com/repos/netbootxyz/webapp/releases/latest" | jq -r '. | .tag_name')
  22. echo "WEBAPP_RELEASE=${WEBAPP_RELEASE}" >> $GITHUB_ENV
  23. - name: Set up Docker Buildx
  24. uses: docker/setup-buildx-action@v3
  25. - name: Set up QEMU
  26. uses: docker/setup-qemu-action@v3
  27. - name: Login to the Docker Container Registry
  28. uses: docker/login-action@v3
  29. with:
  30. username: ${{ secrets.DOCKERHUB_USER }}
  31. password: ${{ secrets.DOCKERHUB_TOKEN }}
  32. - name: Login to the GitHub Container Registry
  33. uses: docker/login-action@v3
  34. with:
  35. registry: ghcr.io
  36. username: ${{ secrets.GHCR_USER }}
  37. password: ${{ secrets.GHCR_TOKEN }}
  38. - name: Determine version numbers
  39. id: version_check
  40. continue-on-error: true
  41. run: |
  42. IMAGE=netbootxyz/netbootxyz
  43. TOKEN=$(curl -sX GET \
  44. "https://ghcr.io/token?scope=repository%3Anetbootxyz%2Fnetbootxyz%3Apull" \
  45. | jq -r '.token')
  46. TAG=$(curl -s --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
  47. --header "Authorization: Bearer ${TOKEN}" \
  48. "https://ghcr.io/v2/${IMAGE}/tags/list?n=1000" \
  49. | jq -r '.tags[-1]')
  50. echo LATEST_TAG: $TAG
  51. MULTIDIGEST=$(curl -s \
  52. --header "Accept: application/vnd.oci.image.index.v1+json" \
  53. --header "Authorization: Bearer ${TOKEN}" \
  54. "https://ghcr.io/v2/${IMAGE}/manifests/${TAG}" \
  55. | jq -r 'first(.manifests[].digest)')
  56. DIGEST=$(curl -s \
  57. --header "Accept: application/vnd.oci.image.manifest.v1+json" \
  58. --header "Authorization: Bearer ${TOKEN}" \
  59. "https://ghcr.io/v2/${IMAGE}/manifests/${MULTIDIGEST}" \
  60. | jq -r '.config.digest')
  61. IMAGE_INFO=$(curl -sL \
  62. --header "Authorization: Bearer ${TOKEN}" \
  63. "https://ghcr.io/v2/${IMAGE}/blobs/${DIGEST}" \
  64. | jq -r '.config')
  65. IMAGE_RELEASE=$(echo ${IMAGE_INFO} | jq -r '.Labels.build_version' | awk '{print $3}')
  66. IMAGE_VERSION=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $1}')
  67. NB_RELEASE_NUMBER=$(echo ${IMAGE_RELEASE} | awk -F'-nbxyz' '{print $2}')
  68. TAG_SHA=$(git rev-list -n 1 ${IMAGE_RELEASE})
  69. if [ -z "${MULTIDIGEST}" ] || [ "${MULTIDIGEST}" == "null" ]; then
  70. echo "**** No existing container build found, assuming first build ****"
  71. VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1
  72. echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
  73. elif [ "${WEBAPP_RELEASE}" == "${IMAGE_VERSION}" ]; then
  74. echo "**** Version ${WEBAPP_RELEASE} unchanged, checking if there is anything to build..."
  75. if [ "${TAG_SHA}" == "${GITHUB_SHA}" ]; then
  76. echo "**** Nothing to do, exiting build... **** "
  77. exit 1
  78. else
  79. echo "**** Changes found... incrementing build number version... ****"
  80. NB_RELEASE_NUMBER=$((NB_RELEASE_NUMBER + 1))
  81. VERSION_TAG=${IMAGE_VERSION}-nbxyz${NB_RELEASE_NUMBER}
  82. echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
  83. fi
  84. else
  85. echo "**** New version ${WEBAPP_RELEASE} found; old version was ${IMAGE_VERSION}. Generating new webapp release... ****"
  86. VERSION_TAG=${WEBAPP_RELEASE}-nbxyz1
  87. echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
  88. fi
  89. - name: Docker meta
  90. if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
  91. id: meta
  92. uses: docker/metadata-action@v5
  93. with:
  94. images: netbootxyz/netbootxyz
  95. labels: |
  96. maintainer=antonym
  97. org.opencontainers.image.created=${{ env.GITHUB_DATE }}
  98. org.opencontainers.image.authors=netboot.xyz
  99. org.opencontainers.image.url=https://github.com/netbootxyz/docker-netbootxyz/packages
  100. org.opencontainers.image.documentation=https://netboot.xyz
  101. org.opencontainers.image.source=https://github.com/netbootxyz/docker-netbootxyz
  102. org.opencontainers.image.version=${{ env.VERSION_TAG }}
  103. org.opencontainers.image.revision=${{ env.GITHUB_SHA }}
  104. org.opencontainers.image.vendor=netboot.xyz
  105. org.opencontainers.image.licenses=Apache-2.0
  106. org.opencontainers.image.ref.name=${{ env.GITHUB_SHA }}
  107. org.opencontainers.image.title=netbootxyz
  108. org.opencontainers.image.description=netboot.xyz official docker container - Your favorite operating systems in one place. A network-based bootable operating system installer based on iPXE.
  109. - name: Build and push image
  110. if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
  111. uses: docker/build-push-action@v6
  112. with:
  113. push: true
  114. context: .
  115. file: ./Dockerfile
  116. platforms: linux/amd64,linux/arm64
  117. build-args: |
  118. WEBAPP_VERSION=${{ env.WEBAPP_RELEASE }}
  119. VERSION=${{ env.VERSION_TAG }}
  120. BUILD_DATE=${{ env.GITHUB_DATE }}
  121. tags: |
  122. netbootxyz/netbootxyz:latest
  123. netbootxyz/netbootxyz:${{ github.sha }}
  124. netbootxyz/netbootxyz:${{ env.VERSION_TAG }}
  125. ghcr.io/netbootxyz/netbootxyz:latest
  126. ghcr.io/netbootxyz/netbootxyz:${{ github.sha }}
  127. ghcr.io/netbootxyz/netbootxyz:${{ env.VERSION_TAG }}
  128. labels: ${{ steps.meta.outputs.labels }}
  129. - name: Bump version and push tag
  130. if: steps.version_check.outcome == 'success' && steps.version_check.conclusion == 'success'
  131. id: tag_version
  132. uses: anothrNick/github-tag-action@1.70.0
  133. env:
  134. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  135. CUSTOM_TAG: ${{ env.VERSION_TAG }}
  136. WITH_V: true
  137. RELEASE_BRANCHES: master