|
| 1 | +name: Republish Multiarch Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + docker_image: |
| 7 | + description: 'Multiarch Docker image with tag' |
| 8 | + required: true |
| 9 | + release_environment: |
| 10 | + description: 'Select release type: "staging" or "production"' |
| 11 | + type: choice |
| 12 | + default: 'staging' |
| 13 | + options: |
| 14 | + - staging |
| 15 | + - production |
| 16 | + upload_artifacts: |
| 17 | + description: 'Upload artifacts directly in this workflow' |
| 18 | + type: boolean |
| 19 | + default: true |
| 20 | + s3_upload_path: |
| 21 | + description: 'Upload artifacts to s3 path' |
| 22 | + type: string |
| 23 | + required: false |
| 24 | + workflow_call: |
| 25 | + inputs: |
| 26 | + docker_image: |
| 27 | + type: string |
| 28 | + required: true |
| 29 | + release_environment: |
| 30 | + type: string |
| 31 | + required: false |
| 32 | + default: 'staging' |
| 33 | + upload_artifacts: |
| 34 | + type: boolean |
| 35 | + required: false |
| 36 | + default: false |
| 37 | + s3_upload_path: |
| 38 | + type: string |
| 39 | + required: false |
| 40 | + outputs: |
| 41 | + image_archives_path: |
| 42 | + description: 'Path to the image archives directory' |
| 43 | + value: ${{ jobs.republish.outputs.image_archives_path }} |
| 44 | + |
| 45 | +env: |
| 46 | + IMAGE: ${{ github.event.inputs.docker_image || inputs.docker_image }} |
| 47 | + |
| 48 | +jobs: |
| 49 | + republish: |
| 50 | + runs-on: [self-hosted, altinity-on-demand, altinity-style-checker-aarch64] |
| 51 | + outputs: |
| 52 | + image_archives_path: ${{ steps.set_path.outputs.image_archives_path }} |
| 53 | + steps: |
| 54 | + - name: Checkout repository |
| 55 | + uses: actions/checkout@v3 |
| 56 | + |
| 57 | + - name: Docker Hub Login |
| 58 | + uses: docker/login-action@v2 |
| 59 | + with: |
| 60 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 61 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 62 | + |
| 63 | + - name: Set clickhouse-server version as new tag |
| 64 | + run: | |
| 65 | + # Determine "clickhouse-server" or "clickhouse-keeper" |
| 66 | + echo "Input IMAGE: $IMAGE" |
| 67 | + COMPONENT=$(echo "$IMAGE" | sed -E 's|.*/(clickhouse-[^:]+):.*|\1|') |
| 68 | + echo "Component determined: $COMPONENT" |
| 69 | + echo "COMPONENT=$COMPONENT" >> $GITHUB_ENV |
| 70 | +
|
| 71 | + # Pull the image |
| 72 | + echo "Pulling the image" |
| 73 | + docker pull $IMAGE |
| 74 | +
|
| 75 | + # Run the container to get the version |
| 76 | + echo "Attempting to run container..." |
| 77 | + CONTAINER_HASH=$(docker run -d --rm $IMAGE 2>&1) |
| 78 | + echo "Container hash: $CONTAINER_HASH" |
| 79 | +
|
| 80 | + # Get version and clean it up |
| 81 | + VERSION_OUTPUT=$(.github/retry.sh 30 10 docker exec $CONTAINER_HASH bash -c "$COMPONENT --version") |
| 82 | + echo "Raw version output: $VERSION_OUTPUT" |
| 83 | +
|
| 84 | + # Extract just the version number |
| 85 | + NEW_TAG=$(echo "$VERSION_OUTPUT" | sed -E 's/.*version ([0-9.]+[^ ]*).*/\1/') |
| 86 | + echo "Cleaned version: $NEW_TAG" |
| 87 | +
|
| 88 | + # Append "-prerelease" if necessary |
| 89 | + if [ "${{ github.event.inputs.release_type || inputs.release_type }}" = "staging" ]; then |
| 90 | + NEW_TAG="${NEW_TAG}-prerelease" |
| 91 | + fi |
| 92 | +
|
| 93 | + if [[ "$IMAGE" == *-alpine* ]]; then |
| 94 | + NEW_TAG="${NEW_TAG}-alpine" |
| 95 | + fi |
| 96 | + echo "New tag: $NEW_TAG" |
| 97 | +
|
| 98 | + # Export the new tag |
| 99 | + echo "new_tag=$NEW_TAG" >> $GITHUB_ENV |
| 100 | +
|
| 101 | + - name: Process multiarch manifest |
| 102 | + run: | |
| 103 | + echo "Re-tag multiarch image $IMAGE to altinity/$COMPONENT:$NEW_TAG" |
| 104 | + docker buildx imagetools create --tag "altinity/$COMPONENT:$NEW_TAG" "$IMAGE" |
| 105 | +
|
| 106 | + # Create directory for image archives |
| 107 | + mkdir -p image_archives |
| 108 | +
|
| 109 | + # Pull and save platform-specific images |
| 110 | + for PLATFORM in "linux/amd64" "linux/arm64"; do |
| 111 | + echo "Pulling and saving image for $PLATFORM..." |
| 112 | + # Pull the specific platform image |
| 113 | + docker pull --platform $PLATFORM "altinity/$COMPONENT:$NEW_TAG" |
| 114 | +
|
| 115 | + # Save the image to a tar file |
| 116 | + ARCH=$(echo $PLATFORM | cut -d'/' -f2) |
| 117 | + docker save "altinity/$COMPONENT:$NEW_TAG" -o "image_archives/${COMPONENT}-${NEW_TAG}-${ARCH}.tar" |
| 118 | + done |
| 119 | +
|
| 120 | + # Save manifest inspection |
| 121 | + docker buildx imagetools inspect "altinity/$COMPONENT:$NEW_TAG" > image_archives/manifest.txt |
| 122 | +
|
| 123 | + # Compress the archives |
| 124 | + cd image_archives |
| 125 | + for file in *.tar; do |
| 126 | + gzip "$file" |
| 127 | + done |
| 128 | + cd .. |
| 129 | +
|
| 130 | + - name: Set image archives path |
| 131 | + id: set_path |
| 132 | + run: | |
| 133 | + echo "image_archives_path=${{ github.workspace }}/image_archives" >> $GITHUB_OUTPUT |
| 134 | +
|
| 135 | + - name: Upload image archives |
| 136 | + if: ${{ github.event.inputs.upload_artifacts || inputs.upload_artifacts }} |
| 137 | + uses: actions/upload-artifact@v4 |
| 138 | + with: |
| 139 | + name: docker-images-backup |
| 140 | + path: image_archives/ |
| 141 | + retention-days: 90 |
| 142 | + |
| 143 | + - name: Install aws cli |
| 144 | + if: ${{ inputs.s3_upload_path != '' }} |
| 145 | + uses: unfor19/install-aws-cli-action@v1 |
| 146 | + with: |
| 147 | + version: 2 |
| 148 | + arch: arm64 |
| 149 | + |
| 150 | + - name: Upload to S3 |
| 151 | + if: ${{ inputs.s3_upload_path != '' }} |
| 152 | + run: | |
| 153 | + aws s3 sync image_archives/ "${{ inputs.s3_upload_path }}" |
| 154 | +
|
0 commit comments