|
| 1 | +name: Build and Publish Cloud SQL Socket Factory |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - "automation/cloudsql-socket-factory/**" |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + paths: |
| 13 | + - "automation/cloudsql-socket-factory/**" |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + version: |
| 17 | + description: 'Cloud SQL Socket Factory version to build (e.g., 1.27.0)' |
| 18 | + required: false |
| 19 | + default: '' |
| 20 | + schedule: |
| 21 | + - cron: "0 0 * * 0" |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + packages: write |
| 26 | + id-token: write |
| 27 | + |
| 28 | +env: |
| 29 | + REGISTRY: ghcr.io |
| 30 | + IMAGE_NAME: ${{ github.repository }}/cloudsql-socket-factory |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + timeout-minutes: 60 |
| 36 | + outputs: |
| 37 | + digest: ${{ steps.build.outputs.digest }} |
| 38 | + version: ${{ steps.version.outputs.version }} |
| 39 | + steps: |
| 40 | + - name: Harden Runner |
| 41 | + uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 |
| 42 | + with: |
| 43 | + egress-policy: audit |
| 44 | + |
| 45 | + - name: Install Cosign |
| 46 | + uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2 |
| 47 | + |
| 48 | + - name: Checkout |
| 49 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 50 | + |
| 51 | + - name: Get version |
| 52 | + id: version |
| 53 | + run: | |
| 54 | + if [ -n "${{ github.event.inputs.version }}" ]; then |
| 55 | + VERSION="${{ github.event.inputs.version }}" |
| 56 | + else |
| 57 | + VERSION=$(cat automation/cloudsql-socket-factory/version.txt | tr -d '\n') |
| 58 | + fi |
| 59 | + if [ -z "$VERSION" ]; then |
| 60 | + echo "::error::Failed to determine version" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 64 | + echo "Building Cloud SQL Socket Factory version: ${VERSION}" |
| 65 | +
|
| 66 | + - name: Set up QEMU |
| 67 | + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 |
| 68 | + with: |
| 69 | + image: tonistiigi/binfmt:qemu-v8.1.5 |
| 70 | + platforms: all |
| 71 | + |
| 72 | + - name: Set up Docker Buildx |
| 73 | + id: buildx |
| 74 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 75 | + |
| 76 | + - name: Login to GHCR |
| 77 | + if: github.event_name != 'pull_request' |
| 78 | + uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 |
| 79 | + with: |
| 80 | + registry: ${{ env.REGISTRY }} |
| 81 | + username: ${{ github.repository_owner }} |
| 82 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + - name: Extract metadata |
| 85 | + id: meta |
| 86 | + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 |
| 87 | + with: |
| 88 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 89 | + tags: | |
| 90 | + type=raw,value=${{ steps.version.outputs.version }} |
| 91 | + type=raw,value=latest |
| 92 | +
|
| 93 | + - name: Build and push |
| 94 | + id: build |
| 95 | + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 |
| 96 | + with: |
| 97 | + builder: ${{ steps.buildx.outputs.name }} |
| 98 | + context: automation/cloudsql-socket-factory |
| 99 | + file: automation/cloudsql-socket-factory/Dockerfile |
| 100 | + build-args: | |
| 101 | + CLOUDSQL_SOCKET_FACTORY_VERSION=${{ steps.version.outputs.version }} |
| 102 | + platforms: linux/amd64,linux/arm64 |
| 103 | + push: ${{ github.event_name != 'pull_request' }} |
| 104 | + tags: ${{ steps.meta.outputs.tags }} |
| 105 | + labels: ${{ steps.meta.outputs.labels }} |
| 106 | + sbom: true |
| 107 | + provenance: true |
| 108 | + cache-from: type=gha,scope=cloudsql-socket-factory |
| 109 | + cache-to: type=gha,mode=max,scope=cloudsql-socket-factory |
| 110 | + |
| 111 | + - name: Sign the image with GitHub OIDC Token |
| 112 | + if: github.event_name != 'pull_request' |
| 113 | + env: |
| 114 | + DIGEST: ${{ steps.build.outputs.digest }} |
| 115 | + TAGS: ${{ steps.meta.outputs.tags }} |
| 116 | + run: | |
| 117 | + images="" |
| 118 | + for tag in ${TAGS}; do |
| 119 | + images+="${tag}@${DIGEST} " |
| 120 | + done |
| 121 | + if [[ -n $images ]]; then |
| 122 | + cosign sign --yes -a author=JanssenProject ${images} |
| 123 | + fi |
| 124 | +
|
| 125 | + - name: Image digest |
| 126 | + run: echo ${{ steps.build.outputs.digest }} |
0 commit comments