|
| 1 | +# Copy Images Action |
| 2 | + |
| 3 | +This composite GitHub Action copies a set of container images from a |
| 4 | +`testing registry` to a `production registry`, and signs them using `Cosign`. |
| 5 | +It requires as input Bake's build result metadata, which is the output provided |
| 6 | +by the [bake-action](https://github.com/docker/bake-action?tab=readme-ov-file#outputs). |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## How it works |
| 11 | + |
| 12 | +The action assumes a consistent naming convention between your testing and production registries. |
| 13 | + |
| 14 | +* A production image is named like `ghcr.io/org/image` |
| 15 | +* The corresponding testing image must include a suffix, e.g. `ghcr.io/org/image-testing` |
| 16 | + |
| 17 | +You can customize this suffix with the `inputs.test_registry_suffix` input. |
| 18 | + |
| 19 | +The action proceeds as follows: |
| 20 | + |
| 21 | +1. It retrieves all image references from `inputs.bake_build_metadata` |
| 22 | +2. It generates a list of destination images by stripping out the `test_registry_suffix` from each image |
| 23 | +3. Each image is copied to the destination registry using `Skopeo copy`. The digest of the image is preserved. |
| 24 | +4. Each production image is signed using `Cosign` |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Requirements |
| 29 | + |
| 30 | +This composite action requires the calling workflow’s `GITHUB_TOKEN` |
| 31 | +to have the following permissions: |
| 32 | + |
| 33 | +``` |
| 34 | +permissions: |
| 35 | + contents: read |
| 36 | + packages: write |
| 37 | + id-token: write # needed by Cosign for signing the images with GitHub OIDC Token |
| 38 | +``` |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Inputs |
| 43 | + |
| 44 | +| Name | Description | Required | Default | |
| 45 | +| ---------------------- | -------------------------------------------------- | --------- | -------------- | |
| 46 | +| `bake_build_metadata` | The JSON build result metadata generated by Bake | ✅ Yes | — | |
| 47 | +| `registry_user` | The user used to authenticate to the registry | ✅ Yes | — | |
| 48 | +| `registry_token` | The token used to authenticate to the registry | ✅ Yes | — | |
| 49 | +| `test_registry_suffix` | The suffix of the testing images | ❌ No | `-testing` | |
| 50 | + |
| 51 | +Note: |
| 52 | + The JSON build result metadata is provided by [bake-action](https://github.com/docker/bake-action) as an output, see |
| 53 | + [bake-action outputs](https://github.com/docker/bake-action?tab=readme-ov-file#outputs). |
| 54 | + Alternatively, if you are using `docker buildx bake` via commandline, you can write your build metadata to a file |
| 55 | + by using `--metadata-file`, and then provide the content of that file as `input.bake_build_metadata`. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Usage |
| 60 | + |
| 61 | +Example usage: |
| 62 | + |
| 63 | +``` |
| 64 | +jobs: |
| 65 | + copytoproduction: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + needs: |
| 68 | + - testbuild |
| 69 | + permissions: |
| 70 | + contents: read |
| 71 | + packages: write |
| 72 | + id-token: write |
| 73 | + steps: |
| 74 | + - name: Copy to production |
| 75 | + uses: cloudnative-pg/postgres-containers/.github/actions/copy-images@main |
| 76 | + with: |
| 77 | + bake_build_metadata: "${{ needs.testbuild.outputs.metadata }}" |
| 78 | + registry_user: ${{ github.actor }} |
| 79 | + registry_token: ${{ secrets.GITHUB_TOKEN }} |
| 80 | +``` |
| 81 | + |
| 82 | +Example workflow: |
| 83 | + |
| 84 | +``` |
| 85 | +jobs: |
| 86 | + # Building and pushing to a testing registry |
| 87 | + testbuild: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + outputs: |
| 90 | + metadata: ${{ steps.build.outputs.metadata }} |
| 91 | + steps: |
| 92 | + ... |
| 93 | + - uses: docker/bake-action@v6 |
| 94 | + id: build |
| 95 | + with: |
| 96 | + push: true |
| 97 | +
|
| 98 | + # Here's when you'd want to have one or |
| 99 | + # multiple jobs to scan and test your images |
| 100 | + scan-images: |
| 101 | + ... |
| 102 | +
|
| 103 | + # If the tests passed, we promote the images to the production repo |
| 104 | + copytoproduction: |
| 105 | + runs-on: ubuntu-latest |
| 106 | + needs: |
| 107 | + - testbuild |
| 108 | + - scan-images |
| 109 | + permissions: |
| 110 | + contents: read |
| 111 | + packages: write |
| 112 | + id-token: write |
| 113 | + steps: |
| 114 | + - name: Copy to production |
| 115 | + uses: cloudnative-pg/postgres-containers/.github/actions/copy-images@main |
| 116 | + with: |
| 117 | + bake_build_metadata: "${{ needs.testbuild.outputs.metadata }}" |
| 118 | + registry_user: ${{ github.actor }} |
| 119 | + registry_token: ${{ secrets.GITHUB_TOKEN }} |
| 120 | +``` |
0 commit comments