From 2ec15d80f8b1e52e69398e23d93bf71ad237b5e9 Mon Sep 17 00:00:00 2001 From: njl <1012408214@qq.com> Date: Fri, 18 Oct 2024 22:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=09=E6=96=B0=E6=96=87=E4=BB=B6=EF=BC=9A=20=20?= =?UTF-8?q?=20function=5Fmodules/noop/buildAndPush.sh=20=09=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=9A=20=20=20=20=20function=5Fmodules/noop/invoke?= =?UTF-8?q?.sh=20=09=E6=96=B0=E6=96=87=E4=BB=B6=EF=BC=9A=20=20=20function?= =?UTF-8?q?=5Fmodules/noop/noop=20=09=E4=BF=AE=E6=94=B9=EF=BC=9A=20=20=20?= =?UTF-8?q?=20=20function=5Fmodules/noop/noop.c=20=09=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=9A=20=20=20function=5Fmodules/noop/run=5Ftrigge?= =?UTF-8?q?r.sh=20=09=E4=BF=AE=E6=94=B9=EF=BC=9A=20=20=20=20=20function=5F?= =?UTF-8?q?modules/noop/test1.json=20=09=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=9A=20=20=20function=5Fmodules/noop/update=5Faction.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function_modules/noop/buildAndPush.sh | 50 +++++++++++++++++++++++++ function_modules/noop/invoke.sh | 0 function_modules/noop/noop | Bin 0 -> 12800 bytes function_modules/noop/noop.c | 45 ++++++++++++++++++++-- function_modules/noop/run_trigger.sh | 3 ++ function_modules/noop/test1.json | 25 ++++++++++--- function_modules/noop/update_action.sh | 7 ++++ 7 files changed, 121 insertions(+), 9 deletions(-) create mode 100755 function_modules/noop/buildAndPush.sh mode change 100644 => 100755 function_modules/noop/invoke.sh create mode 100755 function_modules/noop/noop create mode 100755 function_modules/noop/run_trigger.sh create mode 100755 function_modules/noop/update_action.sh diff --git a/function_modules/noop/buildAndPush.sh b/function_modules/noop/buildAndPush.sh new file mode 100755 index 0000000..a9d4d41 --- /dev/null +++ b/function_modules/noop/buildAndPush.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +IMAGE_NAME=$1 +REGISTRY=${2:-"docker.io"} # 默认使用 docker.io (Docker Hub),如果指定 registry 则使用指定的 +BUILD_CONTEXT=${3:-"."} # 默认使用当前目录作为构建上下文 + +if [ -z "$IMAGE_NAME" ]; then + echo "Error: Image name not provided" + echo "Usage: buildAndPush.sh imageName [registry] [buildContext]" + exit 1 +fi + +echo "Using $IMAGE_NAME as the image name" +echo "Using $REGISTRY as the registry" +echo "Using $BUILD_CONTEXT as the build context" + +# Build the Docker image +BUILD_LOG=$(mktemp) +docker build -t $IMAGE_NAME $BUILD_CONTEXT --progress=plain > $BUILD_LOG 2>&1 +BUILD_EXIT_CODE=$? + +if [ $BUILD_EXIT_CODE -ne 0 ]; then + echo "Docker build failed with exit code $BUILD_EXIT_CODE" + echo "Build log:" + cat $BUILD_LOG + rm $BUILD_LOG + exit 1 +fi + +rm $BUILD_LOG + +# Tag the image for the specified registry +if [ "$REGISTRY" != "docker.io" ]; then + FULL_IMAGE_NAME="$REGISTRY/$IMAGE_NAME" + docker tag $IMAGE_NAME $FULL_IMAGE_NAME + if [ $? -ne 0 ]; then + echo "Docker tagging failed" + exit 1 + fi + IMAGE_NAME="$FULL_IMAGE_NAME" +fi + +# Push the Docker image +docker push $IMAGE_NAME +if [ $? -ne 0 ]; then + echo "Docker push failed" + exit 1 +fi + +echo "Docker image successfully pushed to $IMAGE_NAME" diff --git a/function_modules/noop/invoke.sh b/function_modules/noop/invoke.sh old mode 100644 new mode 100755 diff --git a/function_modules/noop/noop b/function_modules/noop/noop new file mode 100755 index 0000000000000000000000000000000000000000..d521911b102bc44841656edde003980fc816212b GIT binary patch literal 12800 zcmeHNeQ;b=6~CKp+E9{B=m(Sn_7SMGrCpMKrYV(dnoVCcZJ{JZM%vfS?j~8->}Gb~ zmIPakgfi}=h5W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w z-YBwHLf%aqH`nD?qEwcM5lAEg{YE%uCi;=Ug6%ycl4(UhC}H=4()I#UGA2}DjYwQi*aAqKfQLPjVVH@X9{5akcG?1EM(5;IasY{J^Y zMORJbGC6&BB$LXuOkFYzq$KfGq+F%E2}rpaP`NIx%&A;Vc$57-W}pMqOjxv=Ysk6^ zCwhf97B|CQUt`M}Gti~Du2{<3k%}O9FA@@7;<^LLZs85}$KcPRNYav$1K~sxJJ30d z0a+p(4UmDV^+rwMmErKB>g|eyHN$=QrJDdsae1k|;chkTyF+looMmc_f6IdFXd%!O z38GIlQoM+&@Z#RnA0ax?CrE3l4gPV|#wDWvW4D zFFgM;R*Q<=p5K3&-pY!KI_;Z)zlSvox6kj%Ou7GRd6QWOvfG`g&?B4ePpS&j0SXQZ zEzhXRuTi}I+5?Q%N^H;X-AsAi2o+hBJ7&c`)M!n{_WXX%R8yMVf7WCA5ahJRW1ipR zGgR3-`>$Z}2r3j)w&(YKrejKx+jpM-W6Hi!>G8UNDX)9U{#qPP`zL@=Ow{r>^W5U+ z7v2DJiu3xXA+_7{I)kaqiLiO7QgxR3o~yX^0q z4trkTFy-|=>pRc?gtF)B$L~2zf5wK2a=#gV#$i7z@0t}Ab+-SU!=BewOv@Yt-r4>O zu%|T&hl$_AIUn1p&pgxLz_!w6&+D|ln*gG)p2cN(#$Sbi#vZrN>jTbr=e%|vpKQn1 zk=8SGifqr{eR`JxL>ab7=9lf6z6pulKJ&h-Sti^LJ77EJr%@q{+voSkD$UYx>N_rn zco%Af)mZA8U$$SFL97bf+bNGdyJ~}GabqfQ^qir0W9|>npESO?@0Nx7z0IPh9L~92 U*1ZOmeD #include +#include +#define Perior_action_count 5 + + +int main(int argc, char *argv[]) { + //char *str = "{\"__ow_body\": [{\"action_name\": \"/guest/noop2\", \"activation_id\": \"ae0b8d60759642d18b8d60759622d14c\", \"message\": \" hello world!\"}, {\"action_name\": \"/guest/noop3\", \"activation_id\": \"52b5d51af9bd40a0b5d51af9bd10a078\", \"message\": \" hello world!\"}], \"__ow_headers\": {\"accept\": \"*/*\", \"accept-encoding\": \"gzip, deflate\", \"content-type\": \"application/json\", \"host\": \"controllers\", \"user-agent\": \"python-requests/2.18.4\", \"x-forwarded-for\": \"172.17.0.1\", \"x-forwarded-host\": \"172.17.0.1\", \"x-forwarded-port\": \"8080\", \"x-forwarded-proto\": \"http\", \"x-forwarded-url\": \"http://172.17.0.1/api/23bc46b1-71f6-4ed5-8c54-816aa4f8c502/noop4-api/noop4-path\", \"x-real-ip\": \"172.17.0.1\", \"x-request-id\": \"fda5d48c51bbc97ee8602d3f2ab8d90a\"}, \"__ow_method\": \"post\", \"__ow_path\": \"\"}"; + char *str = argv[1]; + char *value = NULL ; + char *key = "action_name"; + char *perior_action[Perior_action_count]; + int perior_action_count=0; + char *start = strstr(str, key); + while (start) + { + start =start+ strlen(key) + 4; // 跳过键部分,指向值的开始 + char *end = strstr(start, ","); + //end +=2 ; // 查找值的结束引号 + int length = end - start; + value = (char *)malloc(length + 1); // +1 用于存储字符串结束符 + if (value == NULL) printf("Memory allocation failed\n"); + if (end) { + // 复制值到 value 中 + strncpy(value, start, length-1); + value[length] = '\0'; // 添加字符串结束符 + } + perior_action[perior_action_count]=value; + perior_action_count++; + start = strstr(end, key); + + } + printf ("argv1:%s\n",argv[1]); + + if (perior_action_count != 0) + {for (int i = 0; i < perior_action_count; i++) + {printf("perior action:%s\n",perior_action[i]); + free (perior_action[i]);} + } + + + const char *actvation_id = getenv("__OW_ACTIVATION_ID"); + const char *action = getenv("__OW_ACTION_NAME"); + printf("{\"action_name\" : \"%s\", \"activation_id\":\"%s\",\"message\": \" hello world!\" }\n",action,actvation_id); -int main() { - const char *env_var = getenv("__OW_ACTIVATION_ID"); - printf("{ \"activation_id\":\"%s\",\"message\": \" hello world!\" }\n",env_var); return 0; // 返回 0 表示程序成功 } diff --git a/function_modules/noop/run_trigger.sh b/function_modules/noop/run_trigger.sh new file mode 100755 index 0000000..ace4f75 --- /dev/null +++ b/function_modules/noop/run_trigger.sh @@ -0,0 +1,3 @@ +trigger_name=$1 + +curl -X POST http://localhost:5001/run/$trigger_name -H "Content-Type: application/json" -d '{}' \ No newline at end of file diff --git a/function_modules/noop/test1.json b/function_modules/noop/test1.json index 88b200f..8d16ce6 100644 --- a/function_modules/noop/test1.json +++ b/function_modules/noop/test1.json @@ -22,11 +22,11 @@ "label":"noop 2", "primitive":"merging", "condition":{}, - "next":["noop4"], + "next":"noop4", "branch_1":"", "branch_2":"", "arguments":"", - "outputs_from":"" + "outputs_from":["noop1"] } }, { @@ -36,11 +36,11 @@ "label":"noop 3", "primitive":"merging", "condition":{}, - "next":["noop4"], + "next":"noop4", "branch_1":"", "branch_2":"", "arguments":"", - "outputs_from":"" + "outputs_from":["noop1"] } }, { @@ -50,13 +50,26 @@ "label":"noop 4", "primitive":"serial", "condition":{}, + "next":"noop5", + "branch_1":"", + "branch_2":"", + "arguments":"", + "outputs_from":["noop2","noop3"] + } + }, + { + "node_id":"noop5", + "properties": + { + "label":"noop 5", + "primitive":"serial", + "condition":{}, "next":"", "branch_1":"", "branch_2":"", "arguments":"", - "outputs_from":"" + "outputs_from":["noop4"] } } ] - } \ No newline at end of file diff --git a/function_modules/noop/update_action.sh b/function_modules/noop/update_action.sh new file mode 100755 index 0000000..af40be1 --- /dev/null +++ b/function_modules/noop/update_action.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +wsk -i action update noop5 --docker localhost:5000/noop-image +wsk -i action update noop4 --docker localhost:5000/noop-image +wsk -i action update noop3 --docker localhost:5000/noop-image +wsk -i action update noop2 --docker localhost:5000/noop-image +wsk -i action update noop1 --docker localhost:5000/noop-image \ No newline at end of file