H-T-6221 / cplus_sample

C++ sample code
0 stars 0 forks source link

20241008_Add_Log_for_Communication_Application #9

Open H-T-6221 opened 1 month ago

H-T-6221 commented 1 month ago

Jenkinsに通信アプリのテストを自動で実施するように実装した。 コードを乗せる場所がないため、以下に記載する。 ※今後、Jenkinsファイルにして、実装したい。

node {
    stage('echo') {
        echo 'Hello'
        sh 'pwd'
    }
    stage('git') {
        sh 'rm -rf cplus_sample'
        sh 'git clone https://github.com/H-T-6221/cplus_sample.git'
        //sh 'cd cplus_sample/02_docker/03_http_com; ./build.sh'
    }
    stage('build') {
        sh 'docker images'
        sh 'docker run -it -d --network container_nw --ip 192.168.20.10 --name build image_ubuntu'
        sh 'docker ps'
        sh 'docker exec build git clone https://github.com/H-T-6221/cplus_sample.git'
        sh 'docker exec build chmod 755 cplus_sample/04_source/build.sh'
        sh 'docker exec build ./cplus_sample/04_source/build.sh'
        sh 'docker cp build:/root/cplus_sample/04_source/module cplus_sample/03_automation'
        sh 'docker stop build'
        sh 'docker rm build'
        sh 'docker ps'
    }
    stage('deploy') {
        sh 'cd cplus_sample/03_automation; ./deploy_container.sh'
    }
    stage('test') {
        //sh 'cd cplus_sample/03_automation; ./automation_test.sh'
        sh 'docker exec /root/sender server &'
        sh 'docker exec /root/reciever client &'
    }
}

Log機能がないため、通信がどこまでできているのか分かっていない。

ユーザー[ichikawa.hisato](http://127.0.0.1:8080/user/ichikawa)が実行
[Pipeline] Start of Pipeline
[Pipeline] node
Running on [Jenkins](http://127.0.0.1:8080/computer/(built-in)/) in C:\ProgramData\Jenkins\.jenkins\workspace\test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (echo)
[Pipeline] echo
Hello
[Pipeline] sh
+ pwd
/c/ProgramData/Jenkins/.jenkins/workspace/test
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (git)
[Pipeline] sh
+ rm -rf cplus_sample
[Pipeline] sh
+ git clone https://github.com/H-T-6221/cplus_sample.git
Cloning into 'cplus_sample'...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] sh
+ docker images
REPOSITORY                 TAG       IMAGE ID       CREATED         SIZE
image_ubuntu               latest    a77ae9f4727e   4 days ago      944MB
jenkins/jenkins            latest    078194d3c9a9   13 days ago     788MB
docker/welcome-to-docker   latest    eedaff45e3c7   11 months ago   29.5MB
[Pipeline] sh
+ docker run -it -d --network container_nw --ip 192.168.20.10 --name build image_ubuntu
41652056e8f62987cc05d577f81657bac632a37bf4aaba5742871f770a934575
[Pipeline] sh
+ docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS                  PORTS     NAMES
41652056e8f6   image_ubuntu   "/bin/bash"   1 second ago   Up Less than a second             build
[Pipeline] sh
+ docker exec build git clone https://github.com/H-T-6221/cplus_sample.git
Cloning into 'cplus_sample'...
[Pipeline] sh
+ docker exec build chmod 755 cplus_sample/04_source/build.sh
[Pipeline] sh
+ docker exec build ./cplus_sample/04_source/build.sh
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at client/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at server/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /root/cplus_sample/04_source/build
[ 25%] Building CXX object client/CMakeFiles/client.dir/client.cpp.o
[ 50%] Linking CXX executable client
[ 50%] Built target client
[ 75%] Building CXX object server/CMakeFiles/server.dir/server.cpp.o
[100%] Linking CXX executable server
[100%] Built target server
/root/cplus_sample/04_source
[Pipeline] sh
+ docker cp build:/root/cplus_sample/04_source/module cplus_sample/03_automation
[Pipeline] sh
+ docker stop build
build
[Pipeline] sh
+ docker rm build
build
[Pipeline] sh
+ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (deploy)
[Pipeline] sh
+ cd cplus_sample/03_automation
+ ./deploy_container.sh
e420a2ba814d7399dc779043274bf8237a3636e70c2af41fd8a32b21c5650c24
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS                  PORTS     NAMES
e420a2ba814d   image_ubuntu   "/bin/bash"   1 second ago   Up Less than a second             reciever
396a6dc002cbc3058eeea8df34b1e40de9ef355a5d0c168d006cc3284d623033
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS                  PORTS     NAMES
396a6dc002cb   image_ubuntu   "/bin/bash"   1 second ago    Up Less than a second             sender
e420a2ba814d   image_ubuntu   "/bin/bash"   2 seconds ago   Up 1 second                       reciever
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (test)
[Pipeline] sh
+ docker exec /root/sender server
[Pipeline] sh
+ docker exec /root/reciever client
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Log機能を追加し、通信テストの確認を行う。

H-T-6221 commented 1 month ago

ソースコードを実装致しました。 ローカル上で動作することを確認致しました。 https://github.com/H-T-6221/cplus_sample/commit/894180a365df74d5016e85e92d37344eee785c73

次はJenkins上で実行し、動作することを確認致します。

H-T-6221 commented 1 month ago

Jenkins上ではわからないがローカル実行で確認したところ、実行できていなかった。 バックグラウンドでエラーが起きている。

hi344@DESKTOP-1CGGT07 MINGW64 /c/work/開発/repository/cplus_sample (main)
$ docker exec sender /root/server&
[1] 2620

hi344@DESKTOP-1CGGT07 MINGW64 /c/work/開発/repository/cplus_sample (main)
$ OCI runtime exec failed: exec failed: unable to start container process: exec: "C:/Program Files/Git/root/server": stat C:/Program Files/Git/root/server: no such file or directory: unknown

[1]+  Exit 126                docker exec sender /root/server
H-T-6221 commented 1 month ago

エラーメッセージから以下のサイトに書かれているを試してみた。 https://stackoverflow.com/questions/48001082/oci-runtime-exec-failed-exec-failed-executable-file-not-found-in-path

Windows CMDの場合(bashに切り替えない):

docker exec -it <container-id> /bin/sh

Windows CMDの場合(bashに切り替えた後):

docker exec -it <container-id> //bin//sh
または
winpty docker exec -it <container-id> //bin//sh

Git Bash の場合:

winpty docker exec -it <container-id> //bin//sh

今回、以下を試した。

docker exec sender //bin//sh /root/server
+ docker exec sender //bin//sh /root/server
//bin//sh: 0: cannot open C:/Program Files/Git/root/server: No such file

まだエラーが発生中