Skip to content

Image Sync

Image Sync #10269

name: Image Sync
on:
schedule:
- cron: '*/30 * * * *'
jobs:
sync-images:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Docker
uses: docker/setup-buildx-action@v1
- uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
- name: Fetch repos, rebuild for k8s, push to internal artifact registry
run: |
gcloud auth configure-docker europe-west2-docker.pkg.dev -q
while IFS= read -r image_path; do
latest_tag=$(curl -s "https://registry.hub.docker.com/v2/repositories/${image_path}/tags/" | jq -r '.results[].name | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))' | sort -V | tail -n 1)
if [ -n "$latest_tag" ]; then
# Check if the image version already exists in GCP Container Registry
if ! gcloud container images list-tags europe-west2-docker.pkg.dev/prj-polygonlabs-devtools-dev/container/${image_path} --filter="tags=${latest_tag}" --format="value(tags)" | grep -q "${latest_tag}"; then
docker pull "${image_path}:${latest_tag}"
docker tag "${image_path}:${latest_tag}" "europe-west2-docker.pkg.dev/prj-polygonlabs-devtools-dev/container/${image_path}:${latest_tag}"
sudo -u $USER docker push "europe-west2-docker.pkg.dev/prj-polygonlabs-devtools-dev/container/${image_path}:${latest_tag}"
# also tag image as 'latest' for internal tracking
sudo -u $USER docker push "europe-west2-docker.pkg.dev/prj-polygonlabs-devtools-dev/container/${image_path}:latest"
else
echo "Image version already exists for ${image_path}:${latest_tag} in GCR. Skipping upload."
fi
fi
done < .github/workflows/repo-list.txt.sample