container.yml 6.8 KB

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