|
1 |
| -name: Bake images |
| 1 | +name: Bake Images |
2 | 2 |
|
3 | 3 | on:
|
4 |
| - schedule: |
5 |
| - - cron: 0 8 * * 1 |
6 | 4 | workflow_dispatch:
|
7 | 5 | inputs:
|
8 | 6 | environment:
|
|
11 | 9 | - testing
|
12 | 10 | - production
|
13 | 11 | default: testing
|
14 |
| - description: "Choose the environment to bake the images for" |
15 |
| - target: |
16 |
| - type: string |
17 |
| - default: "" |
18 |
| - description: "A comma separated list of targets to build. If empty, all targets will be built." |
| 12 | + description: "Choose the environment to bake the target for" |
19 | 13 |
|
20 | 14 | permissions: read-all
|
21 | 15 |
|
22 | 16 | jobs:
|
23 |
| - # Start by building images for testing. We want to run security checks before pushing those to production. |
24 |
| - testbuild: |
25 |
| - name: Build for testing |
26 |
| - runs-on: ubuntu-latest |
27 |
| - permissions: |
28 |
| - contents: read |
29 |
| - packages: write |
30 |
| - security-events: write |
31 |
| - # Required by the cosign step |
32 |
| - id-token: write |
| 17 | + get_versions: |
| 18 | + name: Get PostgreSQL versions |
| 19 | + runs-on: ubuntu-24.04 |
33 | 20 | outputs:
|
34 |
| - metadata: ${{ steps.build.outputs.metadata }} |
35 |
| - images: ${{ steps.images.outputs.images }} |
| 21 | + versions: ${{ steps.set_versions.outputs.versions }} |
36 | 22 | steps:
|
37 | 23 | - name: Checkout Code
|
38 | 24 | uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
39 | 25 |
|
40 |
| - - name: Log in to the GitHub Container registry |
41 |
| - uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3 |
42 |
| - with: |
43 |
| - registry: ghcr.io |
44 |
| - username: ${{ github.actor }} |
45 |
| - password: ${{ secrets.GITHUB_TOKEN }} |
46 |
| - |
47 |
| - # TODO: review this when GitHub has linux/arm64 runners available (Q1 2025?) |
48 |
| - # https://github.com/github/roadmap/issues/970 |
49 |
| - - name: Set up QEMU |
50 |
| - uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3 |
51 |
| - with: |
52 |
| - platforms: 'arm64' |
53 |
| - |
54 |
| - - name: Set up Docker Buildx |
55 |
| - uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3 |
| 26 | + - name: Get supported PostgreSQL versions |
| 27 | + id: set_versions |
| 28 | + run: | |
| 29 | + VERSIONS="$(sed -n '/postgreSQLVersions = \[/,/\]/ s/.*"\(.*\)\..*".*/\"\1\"/p' docker-bake.hcl | xargs echo | tr ' ' ',')" |
| 30 | + echo "PostgreSQL versions: [$VERSIONS]" |
| 31 | + echo "versions=[$VERSIONS]" >> "$GITHUB_OUTPUT" |
56 | 32 |
|
57 |
| - - name: Build and push |
58 |
| - uses: docker/bake-action@3acf805d94d93a86cce4ca44798a76464a75b88c # v6 |
59 |
| - id: build |
60 |
| - env: |
61 |
| - environment: testing |
62 |
| - registry: ghcr.io/${{ github.repository_owner }} |
63 |
| - revision: ${{ github.sha }} |
| 33 | + - name: List targets |
| 34 | + id: targets |
| 35 | + uses: docker/bake-action/subaction/matrix@v6 |
64 | 36 | with:
|
65 |
| - push: true |
66 |
| - targets: ${{ github.event.inputs.target }} |
| 37 | + target: "default" |
67 | 38 |
|
68 |
| - # Get a list of the images that were built and pushed. We only care about a single tag for each image. |
69 |
| - - name: Generated images |
70 |
| - id: images |
| 39 | + - name: Filter by versions |
| 40 | + id: filter_versions |
71 | 41 | run: |
|
72 |
| - echo "images=$(echo '${{ steps.build.outputs.metadata }}' | jq -c '[ .[]."image.name" | sub(",.*";"") ]')" >> "$GITHUB_OUTPUT" |
| 42 | + target=$(echo '${{ steps.targets.outputs.matrix }}' | jq -r '.[] | .[] | select(match("${{ matrix.pgversion }}"))' | xargs echo | sed 's/ /,/g') |
| 43 | + echo "Targets for PostgreSQL ${{ matrix.pgversion }}: $target" |
| 44 | + echo "filtered_targets=$target" >> "$GITHUB_OUTPUT" |
73 | 45 |
|
74 |
| - # Even if we're testing we sign the images, so we can push them to production later if that's required |
75 |
| - - name: Install cosign |
76 |
| - uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3 |
77 |
| - # See https://github.blog/security/supply-chain-security/safeguard-container-signing-capability-actions/ |
78 |
| - # and https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml for more details on |
79 |
| - # how to use cosign. |
80 |
| - - name: Sign images |
81 |
| - run: | |
82 |
| - echo '${{ steps.build.outputs.metadata }}' | \ |
83 |
| - jq '.[] | (."image.name" | sub(",.*";"" )) + "@" + ."containerimage.digest"' | \ |
84 |
| - xargs cosign sign --yes |
85 | 46 |
|
86 |
| - security: |
87 |
| - name: Security checks |
88 |
| - runs-on: ubuntu-latest |
89 |
| - needs: |
90 |
| - - testbuild |
| 47 | + Bake: |
| 48 | + name: Bake PostgreSQL |
| 49 | + strategy: |
| 50 | + fail-fast: |
| 51 | + matrix: |
| 52 | + target: ${{ fromJson(needs.get_versions.outputs.targets) }} |
| 53 | + uses: ./.github/workflows/bake_targets.yaml |
| 54 | + with: |
| 55 | + environment: ${{ github.event.inputs.environment }} |
| 56 | + target: ${{ matrix.target }} |
| 57 | + bake_versions: |
| 58 | + name: Bake PostgreSQL |
| 59 | + needs: get_versions |
| 60 | + runs-on: ubuntu-24.04 |
91 | 61 | strategy:
|
| 62 | + fail-fast: true |
92 | 63 | matrix:
|
93 |
| - image: ${{fromJson(needs.testbuild.outputs.images)}} |
| 64 | + pgversion: ${{ fromJson(needs.get_versions.outputs.versions) }} |
94 | 65 | steps:
|
95 | 66 | - name: Checkout Code
|
96 | 67 | uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
97 | 68 |
|
98 |
| - - name: Log in to the GitHub Container registry |
99 |
| - uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3 |
100 |
| - with: |
101 |
| - registry: ghcr.io |
102 |
| - username: ${{ github.actor }} |
103 |
| - password: ${{ secrets.GITHUB_TOKEN }} |
104 |
| - |
105 |
| - - name: Dockle |
106 |
| - uses: erzz/dockle-action@69369bc745ee29813f730231a821bcd4f71cd290 # v1 |
| 69 | + - name: List targets |
| 70 | + id: targets |
| 71 | + uses: docker/bake-action/subaction/matrix@v6 |
107 | 72 | with:
|
108 |
| - image: ${{ matrix.image }} |
109 |
| - exit-code: '1' |
| 73 | + target: "default" |
110 | 74 |
|
111 |
| - - name: Snyk |
112 |
| - uses: snyk/actions/docker@master |
113 |
| - continue-on-error: true |
114 |
| - env: |
115 |
| - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} |
116 |
| - with: |
117 |
| - image: "${{ matrix.image }}" |
118 |
| - args: --severity-threshold=high --file=Dockerfile |
119 |
| - |
120 |
| - - name: Upload result to GitHub Code Scanning |
121 |
| - uses: github/codeql-action/upload-sarif@2d92b76c45b91eb80fc44c74ce3fce0ee94e8f9d # v3 |
122 |
| - continue-on-error: true |
123 |
| - with: |
124 |
| - sarif_file: snyk.sarif |
125 |
| - |
126 |
| - # Use the metadata generated in the `testbuild` step to find all the images |
127 |
| - # that have been built. We copy them one by one to the production registry |
128 |
| - # using skopeo. Then we sign the production images too. |
129 |
| - copytoproduction: |
130 |
| - name: Copy images to production |
131 |
| - if: | |
132 |
| - github.ref == 'refs/heads/main' && |
133 |
| - ( github.event.inputs.environment == 'production' || github.event_name == 'schedule' ) |
134 |
| - runs-on: ubuntu-latest |
135 |
| - needs: |
136 |
| - - testbuild |
137 |
| - - security |
138 |
| - permissions: |
139 |
| - contents: read |
140 |
| - packages: write |
141 |
| - security-events: write |
142 |
| - # Required by the cosign step |
143 |
| - id-token: write |
144 |
| - steps: |
145 |
| - - name: Log in to the GitHub Container registry |
146 |
| - uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3 |
147 |
| - with: |
148 |
| - registry: ghcr.io |
149 |
| - username: ${{ github.actor }} |
150 |
| - password: ${{ secrets.GITHUB_TOKEN }} |
151 |
| - |
152 |
| - - name: Copy images |
| 75 | + - name: Extract targets per version |
| 76 | + id: extract_targets |
153 | 77 | run: |
|
154 |
| - images=$(echo '${{ needs.testbuild.outputs.metadata }}' | |
155 |
| - jq -r ' |
156 |
| - .[] as $items | |
157 |
| - ( |
158 |
| - $items."image.name" | |
159 |
| - split(",")[] + |
160 |
| - "@" + |
161 |
| - $items."containerimage.digest" |
162 |
| - ) |
163 |
| - ' |
164 |
| - ) |
165 |
| - for image in $images |
166 |
| - do |
167 |
| - testimageshaonly="${image%:*@*}@${image#*@}" |
168 |
| - testimagenosha="${image%@*}" |
169 |
| - prodimage="${testimagenosha/-testing/}" |
170 |
| - echo "Copying ${testimageshaonly} to ${prodimage}" |
171 |
| - docker run --quiet quay.io/skopeo/stable:v1.17.0-immutable copy -q -a \ |
172 |
| - --dest-creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} \ |
173 |
| - docker://${testimageshaonly} docker://${prodimage} |
174 |
| - done |
175 |
| -
|
176 |
| - - name: Install cosign |
177 |
| - uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3 |
| 78 | + target=$(echo '${{ steps.targets.outputs.matrix }}' | jq -r '.[] | .[] | select(match("${{ matrix.pgversion }}"))' | xargs echo | sed 's/ /,/g') |
| 79 | + echo "Targets for PostgreSQL ${{ matrix.pgversion }}: $target" |
| 80 | + echo "filtered_targets=$target" >> "$GITHUB_OUTPUT" |
178 | 81 |
|
179 |
| - - name: Sign images |
| 82 | + - name: Show version |
180 | 83 | run: |
|
181 |
| - images=$(echo '${{ needs.testbuild.outputs.metadata }}' | |
182 |
| - jq -r '.[] | |
183 |
| - ( |
184 |
| - ."image.name" | |
185 |
| - sub(",.*";"") | |
186 |
| - sub("-testing:[^@]+";"") |
187 |
| - ) + "@" + ."containerimage.digest" |
188 |
| - ' |
189 |
| - ) |
190 |
| - echo "Signing ${images}" |
191 |
| - cosign sign --yes ${images} |
| 84 | + echo "PostgreSQL version: ${{ matrix.pgversion }}" |
| 85 | + echo "Matrix Targets: ${{ steps.targets.outputs.matrix }}" |
| 86 | + echo "Filtered Targets: ${{ steps.extract_targets.outputs.filtered_targets }}" |
| 87 | +
|
| 88 | + - name: Build |
| 89 | + uses: ./.github/actions/bake |
| 90 | + with: |
| 91 | + environment: ${{ github.event.inputs.environment }} |
| 92 | + target: ${{ steps.extract_targets.outputs.filtered_targets }} |
0 commit comments