Skip to content

Commit

Permalink
Merge pull request #196 from Desiki-high/feat/action-webhook
Browse files Browse the repository at this point in the history
action: add webhook test
  • Loading branch information
imeoer authored Oct 10, 2023
2 parents c0f5dfc + b86f512 commit 5c24e20
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/webhook-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Webhook Test

on:
push:
branches: [ '*' ]
paths-ignore: [ '**.md']
pull_request:
branches: [ main ]
paths-ignore: [ '**.md']

env:
GO_VERSION: 1.18
HARBOR_VERSION: 2.8.4
NYDUS_VERSION: 2.2.3

jobs:
webhook_test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install Golang
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Build Accel
run: |
make
- name: Install Harbor
run: |
wget https://github.com/goharbor/harbor/releases/download/v${{ env.HARBOR_VERSION }}/harbor-offline-installer-v${{ env.HARBOR_VERSION }}.tgz
tar xzvf harbor-offline-installer-v${{ env.HARBOR_VERSION }}.tgz
cp ./script/integration/harbor.yml harbor/harbor.yml
cd harbor
sudo ./install.sh
- name: Webhook Test
run: |
# Download nydus components
wget https://github.com/dragonflyoss/image-service/releases/download/v${{ env.NYDUS_VERSION }}/nydus-static-v${{ env.NYDUS_VERSION }}-linux-amd64.tgz
sudo tar xzvf nydus-static-v${{ env.NYDUS_VERSION }}-linux-amd64.tgz --wildcards --strip-components=1 -C /usr/bin/ nydus-static/*
sudo ./script/integration/webhook/test.sh
30 changes: 30 additions & 0 deletions script/integration/webhook/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
server:
name: API
host: 0.0.0.0
port: 2077

metric:
enabled: true

provider:
source:
0.0.0.0:
auth: YWRtaW46SGFyYm9yMTIzNDU=
insecure: true
webhook:
auth_header: acceleration-service
work_dir: /tmp
gcpolicy:
threshold: 10MB

converter:
worker: 5
harbor_annotation: true
driver:
type: nydus
config:
work_dir: /tmp
with_referrer: true

rules:
- tag_suffix: -nydus
77 changes: 77 additions & 0 deletions script/integration/webhook/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

set -euo pipefail

# Start acceld service
sudo nohup ./acceld --config ./script/integration/webhook/config.yaml &> acceld.log &
sleep 1

IP=$(ip addr show eth0 | grep -oP 'inet \K[\d.]+')

# create webhook
while :
do
response_code=$(curl -b "" --location 'http://0.0.0.0/api/v2.0/projects/library/webhook/policies' \
--header 'accept: application/json' \
--header 'X-Request-Id: 1' \
--header 'X-Is-Resource-Name: false' \
--header 'authorization: Basic YWRtaW46SGFyYm9yMTIzNDU=' \
--header 'Content-Type: application/json' \
--data "{
\"id\": 0,
\"name\": \"Acceleration Service\",
\"description\": \"test for acceleration service\",
\"project_id\": 0,
\"targets\": [
{
\"type\": \"http\",
\"address\": \"http://${IP}:2077/api/v1/conversions\",
\"auth_header\": \"acceleration-service\",
\"skip_cert_verify\": true
}
],
\"event_types\": [
\"PUSH_ARTIFACT\"
],
\"creator\": \"admin\",
\"creation_time\": \"2023-09-19T03:54:32.967Z\",
\"update_time\": \"2023-09-19T03:54:32.967Z\",
\"enabled\": true
}" -w "%{http_code}\n" -o /dev/null)

if [ "$response_code" -ge 200 ] && [ "$response_code" -lt 300 ]; then
break
fi

sleep 5
done

docker pull alpine
docker login -u admin -p Harbor12345 localhost
docker tag alpine localhost/library/alpine
docker push localhost/library/alpine

sleep 5

count=0
while [ $count -lt 60 ]; do
response=$(curl -b "" --location 'http://0.0.0.0/api/v2.0/projects/library/repositories/alpine/artifacts/latest-nydus/tags?page=1&page_size=10&with_signature=false&with_immutable_status=false' \
--header 'accept: application/json' \
--header 'X-Request-Id: 1' \
-s -o /dev/null -w "%{http_code}")

cat acceld.log
if [ "$response" == "200" ]; then
curl -b "" --location 'http://0.0.0.0/api/v2.0/projects/library/repositories/alpine/artifacts/latest-nydus/tags?page=1&page_size=10&with_signature=false&with_immutable_status=false' --header 'accept: application/json'
if grep -E 'level=error|panic:' acceld.log; then
exit 1
fi
exit 0
fi

sleep 1
count=$((count + 1))
done

curl -b "" --location 'http://0.0.0.0api/v2.0/projects/library/repositories/alpine/artifacts/latest-nydus/tags?page=1&page_size=10&with_signature=false&with_immutable_status=false' --header 'accept: application/json'
exit 1

0 comments on commit 5c24e20

Please sign in to comment.