summaryrefslogtreecommitdiff
path: root/.github/workflows/container.yml
blob: 4d1f59b07397a3a45548cf18e41be4b37b7c2a5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
---
name: Container

# yamllint disable-line rule:truthy
on:
  workflow_dispatch:
  workflow_run:
    workflows:
      - Integration
    types:
      - completed
    branches:
      - master

concurrency:
  group: ${{ github.workflow }}
  cancel-in-progress: false

permissions:
  contents: read
  # Organization GHCR
  packages: read

env:
  PYTHON_VERSION: "3.13"

jobs:
  build-base:
    if: |
      (github.repository_owner == 'searxng' && github.event.workflow_run.conclusion == 'success')
      || github.event_name == 'workflow_dispatch'
    name: Build base
    runs-on: ubuntu-24.04
    permissions:
      # Organization GHCR
      packages: write

    steps:
      - if: github.repository_owner == 'searxng'
        name: Checkout
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8  # v5.0.0
        with:
          persist-credentials: "false"

      - if: github.repository_owner == 'searxng'
        name: Get date
        id: date
        run: echo "date=$(date +'%Y%m%d')" >>$GITHUB_OUTPUT

      - if: github.repository_owner == 'searxng'
        name: Check cache apko
        id: cache-apko
        uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809  # v4.2.4
        with:
          # yamllint disable-line rule:line-length
          key: "apko-${{ steps.date.outputs.date }}-${{ hashFiles('./container/base.yml', './container/base-builder.yml') }}"
          path: "/tmp/.apko/"
          lookup-only: true

      - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
        name: Setup cache apko
        uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809  # v4.2.4
        with:
          # yamllint disable-line rule:line-length
          key: "apko-${{ steps.date.outputs.date }}-${{ hashFiles('./container/base.yml', './container/base-builder.yml') }}"
          restore-keys: "apko-${{ steps.date.outputs.date }}-"
          path: "/tmp/.apko/"

      - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
        name: Setup apko
        run: |
          eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
          brew install apko

      - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
        name: Login to GHCR
        uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1  # v3.5.0
        with:
          registry: "ghcr.io"
          username: "${{ github.repository_owner }}"
          password: "${{ secrets.GITHUB_TOKEN }}"

      - if: github.repository_owner == 'searxng' && steps.cache-apko.outputs.cache-hit != 'true'
        name: Build
        run: |
          eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

          apko publish ./container/base.yml ghcr.io/${{ github.repository_owner }}/base:searxng \
            --cache-dir=/tmp/.apko/ \
            --sbom=false \
            --vcs=false \
            --log-level=debug

          apko publish ./container/base-builder.yml ghcr.io/${{ github.repository_owner }}/base:searxng-builder \
            --cache-dir=/tmp/.apko/ \
            --sbom=false \
            --vcs=false \
            --log-level=debug

  build:
    if: github.repository_owner == 'searxng' || github.event_name == 'workflow_dispatch'
    name: Build (${{ matrix.arch }})
    runs-on: ${{ matrix.os }}
    needs: build-base
    strategy:
      fail-fast: false
      # Faster runners first to cache arch independent wheels
      max-parallel: 1
      matrix:
        include:
          - arch: amd64
            os: ubuntu-24.04
            emulation: false
          - arch: arm64
            os: ubuntu-24.04-arm
            emulation: false
          - arch: armv7
            os: ubuntu-24.04-arm
            emulation: true

    permissions:
      # Organization GHCR
      packages: write
      # Clean key cache step
      actions: write

    outputs:
      docker_tag: ${{ steps.build.outputs.docker_tag }}
      git_url: ${{ steps.build.outputs.git_url }}

    steps:
      - name: Setup Python
        uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065  # v5.6.0
        with:
          python-version: "${{ env.PYTHON_VERSION }}"

      - name: Checkout
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8  # v5.0.0
        with:
          persist-credentials: "false"

      - name: Setup cache Python
        uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809  # v4.2.4
        with:
          key: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-${{ hashFiles('./requirements*.txt') }}"
          restore-keys: "python-${{ env.PYTHON_VERSION }}-${{ runner.arch }}-"
          path: "./local/"

      - name: Restore cache container mounts
        id: cache-container-mounts
        uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809  # v4.2.4
        with:
          key: "container-mounts-${{ hashFiles('./container/*.dockerfile') }}"
          restore-keys: "container-mounts-"
          path: |
            /var/tmp/buildah-cache/
            /var/tmp/buildah-cache-*/

      # https://github.com/actions/cache/pull/1308
      - if: steps.cache-container-mounts.outputs.cache-hit == 'true'
        name: Clean key cache container mounts
        continue-on-error: true
        env:
          GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
        run: gh cache delete container-mounts-${{ hashFiles('./container/*.dockerfile') }}

      - if: ${{ matrix.emulation }}
        name: Setup QEMU
        uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392  # v3.6.0

      - name: Login to GHCR
        uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1  # v3.5.0
        with:
          registry: "ghcr.io"
          username: "${{ github.repository_owner }}"
          password: "${{ secrets.GITHUB_TOKEN }}"

      - name: Build
        id: build
        env:
          OVERRIDE_ARCH: "${{ matrix.arch }}"
        run: make podman.build

      - if: always()
        name: Save cache container mounts
        uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809  # v4.2.4
        with:
          key: "container-mounts-${{ hashFiles('./container/*.dockerfile') }}"
          path: |
            /var/tmp/buildah-cache/
            /var/tmp/buildah-cache-*/

  test:
    name: Test (${{ matrix.arch }})
    runs-on: ${{ matrix.os }}
    needs: build
    strategy:
      fail-fast: false
      matrix:
        include:
          - arch: amd64
            os: ubuntu-24.04
            emulation: false
          - arch: arm64
            os: ubuntu-24.04-arm
            emulation: false
          - arch: armv7
            os: ubuntu-24.04-arm
            emulation: true

    steps:
      - name: Checkout
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8  # v5.0.0
        with:
          persist-credentials: "false"

      - if: ${{ matrix.emulation }}
        name: Setup QEMU
        uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392  # v3.6.0

      - name: Login to GHCR
        uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1  # v3.5.0
        with:
          registry: "ghcr.io"
          username: "${{ github.repository_owner }}"
          password: "${{ secrets.GITHUB_TOKEN }}"

      - name: Test
        env:
          OVERRIDE_ARCH: "${{ matrix.arch }}"
          GIT_URL: "${{ needs.build.outputs.git_url }}"
        run: make container.test

  release:
    if: github.repository_owner == 'searxng' && github.ref_name == 'master'
    name: Release
    runs-on: ubuntu-24.04-arm
    needs:
      - build
      - test

    permissions:
      # Organization GHCR
      packages: write

    steps:
      - name: Checkout
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8  # v5.0.0
        with:
          persist-credentials: "false"

      - name: Login to GHCR
        uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1  # v3.5.0
        with:
          registry: "ghcr.io"
          username: "${{ github.repository_owner }}"
          password: "${{ secrets.GITHUB_TOKEN }}"

      - name: Login to Docker Hub
        uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1  # v3.5.0
        with:
          registry: "docker.io"
          username: "${{ secrets.DOCKERHUB_USERNAME }}"
          password: "${{ secrets.DOCKERHUB_TOKEN }}"

      - name: Release
        env:
          GIT_URL: "${{ needs.build.outputs.git_url }}"
          DOCKER_TAG: "${{ needs.build.outputs.docker_tag }}"
        run: make container.push