diff --git a/docs/pilote/Pilote - Agent/getting_started/launch_local_doctypes.md b/docs/pilote/Pilote - Agent/getting_started/launch_local_doctypes.md new file mode 100644 index 0000000000000000000000000000000000000000..86fb0836c18c6f1385d381b6d77692ce2d0b65d5 --- /dev/null +++ b/docs/pilote/Pilote - Agent/getting_started/launch_local_doctypes.md @@ -0,0 +1,80 @@ +!!! info "" + :construction: Section under Construction :construction: + + + +## Use cozy-doctype in local +In order to be able to use our own cozy-doctype, especialy remote doctype here, we need to use them in local. + +1/ clone cozy-doctype repository into your system. +Then, push it into your root project. + +2/ After that, add your own remote doctype into cozy-doctype folder: + - create a new folder ex: org.mps.share + - push into this folder request file: request + +You must declare this doctype into your manifest.webapp file like that : + "share": { + "description": "Required for searching on back-endTS", + "type": "org.mps.share", + "verbs": ["GET", "POST"] + }, + + +3/ In cozy-app-dev-with-app.sh, you need to add another option when you serve the cozy-stack: + - cozy-stack serve --allow-root (...) --doctypes /path/to/the/doctype + +=> in this project : + - cozy-stack serve (...) --doctypes /data/cozy-doctypes + +!! Warning !! : You need to build and push the newlest image on the forge registry when the step 3 is done +!! Warning !! : You must have all files, into your docker folder, in LF mode of "End of Line Sequence" ! + +For this project: + - cd docker + - docker build . + - docker tag <image_ID_created> registry.forge.grandlyon.com/solidarite/monparcourssocial/mps-usager/cozy-env-doctypes + - docker push registry.forge.grandlyon.com/solidarite/monparcourssocial/mps-usager/cozy-env-doctypes:latest + +4/ The path "/data/cozy-doctypes" is link to the volume of the cozy-app-dev image. + - in order to mount this volume, you need to add it when you run the 'docker run' command : + -v $PWD/cozy-doctypes:/data/cozy-doctypes + + => for this project : + docker run --rm -it -p 8080:8080 -p 5984:5984 -p 8025:8025 -v $PWD/build:/data/cozy-app/mps -v $PWD/data:/usr/local/couchdb/data -v $PWD/docker/disableCSP.yaml:/etc/cozy/cozy.yaml -v $PWD/cozy-doctypes:/data/cozy-doctypes registry.forge.grandlyon.com/solidarite/monparcourssocial/mps-usager/cozy-env-doctypes + + +# How to test your remote doctype ? +## GET +1/ In the request file created. Specify the methode and the route to your target URL : + GET https://pilote-agent-dev.grandlyon.com/api/cozy + + or with value in query : + + GET https://pilote-agent-dev.grandlyon.com/api/auth/token/check?token={{token}} + + +2/ Then, you can test it by : + - await client.getStackClient().fetchJSON('GET','/remote/org.mps.share') + + or with value in query : + + - await client.getStackClient().fetchJSON('GET','/remote/org.mps.share?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNvenlBcGlDaGVjayIsInVzZXJJZCI6IjEiLCJpYXQiOjE2MDU2OTI0NjYsImV4cCI6MTYwNTY5MjUyNn0.HbQh5H-TcVIASUpbjZAD0MY9slRAJOVw-VMKSBu_sQ0' ) + +## POST +1/ In the request file created. Specify the methode and the route to your target URL : + POST https://pilote-agent-dev.grandlyon.com/api/auth/token/check + Content-Type: application/json + + {{data}} + + +2/ Then, you can test it by : + const parameters = { + data: JSON.stringify({ + token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImNvenlBcGlDaGVjayIsInVzZXJJZCI6IjEiLCJpYXQiOjE2MDU2MjYxNzAsImV4cCI6MTYwNTYyNjIzMH0.8m-rEAZkuqb4upAPKY7j8DhvFi8mVbmiCFDitgNYt6Y" + } + ) + } + + console.log('call remote ==> ', await client.getStackClient().fetchJSON('POST','/remote/org.mps.share', parameters )) diff --git a/docs/pilote/Pilote - Agent/getting_started/launch_local_services.md b/docs/pilote/Pilote - Agent/getting_started/launch_local_services.md new file mode 100644 index 0000000000000000000000000000000000000000..7220022ec9114957465da44412089b3bc0d52c89 --- /dev/null +++ b/docs/pilote/Pilote - Agent/getting_started/launch_local_services.md @@ -0,0 +1,120 @@ +!!! info "" + :construction: Section under Construction :construction: + + +### Use services in local +## Configure the cozy-stack on local +In order to be able to use your sercice, follow these steps: + +1/ clone cozy-doctype repository into your system. +Then, push it into your root project. + +2/ After that, add your own remote doctype into cozy-doctype folder: + - create a new folder ex: org.mps.share + - push into this folder request file: request + +You must declare this doctype into your manifest.webapp file like that : + "share": { + "description": "Required for searching on back-endTS", + "type": "org.mps.share", + "verbs": ["GET", "POST"] + }, + + +3/ In cozy-app-dev-with-app.sh, you need to add another option when you serve the cozy-stack: + - cozy-stack serve --allow-root (...) --doctypes /path/to/the/doctype + +=> in this project : + - cozy-stack serve (...) --doctypes /data/cozy-doctypes + +4/ You need to add another option when you install apps in the cozy-stack (go to: docker\cozy-app-dev-with-app.sh) +In do_install_app(): + +``` +#add symbolic link to mps for sms service + ln -s /data/cozy-app/mps /data/cozy-storage/cozy.tools\:8080/.cozy_apps/mps + if [ -d "data/cozy-app/mps/0.1.1" ]; then + echo "data/cozy-app/mps/0.1.1 already here!"; + else + mkdir /data/cozy-app/mps/0.1.1 + cp -a /data/cozy-app/mps/services/ /data/cozy-app/mps/0.1.1/ + echo "data/cozy-app/mps/0.1.1 just create!"; + fi + # mkdir /data/cozy-app/mps/0.1.1 + # cp -a /data/cozy-app/mps/services/ /data/cozy-app/mps/0.1.1/ + echo "service added" +``` + +5/ Then, add konnector-node-run.sh in docker folder. This file is a script to store the service logs. It should contain: + #!/bin/bash + + rundir="${1}" + cd $rundir + node index.js | tee /data/cozy-app/mps/services.log + +Then, add this following row into the Dockerfile: + +COPY konnector-node-run.sh /etc/cozy/konnector-node-run.sh + +6/ Into the disableCSP.yml, you need to add one more configuration: + +konnectors: + cmd: /etc/cozy/konnector-node-run.sh # run connectors with node + + +!! Warning !! : You need to build and push the newlest image on the forge registry when the step 6 is done +!! Warning !! : You must have all files, into your docker folder, in LF mode of "End of Line Sequence" ! + +Finaly, you should rebuild the docker image of the cozy-stack: + - cd docker + - docker build . + - docker tag <image_ID_created> registry.forge.grandlyon.com/solidarite/monparcourssocial/mps-usager/cozy-env-doctypes + - docker push registry.forge.grandlyon.com/solidarite/monparcourssocial/mps-usager/cozy-env-doctypes:latest + + +7/ The path "/data/cozy-doctypes" is link to the volume of the cozy-app-dev image. + - in order to mount this volume, you need to add it when you run the 'docker run' command : + -v $PWD/cozy-doctypes:/data/cozy-doctypes + + => for this project : + docker run --rm -it -p 8080:8080 -p 5984:5984 -p 8025:8025 -v $PWD/build:/data/cozy-app/mps -v $PWD/data:/usr/local/couchdb/data -v $PWD/docker/disableCSP.yaml:/etc/cozy/cozy.yaml -v $PWD/cozy-doctypes:/data/cozy-doctypes registry.forge.grandlyon.com/solidarite/monparcourssocial/mps-usager/cozy-env-doctypes + + +## How to test your service ? + +In the manifest.webapp, you need to declare the service: + +"services": { + "smsProcess": { + "type": "node", + "file": "services/smsProcess/pilote.js" + } + }, + +Then, in src\targets\services, you can add your service. + + + +For this project, we have created a button in Home.component.tsx in order to generate trigger url to run the service: + +const getTrigger = async () => { + const attrs = { type: '@webhook', + worker: 'service', + message: { + name: 'smsProcess', + slug: 'pilotedemo', + }, + } + + const trigger = await client.getStackClient() .collection('io.cozy.triggers') .create(attrs) + console.log('trigger', trigger) + } + +It generate an trigger URL that we can call with our backend application : + +> URL_COZY/job/webhook/{{trigger_id}} + + + +URL_COZY represent the cozy-stack url of your environment and not your application URL. +