Skip to content

Commit

Permalink
ci: copy images from GHCR to ECR Public (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 authored Sep 27, 2024
1 parent bcbd1ca commit c96b013
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
name: push
name: Push and Copy Images

on:
push:
branches:
- master
workflow_dispatch:

env:
TEST_IMAGE: 'ghcr.io/${{ github.repository_owner }}/trivy-test-images' # used in Makefile
GH_USER: "aqua-bot"

jobs:
changed_files:
push_images:
runs-on: ubuntu-latest
name: Push changed images
name: Push images to GHCR
steps:
- uses: actions/checkout@v3

- name: Login to ghcr.io registry
uses: docker/login-action@v2
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.GH_USER }}
Expand Down Expand Up @@ -54,4 +55,37 @@ jobs:

- name: Copy images
if: steps.changed-files-yaml.outputs.crane-images_any_changed == 'true'
run: make copy-images
run: make copy-images

copy_to_ecr:
runs-on: ubuntu-latest
name: Copy images from GHCR to ECR Public
needs: push_images
env:
ECR_REPO: 'public.ecr.aws/${{ github.repository_owner }}/trivy-test-images'
steps:
- name: Install crane
run: |
curl -LO https://github.com/google/go-containerregistry/releases/latest/download/go-containerregistry_Linux_x86_64.tar.gz
tar xzvf go-containerregistry_Linux_x86_64.tar.gz crane
sudo mv crane /usr/local/bin/
- name: Login to ECR Public
uses: docker/login-action@v3
with:
registry: public.ecr.aws
username: ${{ secrets.ECR_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_SECRET_ACCESS_KEY }}

- name: Copy images to ECR Public
env:
GHCR_REPO: ${{ env.TEST_IMAGE }}
ECR_REPO: ${{ env.ECR_REPO }}
run: |
# Get list of tags from GHCR
TAGS=$(crane ls $$GHCR_REPO)
for TAG in $TAGS; do
echo "Copying tag $TAG from GHCR to ECR Public"
crane copy $GHCR_REPO:$TAG $ECR_REPO:$TAG
done

0 comments on commit c96b013

Please sign in to comment.