|
| 1 | +name: Build images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + build_type: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +env: |
| 11 | + BUILDKIT_CACHE_MAP: | |
| 12 | + { |
| 13 | + "var-cache-apt": "/var/cache/apt", |
| 14 | + "var-lib-apt": "/var/lib/apt", |
| 15 | + "ccache": "/ccache" |
| 16 | + } |
| 17 | +
|
| 18 | + DO_PUSH: y |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-images: |
| 22 | + runs-on: |
| 23 | + - ubuntu-24.04 |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v5 |
| 28 | + with: |
| 29 | + # for git describe |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Prepare repo |
| 33 | + run: | |
| 34 | + git config --global user.email "dummy@example.com" |
| 35 | + git config --global user.name "dummy user" |
| 36 | +
|
| 37 | + - name: Login to the registry |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ vars.REGISTRY_DOMAIN }} |
| 41 | + username: ${{ secrets.QUAY_USER_ID }} |
| 42 | + password: ${{ secrets.QUAY_TOKEN }} |
| 43 | + |
| 44 | + - name: Set up Docker Buildx |
| 45 | + uses: docker/setup-buildx-action@v3 |
| 46 | + with: |
| 47 | + driver: docker |
| 48 | + |
| 49 | + - name: Set up Buildkit Cache action |
| 50 | + run: | |
| 51 | + set -e |
| 52 | + git clone https://github.com/reproducible-containers/buildkit-cache-dance.git |
| 53 | + cd buildkit-cache-dance |
| 54 | + git checkout 5b81f4d29dc8397a7d341dba3aeecc7ec54d6361 |
| 55 | +
|
| 56 | + - name: Restore apt caches |
| 57 | + uses: actions/cache/restore@v3 |
| 58 | + with: |
| 59 | + path: | |
| 60 | + var-lib-apt |
| 61 | + var-cache-apt |
| 62 | + key: apt-${{ hashFiles('Dockerfile') }}-${{ hashFiles('vpp-builder.Dockerfile') }}-${{ hashFiles('vpp.spec') }} |
| 63 | + restore-keys: apt- |
| 64 | + |
| 65 | + - name: Restore ccache |
| 66 | + uses: actions/cache/restore@v3 |
| 67 | + with: |
| 68 | + path: ccache |
| 69 | + key: ccache-${{ inputs.build_type }}-${{ hashFiles('Dockerfile') }}-${{ hashFiles('vpp-builder.Dockerfile') }}-${{ hashFiles('vpp.spec') }} |
| 70 | + restore-keys: ccache-${{ inputs.build_type }}- |
| 71 | + |
| 72 | + - name: Inject caches into docker |
| 73 | + run: |
| 74 | + node ./buildkit-cache-dance/dist/index.js --cache-map "${BUILDKIT_CACHE_MAP}" |
| 75 | + |
| 76 | + - name: Build images |
| 77 | + id: build |
| 78 | + run: | |
| 79 | + BUILD_TYPE="${{ inputs.build_type }}" \ |
| 80 | + CI_BUILD=1 \ |
| 81 | + BUILDKIT_PROGRESS=plain \ |
| 82 | + DO_PUSH="${{ env.DO_PUSH }}" \ |
| 83 | + BASE_REPO="${{ vars.BASE_REPO }}" \ |
| 84 | + BUILDER_REPO="${{ vars.BUILDER_REPO }}" \ |
| 85 | + QUAY_IO_IMAGE_EXPIRES_AFTER="${{ vars.QUAY_IO_IMAGE_EXPIRES_AFTER }}" \ |
| 86 | + make image |
| 87 | +
|
| 88 | + - name: Retag base image |
| 89 | + if: github.ref_type == 'tag' |
| 90 | + run: | |
| 91 | + BUILD_TYPE="${{ inputs.build_type }}" BASE_REPO="${{ vars.BASE_REPO }}" build/retag-base-image.sh |
| 92 | +
|
| 93 | + - name: Extract caches from docker |
| 94 | + run: |
| 95 | + node ./buildkit-cache-dance/dist/index.js --extract --cache-map "${BUILDKIT_CACHE_MAP}" |
| 96 | + |
| 97 | + - name: Save apt caches |
| 98 | + if: steps.build.outputs.registry_cache_used == 'none' |
| 99 | + uses: actions/cache/save@v3 |
| 100 | + with: |
| 101 | + path: | |
| 102 | + var-lib-apt |
| 103 | + var-cache-apt |
| 104 | + key: apt-${{ hashFiles('Dockerfile') }}-${{ hashFiles('vpp-builder.Dockerfile') }}-${{ hashFiles('vpp.spec') }} |
| 105 | + |
| 106 | + - name: Save ccache |
| 107 | + if: steps.build.outputs.registry_cache_used != 'vpp-base' |
| 108 | + uses: actions/cache/save@v3 |
| 109 | + with: |
| 110 | + path: ccache |
| 111 | + key: ccache-${{ inputs.build_type }}-${{ hashFiles('Dockerfile') }}-${{ hashFiles('vpp-builder.Dockerfile') }}-${{ hashFiles('vpp.spec') }} |
| 112 | + |
0 commit comments