Bash脚本未在justb4/jmeter容器中作为入口脚本运行。

huangapple go评论61阅读模式
英文:

Bash Script is not running in the justb4/jmeter container as an entrypoint script

问题

I am using the justb4/jmeter image as docker-compose service and the scenario is like the aws-cli should download the jmx file and those jmx file will be used by the justb4/jmeter container. So till the aws-cli container download the files, jmeter have to wait. And I implemented it by checking flag file existance in shared volume. i.e. when aws-cli is download is done, I make one file in the shared container, till then jmeter have to wait in the while loop till the file is not present.

The problem is the jmeter script is not running properly and it is yeilding warnings and errors like
#!/bin/bash: not found and error is syntax error: unexpected end of file (expecting "do")

services:
  jmeterclidemo:
    image: ${DOCKER_REGISTRY-}jmeterclidemo
    build:
      context: .
      dockerfile: JmeterCLIDemo/Dockerfile
    ports:
      - "5001:80"
      - "5000:443"
 awscli:
     image: amazon/aws-cli:latest
     environment:
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
      - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
     entrypoint: /app/aws-script/entrypoint.sh
     volumes:
      - ./aws-script:/app/aws-script
      - test-scripts:/app/test-scripts
      - results:/app/results
      - flag:/app/flag

  jmeter:
    image: justb4/jmeter:latest
    volumes: 
    - test-scripts:/jmeter/test-scripts
    - results:/jmeter/results
    - flag:/jmeter/flag
    #- ./test-scripts:/jmeter/test-scripts
    - ./results:/jmeter/results
    entrypoint: ["sh", "-c","/jmeter/test-scripts/entrypoint.sh"]
    depends_on: 
    - jmeterclidemo
    - awscli

And in the jmeter script file i wrote

#!/bin/bash
echo "execution started"
while [ ! -e "/app/flag/download_done.txt" ];
do
    :
done;

jmeter -n -t /jmeter/test-scripts/TestFileGet.jmx -l /jmeter/results/TestFileGetByID-detail.jtl 
echo "execution completed successfully."

touch "/app/flag/upload_start.txt"
exit 0;

It is printing #!/bin/bash: not found and error is syntax error: unexpected end of file (expecting "do") as the log message.

英文:

I am using the justb4/jmeter image as docker-compose service and the scenario is like the aws-cli should download the jmx file and those jmx file will be used by the justb4/jmeter container. So till the aws-cli container download the files, jmeter have to wait. And I implemented it by checking flag file existance in shared volume. i.e. when aws-cli is download is done, I make one file in the shared container, till then jmeter have to wait in the while loop till the file is not present.
The problem is the jmeter script is not running properly and it is yeilding warnings and errors like
#!/bin/bash: not found and error is syntax error: unexpected end of file (expecting "do")

services:
  jmeterclidemo:
    image: ${DOCKER_REGISTRY-}jmeterclidemo
    build:
      context: .
      dockerfile: JmeterCLIDemo/Dockerfile
    ports:
      - "5001:80"
      - "5000:443"
 awscli:
     image: amazon/aws-cli:latest
     environment:
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
      - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
     entrypoint: /app/aws-script/entrypoint.sh
     volumes:
      - ./aws-script:/app/aws-script
      - test-scripts:/app/test-scripts
      - results:/app/results
      - flag:/app/flag

  jmeter:
    image: justb4/jmeter:latest
    volumes: 
    - test-scripts:/jmeter/test-scripts
    - results:/jmeter/results
    - flag:/jmeter/flag
    #- ./test-scripts:/jmeter/test-scripts
    - ./results:/jmeter/results
    entrypoint: ["sh", "-c","/jmeter/test-scripts/entrypoint.sh"]
    depends_on: 
    - jmeterclidemo
    - awscli

And in the jmeter script file i wrote

#!/bin/bash
echo "execution started"
while [ ! -e "/app/flag/download_done.txt" ];
do
    :
done;

jmeter -n -t /jmeter/test-scripts/TestFileGet.jmx -l /jmeter/results/TestFileGetByID-detail.jtl 
echo "execution completed successfully."

touch "/app/flag/upload_start.txt"
exit 0;

It is printing #!/bin/bash: not found and error is syntax error: unexpected end of file (expecting "do") as the log message.

答案1

得分: 1

以下是翻译好的部分:

让我回答我的问题。
所有的代码都写得正确,语法也没有错误。但问题在于Docker容器将使用Linux操作系统,因此它将在所有文件(包括上面的.sh文件)中查找Linux行尾(LF)。
但是上面的.sh文件具有Windows行尾(CRLF),因此它无法正确识别文件结尾。
从Notepad++或VSCode更改脚本(.sh文件)的文件结尾为LF(Linux文件结尾),然后运行docker-compose up -d,一切都正常工作,如预期。

英文:

Let me answer my question.
All the code is rightly written and no error in syntax as well. But the thing is docker container will use the linux operating system, so it will look for linux line endings (LF) inside all files(including above .sh file).
But the .sh file above has windows line ending(CRLF) so it will not recogize the file ending properly.
Changing the file ending to LF(linux file ending) of the script(.sh file) from notepad++ or vscode and then running docker-compose up -d is working file and as expected.

huangapple
  • 本文由 发表于 2023年6月8日 20:14:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定