diff --git a/.github/actions/aws-mfa-login/action.yml b/.github/actions/aws-mfa-login/action.yml new file mode 100644 index 0000000..95bfb3b --- /dev/null +++ b/.github/actions/aws-mfa-login/action.yml @@ -0,0 +1,49 @@ +name: aws-mfa-login +author: dev@floatic.io +description: mfa login for aws + +inputs: + access_key_id: + description: 'AWS access key id' + required: true + secret_access_key: + description: 'AWS access secret key' + required: true + mfa_key: + description: 'MFA Key' + required: true + mfa_arn: + description: 'MFA arn' + required: true + +runs: + using: "composite" + steps: + - run: sudo apt install awscli -y + shell: bash + + - run: sudo -S -k apt-get install -y oathtool jq + shell: bash + + - uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ inputs.access_key_id }} + aws-secret-access-key: ${{ inputs.secret_access_key }} + aws-region: ap-northeast-2 + + - run: | + token=$(oathtool -b --totp ${{ inputs.mfa_key }}) + aws sts get-session-token --duration-seconds 36000 --serial-number ${{ inputs.mfa_arn }} --token-code $token > mfa-temp.json + accessKeyId=$(cat mfa-temp.json | jq -r .Credentials.AccessKeyId) + secretAccessKey=$(cat mfa-temp.json | jq -r .Credentials.SecretAccessKey) + sessionToken=$(cat mfa-temp.json | jq -r .Credentials.SessionToken) + echo ${accessKeyId} + echo ${secretAccessKey} + echo ${sessionToken} + aws configure set aws_access_key_id $accessKeyId + aws configure set aws_secret_access_key $secretAccessKey + aws configure set aws_session_token $sessionToken + aws configure set region ap-northeast-2 + shell: bash + - run: aws sts get-caller-identity + shell: bash \ No newline at end of file diff --git a/.github/actions/floatic-ppa-access/action.yml b/.github/actions/floatic-ppa-access/action.yml new file mode 100644 index 0000000..6060e1b --- /dev/null +++ b/.github/actions/floatic-ppa-access/action.yml @@ -0,0 +1,31 @@ +name: floatic-ppa-access +author: kein@floatic.io +description: ppa server inbound setting + +inputs: + target_group_name: + description: "aws ec2 scurity group name" + required: true + + protocol: + description: "inbound protocol" + required: true + default: tcp + + port: + description: "inbound port" + required: true + default: 443 + +runs: + using: "composite" + steps: + - id: get_public_ip + uses: haythem/public-ip@v1.2 + + - run: aws ec2 authorize-security-group-ingress --group-name ${{ inputs.target_group_name }} --protocol ${{ inputs.protocol }} --port ${{ inputs.port }} --cidr ${{ steps.get_public_ip.outputs.ipv4 }}/32 + shell: bash + + - uses: webiny/action-post-run@3.0.0 + with: + run: aws ec2 revoke-security-group-ingress --group-name ${{ inputs.target_group_name }} --protocol ${{ inputs.protocol }} --port ${{ inputs.port }} --cidr ${{ steps.get_public_ip.outputs.ipv4 }}/32 \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..a2115d1 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,77 @@ +name: CD +on: + push: + tags: + - v* + +jobs: + ecr_setting: + # if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/deploy') + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: AWS Mfa login + uses: ./.github/actions/aws-mfa-login + with: + access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + mfa_key: ${{ secrets.MFA_KEY }} + mfa_arn: ${{ secrets.MFA_ARN }} + + - id: get_ecr_password + name: Get ECR password + run: | + PROIFLE_REGION=$(aws configure get region) + ECR_PASSWORD=$(aws ecr get-login-password --region $PROIFLE_REGION) + echo "ECR_PASSWORD=$ECR_PASSWORD" >> $GITHUB_OUTPUT + outputs: + ecr_password: ${{ steps.get_ecr_password.outputs.ECR_PASSWORD }} + + debian_build: + needs: ecr_setting + runs-on: ubuntu-latest + container: + image: 557571393534.dkr.ecr.ap-northeast-2.amazonaws.com/floom + credentials: + username: AWS + password: ${{ needs.ecr_setting.outputs.ecr_password }} + steps: + - name: Update dist + run: sudo apt update + + - uses: actions/checkout@v3 + with: + path: 'flody_ws/etc/' + + - name: AWS Mfa login + uses: ./flody_ws/etc/.github/actions/aws-mfa-login + with: + access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} + secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + mfa_key: ${{ secrets.MFA_KEY }} + mfa_arn: ${{ secrets.MFA_ARN }} + + - name: PPA server access + uses: ./flody_ws/etc/.github/actions/floatic-ppa-access + with: + target_group_name: ${{ secrets.SECURITY_GROUP_NAME }} + + - name: Checkout submodules + run: | + cd flody_ws/etc + git submodule update --init --recursive + + - name: Generate debian file + run: | + source /opt/floatic/debian/ros/humble/setup.bash + cd flody_ws/etc + floom-generate rosdebian + ls debian_results/*.deb + shell: bash + + - name: Upload to S3 + run: | + ls flody_ws/etc/debian_results/ + aws s3 cp flody_ws/etc/debian_results s3://robotics-workflow-archive/flody_snapshot --include "*.deb" --recursive \ No newline at end of file diff --git a/README.md b/README.md index cb6d7f6..12abd72 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It subscribes to topics and maintains a buffer of recent messages like a dash ca ### Server ``` -$ ros2 run rosbag2_snapshot snapshotter +$ ros2 run rosbag2_snapshot snapshotter --ros-args --params-file src/rosbag2_snapshot/rosbag2_snapshot/param/multiple_topics.params.yaml (EDITED) Buffer recent messages until triggered to write or trigger an already running instance. @@ -37,8 +37,8 @@ Buffer recent messages until triggered to write or trigger an already running in ### Client -###### Write all buffered data to `.bag` -`ros2 run rosbag2_snapshot snapshotter_client --ros-params -p action_type:=trigger_write` +###### Write all buffered data to `.bag` (EDITED) +`ros2 run rosbag2_snapshot snapshotter_client --ros-args -p action_type:=trigger_write -p prefix:=a -p filename:={절대 경로 to bag file to write to} --params-file {path to topics yaml file from rosbag2_snapshot}` ###### Write buffered data from selected topics to `new_lighting.bag` `ros2 run rosbag2_snapshot snapshotter_client --ros-params -p filename:=new_lighting -p topics:=["/camera/image_raw", "/camera/camera_info"]` @@ -52,7 +52,8 @@ Buffer recent messages until triggered to write or trigger an already running in ###### Resume buffering new data `ros2 run rosbag2_snapshot snapshotter_client --ros-params -p action_type:=resume` -###### Call trigger service manually + +###### Call trigger service manually (LESS ERROR PRONE) ``` $ ros2 service call /trigger_snapshot rosbag2_snapshot_msgs/srv/TriggerSnapshot "{filename: '', topics: [], start_time: {sec: 0, nanosec: 0}, stop_time: {sec: 0, nanosec: 0}}" diff --git a/rosbag2_snapshot/CMakeLists.txt b/rosbag2_snapshot/CMakeLists.txt index 2941c82..43ef617 100644 --- a/rosbag2_snapshot/CMakeLists.txt +++ b/rosbag2_snapshot/CMakeLists.txt @@ -27,5 +27,4 @@ endif() ament_auto_package( INSTALL_TO_SHARE - param ) diff --git a/rosbag2_snapshot/param/multiple_topics.params.yaml b/rosbag2_snapshot/param/multiple_topics.params.yaml deleted file mode 100644 index 9e340b3..0000000 --- a/rosbag2_snapshot/param/multiple_topics.params.yaml +++ /dev/null @@ -1,13 +0,0 @@ -/**: - ros__parameters: - topics: ["/lidar1/points_raw", "/lidar2/points_raw", "/camera1/image"] - topic_details: - /lidar1/points_raw: - type: "sensor_msgs/msg/PointCloud2" - /lidar2/points_raw: - type: "sensor_msgs/msg/PointCloud2" - duration: 10.0 - /camera1/image: - type: "sensor_msgs/msg/Image" - duration: 15.0 - memory: 1024.0 diff --git a/rosbag2_snapshot/param/single_topic.params.yaml b/rosbag2_snapshot/param/single_topic.params.yaml deleted file mode 100644 index c98ba5c..0000000 --- a/rosbag2_snapshot/param/single_topic.params.yaml +++ /dev/null @@ -1,6 +0,0 @@ -/**: - ros__parameters: - topics: ["/rosout"] - topic_details: - /rosout: - type: "rcl_interfaces/msg/Log" diff --git a/rosbag2_snapshot/src/snapshotter.cpp b/rosbag2_snapshot/src/snapshotter.cpp index 8d0681f..87689c2 100644 --- a/rosbag2_snapshot/src/snapshotter.cpp +++ b/rosbag2_snapshot/src/snapshotter.cpp @@ -765,7 +765,7 @@ void SnapshotterClient::setSnapshotterClientOptions(const SnapshotterClientOptio }; } - TriggerSnapshot::Request::SharedPtr req; + TriggerSnapshot::Request::SharedPtr req = std::make_shared(); for (const auto & topic : opts.topics_) { req->topics.push_back(topic.asMessage()); @@ -798,7 +798,7 @@ void SnapshotterClient::setSnapshotterClientOptions(const SnapshotterClientOptio auto future_result = rclcpp::spin_until_future_complete(this->get_node_base_interface(), result_future); - if (future_result == rclcpp::FutureReturnCode::SUCCESS) { + if (future_result != rclcpp::FutureReturnCode::SUCCESS) { RCLCPP_ERROR(get_logger(), "Calling the service failed."); } else { auto result = result_future.get(); @@ -823,14 +823,14 @@ void SnapshotterClient::setSnapshotterClientOptions(const SnapshotterClientOptio }; } - SetBool::Request::SharedPtr req; + SetBool::Request::SharedPtr req = std::make_shared(); req->data = (opts.action_ == SnapshotterClientOptions::RESUME); auto result_future = client->async_send_request(req); auto future_result = rclcpp::spin_until_future_complete(this->get_node_base_interface(), result_future); - if (future_result == rclcpp::FutureReturnCode::SUCCESS) { + if (future_result != rclcpp::FutureReturnCode::SUCCESS) { RCLCPP_ERROR(get_logger(), "Calling the service failed."); } else { auto result = result_future.get(); @@ -852,4 +852,4 @@ void SnapshotterClient::setSnapshotterClientOptions(const SnapshotterClientOptio #include // NOLINT RCLCPP_COMPONENTS_REGISTER_NODE(rosbag2_snapshot::Snapshotter) -RCLCPP_COMPONENTS_REGISTER_NODE(rosbag2_snapshot::SnapshotterClient) +RCLCPP_COMPONENTS_REGISTER_NODE(rosbag2_snapshot::SnapshotterClient) \ No newline at end of file