Skip to content

Commit 9fd120f

Browse files
authored
feat: Speedup of deployment (#11)
2 parents 2424bfb + 931ce32 commit 9fd120f

File tree

4 files changed

+159
-15
lines changed

4 files changed

+159
-15
lines changed

.ci/install.bash

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#! /usr/bin/env bash
2+
# shellcheck disable=SC2016
3+
4+
# Stop on errors
5+
set -o errexit
6+
7+
BASEDIR=$(dirname "$0")
8+
9+
# Standard argument parsing, example: install-package --branch=master --package=ros_robot
10+
for i in "$@"
11+
do
12+
case $i in
13+
-b=* | --branch=* )
14+
# BRANCH should allways be targetbranch
15+
BRANCH="${i#*=}" ;;
16+
17+
-i=* | --image=* )
18+
IMAGE_NAME="${i#*=}" ;;
19+
20+
--ssh )
21+
USE_SSH=true ;;
22+
23+
--ssh-key=* )
24+
SSH_KEY="${i#*=}" ;;
25+
26+
* )
27+
# unknown option
28+
if [[ -n "$i" ]]
29+
then
30+
echo -e "\e[35m\e[1m Unknown input argument '$i'. Check CI .yml file \e[0m"
31+
exit 1
32+
fi ;;
33+
esac
34+
shift
35+
done
36+
37+
echo -e "\e[35m\e[1m BRANCH = ${BRANCH} \e[0m"
38+
39+
# Set default value for IMAGE_NAME
40+
[ -z "$IMAGE_NAME" ] && IMAGE_NAME='tuerobotics/tue-env'
41+
echo -e "\e[35m\e[1m IMAGE_NAME = ${IMAGE_NAME} \e[0m"
42+
43+
# Determine docker tag if the same branch exists there
44+
BRANCH_TAG=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]' | sed -e 's:/:_:g')
45+
46+
# Set the default fallback branch to latest
47+
MASTER_TAG="latest"
48+
49+
# Remove any previously started containers if they exist (if not exist, still return true to let the script continue)
50+
docker stop tue-env &> /dev/null || true
51+
docker rm tue-env &> /dev/null || true
52+
53+
# Pull the identical branch name from dockerhub if exist, use master as fallback
54+
echo -e "\e[35m\e[1m Trying to fetch docker image: $IMAGE_NAME:$BRANCH_TAG \e[0m"
55+
if ! docker pull "$IMAGE_NAME:$BRANCH_TAG"
56+
then
57+
echo -e "\e[35m\e[1m No worries, we just test against the master branch: $IMAGE_NAME:$MASTER_TAG \e[0m"
58+
docker pull "$IMAGE_NAME":"$MASTER_TAG"
59+
BRANCH_TAG=$MASTER_TAG
60+
fi
61+
62+
if [ -f ~/.ssh/known_hosts ]
63+
then
64+
MERGE_KNOWN_HOSTS="true"
65+
DOCKER_MOUNT_KNOWN_HOSTS_ARGS="--mount type=bind,source=$HOME/.ssh/known_hosts,target=/tmp/known_hosts_extra"
66+
fi
67+
68+
# Run the docker image along with setting new environment variables
69+
# shellcheck disable=SC2086
70+
docker run --detach --interactive --tty -e CI="true" -e BRANCH="$BRANCH" --name tue-env $DOCKER_MOUNT_KNOWN_HOSTS_ARGS "$IMAGE_NAME:$BRANCH_TAG"
71+
72+
if [ "$MERGE_KNOWN_HOSTS" == "true" ]
73+
then
74+
docker exec -t tue-env bash -c "sudo chown 1000:1000 /tmp/known_hosts_extra && ~/.tue/ci/ssh-merge-known_hosts.py ~/.ssh/known_hosts /tmp/known_hosts_extra --output ~/.ssh/known_hosts"
75+
fi
76+
77+
if [ "$USE_SSH" == "true" ]
78+
then
79+
docker exec -t tue-env bash -c "echo '$SSH_KEY' > ~/.ssh/id_rsa && chmod 700 ~/.ssh/id_rsa"
80+
docker exec -t tue-env bash -c "eval $(ssh-agent -s)"
81+
fi
82+
83+
echo -e "\e[35m\e[1m tue-get install tue-documentation-github --no-ros-deps --doc-depend\e[0m"
84+
docker exec -t tue-env bash -c 'source ~/.bashrc; tue-get install tue-documentation-github --no-ros-deps --doc-depend'
85+
86+
DOCKER_HOME=$(docker exec -t tue-env bash -c 'source ~/.bashrc; echo "$HOME"' | tr -d '\r')
87+
88+
echo -e "\e[35m\e[1m docker cp ${BASEDIR}/get_message_packages.py tue-env:${DOCKER_HOME}\e[0m"
89+
docker cp "${BASEDIR}"/get_message_packages.py tue-env:"${DOCKER_HOME}"
90+
91+
echo -e "\e[35m\e[1m ~/get_message_packages.py base_local_planner costmap_2d\e[0m"
92+
MSG_PKGS=($(docker exec -t tue-env bash -c 'source ~/.bashrc; ${HOME}/get_message_packages.py base_local_planner costmap_2d' | tr -d '\r')) # Skip base_local_planner and costmap_2d as these take too much time
93+
MSG_TARGETS=(${MSG_PKGS[@]/#/ros-})
94+
echo -e "\e[35m\e[1m MSG_PKGS= " "${MSG_PKGS[@]}" "\e[0m"
95+
96+
echo -e "\e[35m\e[1m tue-get install ros-python_orocos_kdl " "${MSG_TARGETS[@]}" "\e[0m"
97+
# shellcheck disable=SC2145
98+
docker exec -t tue-env bash -c "source ~/.bashrc; tue-get install ros-python_orocos_kdl ${MSG_TARGETS[@]}" # Needs to be installed fully as it needs to be build to generate docs
99+
100+
echo -e "\e[35m\e[1m tue-make --no-status python_orocos_kdl " "${MSG_PKGS[@]}" "\e[0m"
101+
# shellcheck disable=SC2145
102+
docker exec -t tue-env bash -c "source ~/.bashrc; tue-make --no-status python_orocos_kdl ${MSG_PKGS[@]}" # Needs to be build to generate docs

.ci/pre_deploy.bash

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env bash
2+
# shellcheck disable=SC2016
3+
4+
# Stop on errors
5+
set -o errexit
6+
7+
# Standard argument parsing, example: install-package --branch=master --package=ros_robot
8+
for i in "$@"
9+
do
10+
case $i in
11+
* )
12+
# unknown option
13+
if [[ -n "$i" ]]
14+
then
15+
echo -e "\e[35m\e[1m Unknown input argument '$i'. Check CI .yml file \e[0m"
16+
exit 1
17+
fi ;;
18+
esac
19+
shift
20+
done
21+
22+
TUE_SYSTEM_DIR=$(docker exec -t tue-env bash -c 'source ~/.bashrc; echo "$TUE_SYSTEM_DIR"' | tr -d '\r')
23+
24+
echo -e "\e[35m\e[1m docker cp tue-env:${TUE_SYSTEM_DIR}/docs .\e[0m"
25+
docker cp tue-env:"${TUE_SYSTEM_DIR}"/docs .

.ci/script.bash

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env bash
2+
# shellcheck disable=SC2016
3+
4+
# Stop on errors
5+
set -o errexit
6+
7+
# Standard argument parsing, example: install-package --branch=master --package=ros_robot
8+
for i in "$@"
9+
do
10+
case $i in
11+
* )
12+
# unknown option
13+
if [[ -n "$i" ]]
14+
then
15+
echo -e "\e[35m\e[1m Unknown input argument '$i'. Check CI .yml file \e[0m"
16+
exit 1
17+
fi ;;
18+
esac
19+
shift
20+
done
21+
22+
echo -e "\e[35m\e[1m tue-make-documentation --no-status\e[0m"
23+
docker exec -t tue-env bash -c 'source ~/.bashrc; tue-make-documentation --no-status'

.github/workflows/main.yml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
defaults:
1010
run:
11-
shell: bash --noprofile --norc -o pipefail {0}
11+
shell: bash
1212

1313
jobs:
1414
deployment:
@@ -18,23 +18,17 @@ jobs:
1818
- uses: actions/checkout@v2
1919
- name: Install
2020
run: |
21-
source <(wget -O - https://raw.githubusercontent.com/tue-robotics/tue-env/master/installer/bootstrap.bash)
22-
tue-get install tue-documentation-github --no-ros-deps --doc-depend
23-
MSG_PKGS=($(./.ci/get_message_packages.py base_local_planner costmap_2d)) # Skip base_local_planner and costmap_2d as these take too much time
24-
echo "MSG_PKGS= ${MSG_PKGS[@]}"
25-
MSG_TARGETS=(${MSG_PKGS[@]/#/ros-})
26-
tue-get install ros-python_orocos_kdl ${MSG_TARGETS[@]} # Needs to be installed fully as it needs to be build to generate docs
21+
GITHUB_REF=${GITHUB_REF#refs/heads/}
22+
GITHUB_REF=${GITHUB_REF#refs/tags/}
23+
BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF}}
24+
mkdir -p ${HOME}/.ssh
25+
ssh-keyscan -t rsa -H "github.com" 2>&1 | tee -a "${HOME}"/.ssh/known_hosts
26+
.ci/install.bash --branch=$BRANCH
2727
- name: Script
28-
run: |
29-
source ~/.tue/setup.bash
30-
tue-make --no-status python_orocos_kdl ${MSG_PKGS[@]} # Needs to be build to generate docs
31-
source ~/.tue/setup.bash # Source the workspace
32-
tue-make-documentation --no-status
28+
run: .ci/script.bash
3329
- name: Before Deploy
3430
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && github.ref == 'refs/heads/master' }}
35-
run: |
36-
source ~/.tue/setup.bash
37-
cp -r $TUE_SYSTEM_DIR/docs .
31+
run: .ci/pre_deploy.bash
3832
- name: Deploy
3933
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && github.ref == 'refs/heads/master' }}
4034
uses: peaceiris/actions-gh-pages@v3

0 commit comments

Comments
 (0)