Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyasdf committed Jul 5, 2023
1 parent 9e63a6a commit 696d80a
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/autotest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: autotest

on:
push: {}
pull_request: {}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true

jobs:
test_sync_job:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run docker registry
run: docker run -d -p 5000:5000 --restart=always --name registry registry:2
- uses: ./
with:
auth_file: ./.github/workflows/test-auth.yaml
images_file: ./.github/workflows//test-images.yaml
env:
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
36 changes: 36 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: check

on:
push: {}
pull_request: {}

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ludeeus/[email protected]
env:
SHELLCHECK_OPTS: -e SC2236,SC2162,SC2268
with:
ignore: tests

super-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint Code Base
uses: github/[email protected]
env:
VALIDATE_ALL_CODEBASE: true
VALIDATE_MARKDOWN: true
LINTER_RULES_PATH: .github
MARKDOWN_CONFIG_FILE: .markdown-lint.yml
VALIDATE_MD: true
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER_REGEX_EXCLUDE: .github/.*
2 changes: 2 additions & 0 deletions .github/workflows/test-auth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost:5000:
insecure: true
1 change: 1 addition & 0 deletions .github/workflows/test-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quay.io/operator-framework/olm:v0.18.3: "localhost:5000/image-syncer-test/olm"
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Image Sync Action

- Use [image-syncer](https://github.com/AliyunContainerService/image-syncer) to Sync images between docker registries.

## Examples

#### Typical Use Case

```yaml
- name: Checkout
uses: actions/checkout@v3
- uses: hhyasdf/image-sync-action@v1
with:
auth_file: ./test-auth.yaml # The auth information file of registries, optional.
images_file: ./test-images.yaml # The images need to sync, always needed.
version: latest # The version of image-syncer, use the latest version if not specified.
proc: 6 # The max number of goroutines to sync images, default value is 5.
env:
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }} # For safty consideration, passing registry password by github action secrets is needed.
```
To use the `TEST_PASSWORD` environment variable as a paasword, the auth file needs to include something like:

```yaml
registry.cn-beijing.aliyuncs.com:
username: test
password: ${TEST_PASSWORD}
```

For more information of how to create an auth file or images file, refer to the [image-syncer configure files](https://github.com/AliyunContainerService/image-syncer/blob/master/README.md#configure-files).
43 changes: 43 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "Image Sync Action"
description: "Automatically sync conatiner images between registries through Github Action"
inputs:
version:
description: "The version of image-syncer"
default: "latest"
required: false
auth_file:
description: "The --auth parameter of image-syncer, auth file path. This flag need to be pair used with --images"
required: false
images_file:
description: "The --images parameter of image-syncer, images file path. This flag need to be pair used with --auth"
default: "./images.yaml"
required: true
default_namespace:
description: "The --namespace parameter of image-syncer, default destination namespace when destination namespace is not given in the config file, can also be set with DEFAULT_NAMESPACE environment value"
required: false
default_registry:
description: "The --registry parameter of image-syncer, default destination registry url when destination registry is not given in the config file, can also be set with DEFAULT_REGISTRY environment value"
required: false
arch:
description: "The --arch parameter of image-syncer, architecture list to filter source tags, not works for OCI media"
required: false
os:
description: "The --os parameter of image-syncer, os list to filter source tags, not works for docker v2 schema1 and OCI media"
required: false
proc:
description: "The --proc parameter of image-syncer, numbers of working goroutines (default 5)"
default: 5
required: false
retries:
description: "The --retries parameter of image-syncer, times to retry failed task (default 2)"
default: 2
required: false
runs:
using: "composite"
steps:
- id: download
run: ${{ github.action_path }}/download.sh ${{ inputs.version }}
shell: bash
- id: excute
run: ./image-syncer --auth=${{ inputs.auth_file }} --images=${{ inputs.images_file }} --namespace=${{ inputs.default_namespace }} --registry=${{ inputs.default_registry }} --arch=${{ inputs.arch }} --os=${{ inputs.os }} --proc=${{ inputs.proc }} --retries=${{ inputs.retries }}
shell: bash
11 changes: 11 additions & 0 deletions download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

target_tag=$(curl --silent "https://api.github.com/repos/AliyunContainerService/image-syncer/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

if [ "${1}" != "latest" ]; then
target_tag=${1}
fi

wget https://github.com/AliyunContainerService/image-syncer/releases/download/"${target_tag}"/image-syncer-"${target_tag}"-linux-amd64.tar.gz

tar -xvf image-syncer-"${target_tag}"-linux-amd64.tar.gz

0 comments on commit 696d80a

Please sign in to comment.