Skip to content

Commit

Permalink
Fix: attach latest tag to images - DockerHub synchronize with GHCR (#…
Browse files Browse the repository at this point in the history
…1086)

* push image to multiple registry

Signed-off-by: Sarath Chandra Oruganti <39090092+SarathChandra24@users.noreply.github.com>
Signed-off-by: Sarath Chandra Oruganti <sarathchandraoruganti@gmail.com>

* github actions permissions

Signed-off-by: Sarath Chandra Oruganti <39090092+SarathChandra24@users.noreply.github.com>
Signed-off-by: Sarath Chandra Oruganti <sarathchandraoruganti@gmail.com>

* fluentd multi registry image push

Signed-off-by: Sarath Chandra Oruganti <sarathchandraoruganti@gmail.com>

* Limit build to PR changes for certain files

Signed-off-by: Sarath Chandra Oruganti <sarathchandraoruganti@gmail.com>

* Fix: Latest tag while pushing to docker hub

Signed-off-by: Sarath Chandra Oruganti <sarathchandraoruganti@gmail.com>

---------

Signed-off-by: Sarath Chandra Oruganti <39090092+SarathChandra24@users.noreply.github.com>
Signed-off-by: Sarath Chandra Oruganti <sarathchandraoruganti@gmail.com>
  • Loading branch information
sarathchandra24 committed Mar 10, 2024
1 parent 7f91cc0 commit 2f49673
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 12 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build-fb-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: docker metadata
- name: docker metadata for building
id: image-metadata
uses: docker/metadata-action@v5
with:
Expand Down Expand Up @@ -210,9 +210,10 @@ jobs:
with:
source_image: "${{ needs.build-prod-image-metadata.outputs.IMG_NAME }}:${{ needs.build-prod-image-metadata.outputs.version }}"
source_registry: ghcr.io
target_image: "${{ needs.build-prod-image-metadata.outputs.DOCKER_IMG_NAME }}:${{ needs.build-prod-image-metadata.outputs.version }}"
target_image: "${{ needs.build-prod-image-metadata.outputs.DOCKER_IMG_NAME }}"
target_registry: docker.io
platforms: "['linux/arm64', 'linux/amd64']"
is_latest: true
secrets:
source_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -229,9 +230,11 @@ jobs:
with:
source_image: "${{ needs.build-debug-image-metadata.outputs.IMG_NAME }}:${{ needs.build-debug-image-metadata.outputs.version }}"
source_registry: ghcr.io
target_image: "${{ needs.build-debug-image-metadata.outputs.DOCKER_IMG_NAME }}:${{ needs.build-debug-image-metadata.outputs.version }}"
target_image: "${{ needs.build-debug-image-metadata.outputs.DOCKER_IMG_NAME }}"
target_registry: docker.io
platforms: "['linux/arm64', 'linux/amd64']"
is_latest: false
suffix: "-debug"
secrets:
source_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/build-fd-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,13 @@ jobs:
- build-arm64-base-image-metadata
- build-arm64-base
with:
source_image: "${{ needs.build-arm64-base-image-metadata.outputs.IMG_NAME }}:${{ needs.build-arm64-base-image-metadata.outputs.version }}"
source_image: "${{ needs.build-arm64-base-image-metadata.outputs.IMG_NAME }}"
source_registry: ghcr.io
target_image: "${{ needs.build-arm64-base-image-metadata.outputs.DOCKER_IMG_NAME }}:${{ needs.build-arm64-base-image-metadata.outputs.version }}"
target_image: "${{ needs.build-arm64-base-image-metadata.outputs.DOCKER_IMG_NAME }}"
target_registry: docker.io
platforms: "['linux/arm64']"
is_latest: false
suffix: "-arm64-base"
secrets:
source_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -301,8 +303,6 @@ jobs:
uses: docker/metadata-action@v5
with:
images: "ghcr.io/${{ env.GITHUB_IMAGE }}"
flavor: |
latest=false
tags: |
raw,latest
type=ref,event=branch
Expand Down Expand Up @@ -347,11 +347,12 @@ jobs:
- prod-image-manifest
- scan-image
with:
source_image: "${{ needs.prod-image-manifest.outputs.IMG_NAME }}:${{ needs.prod-image-manifest.outputs.version }}"
source_image: "${{ needs.prod-image-manifest.outputs.IMG_NAME }}"
source_registry: ghcr.io
target_image: "${{ needs.prod-image-manifest.outputs.DOCKER_IMG_NAME }}:${{ needs.prod-image-manifest.outputs.version }}"
target_image: "${{ needs.prod-image-manifest.outputs.DOCKER_IMG_NAME }}"
target_registry: docker.io
platforms: "['linux/arm64', 'linux/amd64']"
is_latest: true
secrets:
source_registry_username: ${{ github.actor }}
source_registry_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-op-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
with:
source_image: "${{ needs.build-image-metadata.outputs.IMG_NAME }}:${{ needs.build-image-metadata.outputs.version }}"
source_registry: ghcr.io
target_image: "${{ needs.build-image-metadata.outputs.DOCKER_IMG_NAME }}:${{ needs.build-image-metadata.outputs.version }}"
target_image: "${{ needs.build-image-metadata.outputs.DOCKER_IMG_NAME }}"
target_registry: docker.io
platforms: "['linux/arm64', 'linux/amd64']"
secrets:
Expand Down
61 changes: 59 additions & 2 deletions .github/workflows/clone-docker-image-action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
required: false
type: string
default: '["linux/arm64", "linux/amd64"]'
suffix:
description: 'The suffix to append to the target image'
required: false
type: string
default: ''
is_latest:
description: 'Whether to tag the image as latest'
required: false
type: boolean
default: false
secrets:
source_registry_token:
description: The Github token or similar to authenticate with for the registry.
Expand Down Expand Up @@ -58,9 +68,56 @@
env:
SOURCE_IMAGE: ${{ inputs.source_registry }}/${{ inputs.source_image }}
shell: bash
create-tags:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.tags-converter.outputs.TAGS }}
steps:
- name: docker metadata for tags
id: tags-metadata
uses: docker/metadata-action@v5
with:
flavor: |
latest=${{ inputs.is_latest }}
suffix=${{ inputs.suffix }}
tags: |
raw,latest
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Convert tags to JSON array
id: tags-converter
run: |
# Get the line-separated list of tags
TAGS="${{ steps.tags-metadata.outputs.tags }}"
# Initialize an empty array
JSON_TAGS="["
# Loop through each tag and append to the JSON array
while read -r tag; do
JSON_TAGS+="\"$tag\","
done <<< "$TAGS"
# print the JSON array
echo "TAGS=$JSON_TAGS"
# Remove the trailing comma and close the array
JSON_TAGS="${JSON_TAGS%,}]"
# Output the JSON array
echo "TAGS=$JSON_TAGS" >> $GITHUB_OUTPUT
push-image:
needs: check-image-exists
needs:
- check-image-exists
- create-tags
strategy:
matrix:
image_tags: ${{fromJson(needs.create-tags.outputs.tags)}}
runs-on: ubuntu-latest
steps:
- name: Promote container images from ${{ inputs.source_registry }} to ${{ inputs.target_registry }}
Expand All @@ -77,6 +134,6 @@
"docker://$RELEASE_IMAGE"
env:
SOURCE_IMAGE: "${{ inputs.source_registry }}/${{ inputs.source_image }}"
RELEASE_IMAGE: "${{ inputs.target_registry }}/${{ inputs.target_image }}"
RELEASE_IMAGE: "${{ inputs.target_registry }}/${{ inputs.target_image }}:${{ matrix.image_tags }}"
RELEASE_CREDS: ${{ secrets.target_registry_username }}:${{ secrets.target_registry_token }}
SOURCE_CREDS: ${{ secrets.source_registry_username }}:${{ secrets.source_registry_token }}

0 comments on commit 2f49673

Please sign in to comment.