修改: function_modules/noop/invoke.sh 新文件: function_modules/noop/noop 修改: function_modules/noop/noop.c 新文件: function_modules/noop/run_trigger.sh 修改: function_modules/noop/test1.json 新文件: function_modules/noop/update_action.shanubhav
parent
0eacbfaafc
commit
2ec15d80f8
@ -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"
|
Binary file not shown.
@ -1,9 +1,48 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#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 表示程序成功
|
return 0; // 返回 0 表示程序成功
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
trigger_name=$1
|
||||||
|
|
||||||
|
curl -X POST http://localhost:5001/run/$trigger_name -H "Content-Type: application/json" -d '{}'
|
@ -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
|
Loading…
Reference in new issue