|
| 1 | +# Simple colcon build and deploy |
| 2 | +version: 2.1 |
| 3 | + |
| 4 | +orbs: |
| 5 | + aws-s3: circleci/aws-s3@3.0.0 |
| 6 | + |
| 7 | +workflows: |
| 8 | + build, test and create: |
| 9 | + jobs: |
| 10 | + - build-test: |
| 11 | + filters: |
| 12 | + tags: |
| 13 | + ignore: /[0-9]*\.[0-9]*\.[0-9]/ |
| 14 | + context: |
| 15 | + - ROS Pipelines |
| 16 | + - OpenVPN |
| 17 | + - create: |
| 18 | + requires: |
| 19 | + - build-test |
| 20 | + context: |
| 21 | + - ROS Pipelines |
| 22 | + |
| 23 | + build, test, create and deploy: |
| 24 | + jobs: |
| 25 | + - build-test: |
| 26 | + filters: |
| 27 | + branches: |
| 28 | + ignore: /.*/ |
| 29 | + tags: |
| 30 | + only: /[0-9]*\.[0-9]*\.[0-9]/ |
| 31 | + context: |
| 32 | + - ROS Pipelines |
| 33 | + - OpenVPN |
| 34 | + - create: |
| 35 | + filters: |
| 36 | + branches: |
| 37 | + ignore: /.*/ |
| 38 | + tags: |
| 39 | + only: /[0-9]*\.[0-9]*\.[0-9]/ |
| 40 | + requires: |
| 41 | + - build-test |
| 42 | + context: |
| 43 | + - ROS Pipelines |
| 44 | + - deploy: |
| 45 | + filters: |
| 46 | + branches: |
| 47 | + ignore: /.*/ |
| 48 | + tags: |
| 49 | + only: /[0-9]*\.[0-9]*\.[0-9]/ |
| 50 | + requires: |
| 51 | + - build-test |
| 52 | + - create |
| 53 | + context: |
| 54 | + - AWS ECR Access |
| 55 | + |
| 56 | +executors: |
| 57 | + simple-machine: |
| 58 | + machine: |
| 59 | + image: ubuntu-2004:202111-02 |
| 60 | + working_directory: ~/workspace/src/linak_actuator_modbus |
| 61 | + simple-docker: |
| 62 | + docker: |
| 63 | + - image: gallaisoma/ros2-galactic:latest |
| 64 | + working_directory: ~/workspace/src/cmr_tests_utils |
| 65 | +jobs: |
| 66 | + build-test: |
| 67 | + executor: simple-machine |
| 68 | + steps: |
| 69 | + - checkout: |
| 70 | + path: ~/workspace/src/$CIRCLE_PROJECT_REPONAME |
| 71 | + - run: |
| 72 | + name: Install OpenVPN3 |
| 73 | + command: | |
| 74 | + sudo apt update && sudo apt install apt-transport-https |
| 75 | + sudo wget https://swupdate.openvpn.net/repos/openvpn-repo-pkg-key.pub |
| 76 | + sudo apt-key add openvpn-repo-pkg-key.pub |
| 77 | + sudo wget -O /etc/apt/sources.list.d/openvpn3.list https://swupdate.openvpn.net/community/openvpn3/repos/openvpn3-focal.list |
| 78 | + sudo apt update && sudo apt install openvpn3 |
| 79 | + - run: |
| 80 | + name: VPN setup |
| 81 | + background: true |
| 82 | + command: | |
| 83 | + echo $VPN_CLIENT_CONFIG | base64 --decode > /tmp/config.ovpn |
| 84 | + phone_home=$(ss -Hnto state established '( sport = :ssh )' | head -n1 | awk '{ split($4, a, ":"); print a[1] }') |
| 85 | + echo $phone_home |
| 86 | + if [ -n "$phone_home" ]; then |
| 87 | + echo -e "\nroute $phone_home 255.255.255.255 net_gateway" >> /tmp/config.ovpn |
| 88 | + fi |
| 89 | + echo "\nroute 169.254.0.0 255.255.0.0 net_gateway" >> /tmp/config.ovpn |
| 90 | + sudo openvpn3 session-start --config /tmp/config.ovpn > /tmp/openvpn.log |
| 91 | + - run: |
| 92 | + name: Wait for the connection to be established and check |
| 93 | + command: | |
| 94 | + until sudo openvpn3 sessions-list|grep "Client connected"; do |
| 95 | + echo "Attempting to connect to VPN server..." |
| 96 | + sleep 1; |
| 97 | + done |
| 98 | + - run: |
| 99 | + name: Start Docker |
| 100 | + command: | |
| 101 | + docker pull gallaisoma/ros2-galactic:latest |
| 102 | + docker run -e ROSDISTRO_INDEX_URL=$ROSDISTRO_INDEX_URL -v ~/workspace/src/$CIRCLE_PROJECT_REPONAME:/root/workspace/src/$CIRCLE_PROJECT_REPONAME --name ci_fun -dit gallaisoma/ros2-galactic:latest |
| 103 | + - run: |
| 104 | + name: Run build and test inside docker |
| 105 | + command: docker exec -it ci_fun /bin/bash -c " source /opt/ros/galactic/setup.bash && cd ~/workspace && curl -o aptly_repo_signing.key http://172.31.46.198/aptly_repo_signing.key && apt-key add aptly_repo_signing.key && echo 'deb http://172.31.46.198/ focal main' >> /etc/apt/sources.list && apt update && rosdep init && rosdep update && rosdep install --from-paths src --ignore-src -r -y && colcon build --packages-up-to $CIRCLE_PROJECT_REPONAME && source install/setup.bash " |
| 106 | + - run: |
| 107 | + name: Disconnect from OpenVPN |
| 108 | + command: | |
| 109 | + SESSION_PATH=$(sudo openvpn3 sessions-list | grep Path | awk -F': ' '{print $2}') |
| 110 | + echo $SESSION_PATH |
| 111 | + sudo openvpn3 session-manage --session-path $SESSION_PATH --disconnect |
| 112 | + when: always |
| 113 | + |
| 114 | + - persist_to_workspace: |
| 115 | + root: ../.. |
| 116 | + paths: |
| 117 | + - . |
| 118 | + create: |
| 119 | + executor: simple-docker |
| 120 | + steps: |
| 121 | + - attach_workspace: |
| 122 | + at: ~/workspace |
| 123 | + - run: |
| 124 | + name: Deploy the deb artifact |
| 125 | + command: | |
| 126 | + cd ~/workspace |
| 127 | + mkdir ~/.ssh/ |
| 128 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 129 | + git clone git@github.com:cmrobotics/pipeline_scripts.git |
| 130 | + cd ~/workspace/pipeline_scripts |
| 131 | + ./binarization.sh |
| 132 | +
|
| 133 | + - store_artifacts: |
| 134 | + path: ~/workspace/src/ros-galactic-cmr_tests_utils.deb |
| 135 | + |
| 136 | + - persist_to_workspace: |
| 137 | + root: ~/workspace |
| 138 | + paths: |
| 139 | + - src/ros-galactic-cmr_tests_utils.deb |
| 140 | + |
| 141 | + deploy: |
| 142 | + executor: simple-docker |
| 143 | + steps: |
| 144 | + - attach_workspace: |
| 145 | + at: ~/workspace |
| 146 | + - run: |
| 147 | + name: Renaming with tag name |
| 148 | + command: mv ~/workspace/src/ros-galactic-$CIRCLE_PROJECT_REPONAME.deb ~/workspace/src/ros-galactic-$CIRCLE_PROJECT_REPONAME-$CIRCLE_TAG.deb |
| 149 | + - aws-s3/copy: |
| 150 | + arguments: | |
| 151 | + --acl private |
| 152 | + aws-access-key-id: AWS_ACCESS_KEY_ID |
| 153 | + aws-region: AWS_REGION |
| 154 | + aws-secret-access-key: AWS_SECRET_ACCESS_KEY |
| 155 | + from: ~/workspace/src/ros-galactic-$CIRCLE_PROJECT_REPONAME-$CIRCLE_TAG.deb |
| 156 | + to: 's3://aptly-debian-files/ros-galactic-$CIRCLE_PROJECT_REPONAME.deb' |
| 157 | + |
0 commit comments