alpine.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ---
  2. name: alpine docker image
  3. on:
  4. schedule:
  5. - cron: '41 3 * * *'
  6. push:
  7. tags:
  8. - '[0-9]+.[0-9]+.[0-9]+'
  9. # Allows you to run this workflow manually from the Actions tab
  10. workflow_dispatch:
  11. env:
  12. IMAGE_NAME: kamailio-ci
  13. SOURCE_BRANCH: ${{ github.ref_name }}
  14. DOCKER_REPO: ghcr.io/kamailio/kamailio-ci
  15. jobs:
  16. # is required nightly build?
  17. # More info at https://stackoverflow.com/questions/63014786/how-to-schedule-a-github-actions-nightly-build-but-run-it-only-when-there-where
  18. check:
  19. runs-on: ubuntu-latest
  20. permissions:
  21. contents: read
  22. steps:
  23. - uses: octokit/[email protected]
  24. id: check_last_run
  25. with:
  26. route: GET /repos/{owner}/{repo}/actions/workflows/alpine.yml/runs?per_page=1&status=success
  27. owner: ${{ github.repository_owner }}
  28. repo: kamailio
  29. env:
  30. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  31. - run: |
  32. echo Last daily build: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].head_sha }}
  33. echo commit_message: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].head_commit.message }}
  34. echo display_title: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].display_title }}
  35. echo conclusion: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].conclusion }}
  36. outputs:
  37. last_sha: ${{ fromJson(steps.check_last_run.outputs.data).workflow_runs[0].head_sha }}
  38. x86_64:
  39. needs: [check]
  40. if: needs.check.outputs.last_sha != github.sha
  41. runs-on: ubuntu-latest
  42. permissions:
  43. contents: read
  44. packages: write
  45. steps:
  46. - uses: actions/checkout@v4
  47. - name: print latest_commit
  48. run: echo ${{ github.sha }}
  49. - name: Login to GitHub Container Registry
  50. uses: docker/login-action@v3
  51. with:
  52. registry: ghcr.io
  53. username: ${{ github.repository_owner }}
  54. password: ${{ secrets.GITHUB_TOKEN }}
  55. - name: Compile Kamailio source
  56. run: |
  57. git submodule init
  58. git submodule update
  59. cd pkg/docker/alpine
  60. ./hooks/pre_build || true
  61. - name: Docker meta
  62. id: meta
  63. uses: docker/metadata-action@v5
  64. with:
  65. # list of Docker images to use as base name for tags
  66. images: |
  67. ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
  68. # generate Docker tags based on the following events/attributes
  69. tags: |
  70. type=pep440,pattern={{version}}
  71. type=pep440,pattern={{major}}.{{minor}}
  72. type=pep440,pattern={{major}}
  73. type=ref,event=branch
  74. flavor: |
  75. suffix=
  76. latest=auto
  77. - name: Docker meta "-alpine"
  78. id: meta-alpine
  79. uses: docker/metadata-action@v5
  80. with:
  81. # list of Docker images to use as base name for tags
  82. images: |
  83. ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
  84. # generate Docker tags based on the following events/attributes
  85. tags: |
  86. type=pep440,pattern={{version}}
  87. type=pep440,pattern={{major}}.{{minor}}
  88. type=pep440,pattern={{major}}
  89. type=ref,event=branch
  90. flavor: |
  91. suffix=-alpine
  92. latest=false
  93. - name: Docker meta "-debug"
  94. id: meta-debug
  95. uses: docker/metadata-action@v5
  96. with:
  97. # list of Docker images to use as base name for tags
  98. images: |
  99. ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
  100. # generate Docker tags based on the following events/attributes
  101. tags: |
  102. type=pep440,pattern={{version}}
  103. type=pep440,pattern={{major}}.{{minor}}
  104. type=pep440,pattern={{major}}
  105. type=ref,event=branch
  106. flavor: |
  107. suffix=-debug
  108. latest=false
  109. - name: temporal workarround for "-alpine" and "-debug" builds
  110. run: |
  111. sudo chown -R ${USER}:${USER} ${{ github.workspace }}/pkg/docker/alpine
  112. cd pkg/docker/alpine
  113. mkdir repackage
  114. tar xz --directory=repackage -f kamailio_min-without_os_files.tar.gz
  115. rm -f kamailio_min-without_os_files.tar.gz
  116. tar cz --directory=repackage -f kamailio_min-without_os_files.tar.gz $(ls -A repackage)
  117. - name: Prepare local repo for "-debug" build
  118. run: |
  119. docker network create kamailio-build
  120. docker run \
  121. --detach \
  122. --network kamailio-build \
  123. --name local-repo \
  124. --hostname local-repo \
  125. --rm=true \
  126. --volume=${{ github.workspace }}/pkg/docker/alpine/apk_files:/usr/share/nginx/html:ro \
  127. nginx
  128. LOCAL_REPO_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' local-repo)
  129. sed -i -e "s/local-repo/${LOCAL_REPO_IP}/" pkg/docker/alpine/Dockerfile.debug
  130. - name: Create custom builder for "-debug" build
  131. id: local-repo
  132. uses: docker/setup-buildx-action@v3
  133. with:
  134. driver-opts: |
  135. network=kamailio-build
  136. - name: Build and push "-debug" build
  137. uses: docker/build-push-action@v6
  138. with:
  139. context: pkg/docker/alpine
  140. file: pkg/docker/alpine/Dockerfile.debug
  141. builder: ${{ steps.local-repo.outputs.name }}
  142. push: ${{ github.event_name != 'pull_request' }}
  143. tags: ${{ steps.meta-debug.outputs.tags }}
  144. labels: ${{ steps.meta-debug.outputs.labels }}
  145. - name: Cleanup after "-debug" build
  146. run: |
  147. docker buildx stop ${{ steps.local-repo.outputs.name }}
  148. docker buildx rm ${{ steps.local-repo.outputs.name }}
  149. docker stop local-repo
  150. docker network rm kamailio-build
  151. - name: Build and push "-alpine" build
  152. uses: docker/build-push-action@v6
  153. with:
  154. context: pkg/docker/alpine
  155. file: pkg/docker/alpine/Dockerfile.alpine
  156. push: ${{ github.event_name != 'pull_request' }}
  157. tags: ${{ steps.meta-alpine.outputs.tags }}
  158. labels: ${{ steps.meta-alpine.outputs.labels }}
  159. - name: Build and push
  160. uses: docker/build-push-action@v6
  161. with:
  162. context: pkg/docker/alpine
  163. file: pkg/docker/alpine/Dockerfile
  164. push: ${{ github.event_name != 'pull_request' }}
  165. tags: ${{ steps.meta.outputs.tags }}
  166. labels: ${{ steps.meta.outputs.labels }}