container.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ---
  2. name: Container
  3. # yamllint disable-line rule:truthy
  4. on:
  5. workflow_dispatch:
  6. workflow_run:
  7. workflows:
  8. - Integration
  9. types:
  10. - completed
  11. branches:
  12. - master
  13. concurrency:
  14. group: ${{ github.workflow }}
  15. cancel-in-progress: false
  16. permissions:
  17. contents: read
  18. # Organization GHCR
  19. packages: read
  20. env:
  21. PYTHON_VERSION: "3.13"
  22. jobs:
  23. build-base:
  24. if: |
  25. (github.repository_owner == 'searxng' && github.event.workflow_run.conclusion == 'success')
  26. || github.event_name == 'workflow_dispatch'
  27. name: Build base
  28. runs-on: ubuntu-24.04
  29. permissions:
  30. # Organization GHCR
  31. packages: write
  32. steps:
  33. - if: github.repository_owner == 'searxng'
  34. name: Checkout
  35. uses: actions/checkout@v4
  36. with:
  37. persist-credentials: "false"
  38. - if: github.repository_owner == 'searxng'
  39. name: Get date
  40. id: date
  41. run: echo "date=$(date +'%Y%m%d')" >>$GITHUB_OUTPUT
  42. - if: github.repository_owner == 'searxng'
  43. name: Check cache apko
  44. id: cache-apko
  45. uses: actions/cache/restore@v4
  46. with:
  47. # yamllint disable-line rule:line-length
  48. key: "apko-${{ steps.date.outputs.date }}-${{ hashFiles('./container/base.yml', './container/base-builder.yml') }}"
  49. path: "/tmp/.apko/"
  50. lookup-only: true
  51. - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
  52. name: Setup cache apko
  53. uses: actions/cache@v4
  54. with:
  55. # yamllint disable-line rule:line-length
  56. key: "apko-${{ steps.date.outputs.date }}-${{ hashFiles('./container/base.yml', './container/base-builder.yml') }}"
  57. restore-keys: "apko-${{ steps.date.outputs.date }}-"
  58. path: "/tmp/.apko/"
  59. - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
  60. name: Setup apko
  61. run: |
  62. eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
  63. brew install apko
  64. - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
  65. name: Login to GHCR
  66. uses: docker/login-action@v3
  67. with:
  68. registry: "ghcr.io"
  69. username: "${{ github.repository_owner }}"
  70. password: "${{ secrets.GITHUB_TOKEN }}"
  71. - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
  72. name: Build
  73. run: |
  74. eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
  75. apko publish ./container/base.yml ghcr.io/${{ github.repository_owner }}/base:searxng \
  76. --cache-dir=/tmp/.apko/ \
  77. --sbom=false \
  78. --vcs=false \
  79. --log-level=debug
  80. apko publish ./container/base-builder.yml ghcr.io/${{ github.repository_owner }}/base:searxng-builder \
  81. --cache-dir=/tmp/.apko/ \
  82. --sbom=false \
  83. --vcs=false \
  84. --log-level=debug
  85. build:
  86. if: github.repository_owner == 'searxng' || github.event_name == 'workflow_dispatch'
  87. name: Build (${{ matrix.arch }})
  88. runs-on: ${{ matrix.os }}
  89. needs: build-base
  90. strategy:
  91. fail-fast: false
  92. matrix:
  93. include:
  94. - arch: amd64
  95. os: ubuntu-24.04
  96. emulation: false
  97. - arch: arm64
  98. os: ubuntu-24.04-arm
  99. emulation: false
  100. - arch: armv7
  101. os: ubuntu-24.04-arm
  102. emulation: true
  103. permissions:
  104. # Organization GHCR
  105. packages: write
  106. outputs:
  107. version_string: ${{ steps.build.outputs.version_string }}
  108. version_tag: ${{ steps.build.outputs.version_tag }}
  109. docker_tag: ${{ steps.build.outputs.docker_tag }}
  110. git_url: ${{ steps.build.outputs.git_url }}
  111. git_branch: ${{ steps.build.outputs.git_branch }}
  112. steps:
  113. - name: Setup Python
  114. uses: actions/setup-python@v5
  115. with:
  116. python-version: "${{ env.PYTHON_VERSION }}"
  117. - name: Checkout
  118. uses: actions/checkout@v4
  119. with:
  120. persist-credentials: "false"
  121. - name: Setup cache Python
  122. uses: actions/cache@v4
  123. with:
  124. key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
  125. restore-keys: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-"
  126. path: "./local/"
  127. - name: Setup cache container mounts
  128. uses: actions/cache@v4
  129. with:
  130. # yamllint disable-line rule:line-length
  131. key: "container-mounts-${{ matrix.arch }}-${{ hashFiles('./container/Dockerfile', './container/legacy/Dockerfile') }}"
  132. restore-keys: "container-mounts-${{ matrix.arch }}-"
  133. path: |
  134. /var/tmp/buildah-cache/
  135. /var/tmp/buildah-cache-*/
  136. - if: ${{ matrix.emulation }}
  137. name: Setup QEMU
  138. uses: docker/setup-qemu-action@v3
  139. - name: Login to GHCR
  140. uses: docker/login-action@v3
  141. with:
  142. registry: "ghcr.io"
  143. username: "${{ github.repository_owner }}"
  144. password: "${{ secrets.GITHUB_TOKEN }}"
  145. - name: Build
  146. id: build
  147. env:
  148. OVERRIDE_ARCH: "${{ matrix.arch }}"
  149. run: make podman.build
  150. test:
  151. name: Test (${{ matrix.arch }})
  152. runs-on: ${{ matrix.os }}
  153. needs: build
  154. strategy:
  155. fail-fast: false
  156. matrix:
  157. include:
  158. - arch: amd64
  159. os: ubuntu-24.04
  160. emulation: false
  161. - arch: arm64
  162. os: ubuntu-24.04-arm
  163. emulation: false
  164. - arch: armv7
  165. os: ubuntu-24.04-arm
  166. emulation: true
  167. steps:
  168. - name: Checkout
  169. uses: actions/checkout@v4
  170. with:
  171. persist-credentials: "false"
  172. - if: ${{ matrix.emulation }}
  173. name: Setup QEMU
  174. uses: docker/setup-qemu-action@v3
  175. - name: Login to GHCR
  176. uses: docker/login-action@v3
  177. with:
  178. registry: "ghcr.io"
  179. username: "${{ github.repository_owner }}"
  180. password: "${{ secrets.GITHUB_TOKEN }}"
  181. - name: Test
  182. env:
  183. OVERRIDE_ARCH: "${{ matrix.arch }}"
  184. GIT_URL: "${{ needs.build.outputs.git_url }}"
  185. run: make container.test
  186. release:
  187. if: github.repository_owner == 'searxng' && github.ref_name == 'master'
  188. name: Release
  189. runs-on: ubuntu-24.04-arm
  190. needs:
  191. - build
  192. - test
  193. permissions:
  194. # Organization GHCR
  195. packages: write
  196. steps:
  197. - name: Checkout
  198. uses: actions/checkout@v4
  199. with:
  200. persist-credentials: "false"
  201. - name: Login to GHCR
  202. uses: docker/login-action@v3
  203. with:
  204. registry: "ghcr.io"
  205. username: "${{ github.repository_owner }}"
  206. password: "${{ secrets.GITHUB_TOKEN }}"
  207. - name: Login to Docker Hub
  208. uses: docker/login-action@v3
  209. with:
  210. registry: "docker.io"
  211. username: "${{ secrets.DOCKERHUB_USERNAME }}"
  212. password: "${{ secrets.DOCKERHUB_TOKEN }}"
  213. - name: Release
  214. env:
  215. GIT_URL: "${{ needs.build.outputs.git_url }}"
  216. DOCKER_TAG: "${{ needs.build.outputs.docker_tag }}"
  217. run: make container.push