|
| 1 | +name: OCI Artifact Collector |
| 2 | +description: Collect OCI artifacts and push multi-arch manifests to registries using regctl |
| 3 | + |
| 4 | +inputs: |
| 5 | + artifacts-pattern: |
| 6 | + description: Pattern to match artifact names (e.g., "oci-*") |
| 7 | + required: false |
| 8 | + default: oci-* |
| 9 | + artifacts-path: |
| 10 | + description: Path to download artifacts to |
| 11 | + required: false |
| 12 | + default: ./oci-images |
| 13 | + oci-tmp-path: |
| 14 | + description: Path to download artifacts to |
| 15 | + required: false |
| 16 | + default: /tmp/oci |
| 17 | + manifest-config: |
| 18 | + description: | |
| 19 | + JSON configuration for manifests to create. Format: |
| 20 | + { |
| 21 | + "manifests": [ |
| 22 | + { |
| 23 | + "name": "my-image", |
| 24 | + "tag": "latest", |
| 25 | + "registry": "docker.io/myorg", |
| 26 | + "architectures": ["amd64", "arm64"], |
| 27 | + "artifact-pattern": "{arch}/myimage-{arch}.tar", |
| 28 | + } |
| 29 | + ] |
| 30 | + } |
| 31 | + required: true |
| 32 | + dry-run: |
| 33 | + description: Run without actually pushing images |
| 34 | + required: false |
| 35 | + default: false |
| 36 | + dockerhub-username: |
| 37 | + description: Docker Hub username |
| 38 | + required: false |
| 39 | + default: |
| 40 | + dockerhub-password: |
| 41 | + description: Docker Hub token/password |
| 42 | + required: false |
| 43 | + type: string |
| 44 | + gcr-key: |
| 45 | + description: GCR service account JSON |
| 46 | + required: false |
| 47 | + type: string |
| 48 | + |
| 49 | + |
| 50 | +runs: |
| 51 | + using: composite |
| 52 | + steps: |
| 53 | + - name: Download OCI artifacts |
| 54 | + uses: actions/download-artifact@v4 |
| 55 | + with: |
| 56 | + pattern: ${{ inputs.artifacts-pattern }} |
| 57 | + path: ${{ inputs.artifacts-path }} |
| 58 | + |
| 59 | + - name: Extract OCI archives |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + echo "::group::Finding tar files" |
| 63 | + find ${{ inputs.artifacts-path }} -name "*.tar" -type f | sort |
| 64 | + echo "::endgroup::" |
| 65 | + echo "::group::Extracting OCI archives" |
| 66 | + mkdir -p ${{ inputs.oci-tmp-path }} |
| 67 | + for tar_file in $(find ${{ inputs.artifacts-path }} -name "*.tar" -type f); do |
| 68 | + echo "Processing: ${tar_file}" |
| 69 | + dir_name=$(basename "${tar_file}" .tar) |
| 70 | + extract_dir="${{ inputs.oci-tmp-path }}/${dir_name}" |
| 71 | + echo " Basename: ${dir_name}" |
| 72 | + echo " Extract to: ${extract_dir}" |
| 73 | + mkdir -p "${extract_dir}" |
| 74 | + tar -xf "${tar_file}" -C "${extract_dir}" |
| 75 | + echo " ✓ Extracted successfully" |
| 76 | + done |
| 77 | + echo "::endgroup::" |
| 78 | +
|
| 79 | + echo "::group::Extracted OCI directories" |
| 80 | + ls -la ${{ inputs.oci-tmp-path }} |
| 81 | + echo "::endgroup::" |
| 82 | + - name: Buildah operations |
| 83 | + uses: envoyproxy/toolshed/gh-actions/jq@actions-v0.3.23 |
| 84 | + id: operations |
| 85 | + with: |
| 86 | + input: | |
| 87 | + config: ${{ inputs.manifest-config }} |
| 88 | + input-format: yaml |
| 89 | + filter: | |
| 90 | + [.config.manifests[] |
| 91 | + | . as $manifest |
| 92 | + | .registry as $registry |
| 93 | + | .name as $name |
| 94 | + | .tag as $tag |
| 95 | + | "\(.registry)/\(.name):\(.tag)" as $manifest_tag |
| 96 | + | ."artifact-pattern" as $pattern |
| 97 | + | (.["additional-tags"] // []) as $additional_tags |
| 98 | + | ("manifest-\($manifest_tag | gsub("[:/]"; "_"))") as $manifest_name |
| 99 | + | ([.architectures[] as $arch |
| 100 | + | ($pattern | gsub("{arch}"; $arch) | gsub("{name}"; $name) | gsub("{tag}"; $tag)) as $tar_file |
| 101 | + | ($tar_file | gsub(".*/"; "") | gsub("\\.tar$"; "")) as $basename |
| 102 | + | "${{ inputs.oci-tmp-path }}/\($basename)" |
| 103 | + ]) as $sources |
| 104 | + | {command: "manifest", |
| 105 | + args: ["create", $manifest_name], |
| 106 | + metadata: { tag: $manifest_tag }}, |
| 107 | + ($sources[] |
| 108 | + | {command: "manifest", |
| 109 | + args: ["add", $manifest_name, "oci:\(.)"], |
| 110 | + metadata: {tag: $manifest_tag}}), |
| 111 | + {command: "manifest", |
| 112 | + args: ["push", "--all", $manifest_name, "docker://\($manifest_tag)"], |
| 113 | + metadata: {tag: $manifest_tag}}] |
| 114 | + - name: Execute buildah operations |
| 115 | + uses: envoyproxy/toolshed/gh-actions/buildah@0a35e73988ced481f7b786b9a404f4d4cbf3a2ea |
| 116 | + id: buildah |
| 117 | + with: |
| 118 | + operations: ${{ steps.operations.outputs.value }} |
| 119 | + dry-run: ${{ inputs.dry-run }} |
| 120 | + dockerhub-username: ${{ inputs.dry-run != true && inputs.dockerhub-username || '' }} |
| 121 | + dockerhub-password: ${{ inputs.dry-run != true && inputs.dockerhub-password || '' }} |
| 122 | + gcr-key: ${{ inputs.dry-run != true && inputs.gcr-key || '' }} |
0 commit comments