|
| 1 | +name: Build cso Image |
| 2 | +# yamllint disable rule:line-length |
| 3 | +on: # yamllint disable-line rule:truthy |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + # If the cache was cleaned we should re-build the cache with the latest commit |
| 8 | + workflow_run: |
| 9 | + workflows: |
| 10 | + - "CSO Image Cache Cleaner" |
| 11 | + branches: |
| 12 | + - main |
| 13 | + types: |
| 14 | + - completed |
| 15 | + workflow_dispatch: |
| 16 | +env: |
| 17 | + REGISTRY: ghcr.io/sovereigncloudstack |
| 18 | + metadata_flavor: latest=true |
| 19 | + metadata_tags: type=sha,prefix=sha-,format=short |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + # Required to generate OIDC tokens for `sigstore/cosign-installer` authentication |
| 24 | + id-token: write |
| 25 | +jobs: |
| 26 | + manager-image: |
| 27 | + name: Build and push manager image |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout code |
| 31 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + - uses: ./.github/actions/setup-go |
| 35 | + - name: Set up QEMU |
| 36 | + uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2 |
| 37 | + - name: Set up Docker Buildx |
| 38 | + uses: docker/setup-buildx-action@ecf95283f03858871ff00b787d79c419715afc34 # v2 |
| 39 | + |
| 40 | + - name: Generate metadata cso |
| 41 | + id: metacso |
| 42 | + uses: ./.github/actions/metadata |
| 43 | + env: |
| 44 | + IMAGE_NAME: cso-staging |
| 45 | + with: |
| 46 | + metadata_flavor: ${{ env.metadata_flavor }} |
| 47 | + metadata_tags: ${{ env.metadata_tags }} |
| 48 | + |
| 49 | + - name: Login to ghcr.io for CI |
| 50 | + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0 |
| 51 | + with: |
| 52 | + registry: ghcr.io |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Install Cosign |
| 57 | + uses: sigstore/cosign-installer@dd6b2e2b610a11fd73dd187a43d57cc1394e35f9 # v3.0.5 |
| 58 | + |
| 59 | + - name: Setup Env |
| 60 | + run: | |
| 61 | + DOCKER_BUILD_LDFLAGS="$(hack/version.sh)" |
| 62 | + echo 'DOCKER_BUILD_LDFLAGS<<EOF' >> $GITHUB_ENV |
| 63 | + echo $DOCKER_BUILD_LDFLAGS >> $GITHUB_ENV |
| 64 | + echo 'EOF' >> $GITHUB_ENV |
| 65 | +
|
| 66 | + # Load Golang cache build from GitHub |
| 67 | + - name: Load cso Golang cache build from GitHub |
| 68 | + uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 |
| 69 | + id: cache |
| 70 | + with: |
| 71 | + path: /tmp/.cache/cso |
| 72 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-cso-${{ github.sha }} |
| 73 | + restore-keys: | |
| 74 | + ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-cso- |
| 75 | + ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}- |
| 76 | + ${{ runner.os }}-go- |
| 77 | +
|
| 78 | + - name: Create cso cache directory |
| 79 | + if: ${{ steps.cache.outputs.cache-hit != 'true' }} |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + mkdir -p /tmp/.cache/cso |
| 83 | +
|
| 84 | + # Import GitHub's cache build to docker cache |
| 85 | + - name: Copy cso Golang cache to docker cache |
| 86 | + uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1 |
| 87 | + with: |
| 88 | + provenance: false |
| 89 | + context: /tmp/.cache/cso |
| 90 | + file: ./images/cache/Dockerfile |
| 91 | + push: false |
| 92 | + platforms: linux/amd64 |
| 93 | + target: import-cache |
| 94 | + |
| 95 | + - name: Build and push cso image |
| 96 | + uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4 |
| 97 | + id: docker_build_release_cso |
| 98 | + with: |
| 99 | + provenance: false |
| 100 | + context: . |
| 101 | + file: ./images/cso/Dockerfile |
| 102 | + push: true |
| 103 | + build-args: | |
| 104 | + LDFLAGS=${{ env.DOCKER_BUILD_LDFLAGS }} |
| 105 | + tags: ${{ steps.metacso.outputs.tags }} |
| 106 | + labels: ${{ steps.metacso.outputs.labels }} |
| 107 | + platforms: linux/amd64 |
| 108 | + |
| 109 | + - name: Sign Container Images |
| 110 | + env: |
| 111 | + COSIGN_EXPERIMENTAL: "true" |
| 112 | + run: | |
| 113 | + cosign sign --yes ghcr.io/sovereigncloudstack/cso-staging@${{ steps.docker_build_release_cso.outputs.digest }} |
| 114 | +
|
| 115 | + - name: Image Releases digests cso |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + mkdir -p image-digest/ |
| 119 | + echo "ghcr.io/sovereigncloudstack/cso-staging:{{ steps.metacso.outputs.tags }}@${{ steps.docker_build_release_cso.outputs.digest }}" >> image-digest/cso.txt |
| 120 | +
|
| 121 | + # Upload artifact digests |
| 122 | + - name: Upload artifact digests |
| 123 | + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 |
| 124 | + with: |
| 125 | + name: image-digest |
| 126 | + path: image-digest |
| 127 | + retention-days: 90 |
| 128 | + |
| 129 | + # Store docker's golang's cache build locally only on the main branch |
| 130 | + - name: Store cso Golang cache build locally |
| 131 | + if: ${{ steps.cache.outputs.cache-hit != 'true' }} |
| 132 | + uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1 |
| 133 | + with: |
| 134 | + provenance: false |
| 135 | + context: . |
| 136 | + file: ./images/cache/Dockerfile |
| 137 | + push: false |
| 138 | + outputs: type=local,dest=/tmp/docker-cache-cso |
| 139 | + platforms: linux/amd64 |
| 140 | + target: export-cache |
| 141 | + |
| 142 | + # Store docker's golang's cache build locally only on the main branch |
| 143 | + - name: Store cso Golang cache in GitHub cache path |
| 144 | + if: ${{ steps.cache.outputs.cache-hit != 'true' }} |
| 145 | + shell: bash |
| 146 | + run: | |
| 147 | + mkdir -p /tmp/.cache/cso/ |
| 148 | + if [ -f /tmp/docker-cache-cso/tmp/go-build-cache.tar.gz ]; then |
| 149 | + cp /tmp/docker-cache-cso/tmp/go-build-cache.tar.gz /tmp/.cache/cso/ |
| 150 | + fi |
| 151 | + if [ -f /tmp/docker-cache-cso/tmp/go-pkg-cache.tar.gz ]; then |
| 152 | + cp /tmp/docker-cache-cso/tmp/go-pkg-cache.tar.gz /tmp/.cache/cso/ |
| 153 | + fi |
| 154 | +
|
| 155 | + - name: Image Digests Output |
| 156 | + shell: bash |
| 157 | + run: | |
| 158 | + cd image-digest/ |
| 159 | + find -type f | sort | xargs -d '\n' cat |
0 commit comments