-
Notifications
You must be signed in to change notification settings - Fork 5
218 lines (212 loc) · 8.46 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: CI
on: [push, pull_request, workflow_dispatch]
env:
REGISTRY: ghcr.io
jobs:
linting_python_black:
name: Black Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: --check --diff --color -l 120
linting_shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Shellcheck
run: |
shopt -s globstar
shellcheck --version
shellcheck **/*.bash **/*.sh
docker_generation_tue_env:
name: Docker Generation tue-env
runs-on: ubuntu-latest
needs: [linting_python_black, linting_shellcheck]
strategy:
fail-fast: false
matrix:
include:
- ros-distro: noetic
ros-version: 1
platform: "amd64"
base-image: "ubuntu:20.04"
- ros-distro: humble
ros-version: 2
platform: "amd64"
base-image: "ubuntu:22.04"
- ros-distro: rolling
ros-version: 2
platform: "amd64"
base-image: "ubuntu:22.04"
flavor: u22
- ros-distro: rolling
ros-version: 2
platform: "amd64"
base-image: "ubuntu:24.04"
flavor: u24
create-venv: true
docker-user-id: 1001
- ros-distro: noetic
ros-version: 1
platform: "amd64"
base-image: "nvidia/cuda:12.1.1-devel-ubuntu20.04"
flavor: cu12.1.1-devel
default-branch-only: true
maximize-build-space: true
outputs:
key: ${{ steps.artifacts.outputs.key }}
tag: ${{ steps.script.outputs.tag }}
steps:
- name: Maximize build space
if: ${{ matrix.maximize-build-space == true }}
uses: easimon/maximize-build-space@master
with:
build-mount-path: /var/lib/docker/
root-reserve-mb: 2048
temp-reserve-mb: 512
- name: Restart docker
run: sudo service docker restart
- uses: actions/checkout@v4
- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
# Comment out when generating arm64
#- name: Install QEMU
# run: |
# sudo apt update -qq
# sudo apt install -qq -y qemu qemu-user-static
- name: Docker info
run: docker info
- name: Script
id: script
run: |
#! /usr/bin/env bash
GITHUB_REF=${GITHUB_REF#refs/heads/}
GITHUB_REF=${GITHUB_REF#refs/tags/}
BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF}}
# shellcheck disable=SC1083,SC2296
PULLREQUEST=${{ github.event.number }}
PULLREQUEST=${PULLREQUEST:-false}
# shellcheck disable=SC1083,SC2296
PUSH_IMAGE=${{ matrix.push-image }}
[[ ${PULLREQUEST} != "false" ]] && PUSH_IMAGE="false"
PUSH_IMAGE=${PUSH_IMAGE:-true}
# shellcheck disable=SC1083,SC2296
DEFAULT_BRANCH=${{ github.event.repository.default_branch }}
if [[ "$BRANCH" == "$DEFAULT_BRANCH" ]]
then
IMAGE_TAG="latest"
else
IMAGE_TAG="$(echo "${BRANCH}" | tr '[:upper:]' '[:lower:]' | sed -e 's:/:_:g')"
fi
# shellcheck disable=SC1083,SC2296
IMAGE_FLAVOR=${{ matrix.flavor }}
IMAGE_FLAVOR=${IMAGE_FLAVOR:+"-${IMAGE_FLAVOR}"}
# shellcheck disable=SC2296
TARGET_IMAGE="${{ env.REGISTRY }}/tue-robotics/tue-env-ros-${{ matrix.ros-distro }}${IMAGE_FLAVOR}:${IMAGE_TAG}-${{ matrix.platform }}"
SSH_KNOWN_HOSTS="github.com"
SSH_ARGS=()
if [[ -n "${SSH_KEY}" ]]
then
SSH_KEY_PATH="${HOME}"/.ssh/ci_ssh_key
echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m"
mkdir -p "${HOME}"/.ssh
echo "${SSH_KEY}" > "${SSH_KEY_PATH}"
chmod 600 "${SSH_KEY_PATH}"
eval "$(ssh-agent -s)"
SSH_ARGS+=("--ssh" "--ssh-key=${SSH_KEY_PATH}")
fi
if [[ -n "${SSH_KNOWN_HOSTS}" ]]
then
echo -e "\e[35;1mmkdir -p ${HOME}/.ssh\e[0m"
mkdir -p "${HOME}"/.ssh
for host in ${SSH_KNOWN_HOSTS}
do
echo -e "\e[35;1mssh-keyscan -t rsa -H \"${host}\" 2>&1 | tee -a ${HOME}/.ssh/known_hosts\e[0m"
ssh-keyscan -t rsa -H "${host}" 2>&1 | tee -a "${HOME}"/.ssh/known_hosts
done
fi
# shellcheck disable=SC1083,SC2296
CREATE_VENV=${{ matrix.create-venv }}
CREATE_VENV=${CREATE_VENV:-false}
# shellcheck disable=SC1083,SC2296
VENV_INCLUDE_SYSTEM_SITE=${{ matrix.venv-include-system-site }}
VENV_INCLUDE_SYSTEM_SITE=${VENV_INCLUDE_SYSTEM_SITE:-true}
# shellcheck disable=SC1083,SC2296
DOCKER_USER=${{ matrix.docker-user }}
DOCKER_USER=${DOCKER_USER:-docker}
# shellcheck disable=SC1083,SC2296
DOCKER_USER_ID=${{ matrix.docker-user-id }}
DOCKER_USER_ID=${DOCKER_USER_ID:-1000}
# shellcheck disable=SC2296
ci/build-docker-image.sh \
--registry="${{ env.REGISTRY }}" \
--image="${TARGET_IMAGE}" \
--branch="${BRANCH}" \
--commit="${GITHUB_SHA}" \
--push_image="${PUSH_IMAGE}" \
--pull_request="${PULLREQUEST}" \
--ros_version="${{ matrix.ros-version }}" \
--ros_distro="${{ matrix.ros-distro }}" \
--base_image="${{ matrix.base-image }}" \
--docker_file="dockerfiles/tue-env.Dockerfile" \
--oauth2_token="${{ secrets.OAUTH2_TOKEN }}" \
--platforms="${{ matrix.platform }}" \
--create-virtualenv="${CREATE_VENV}" \
--virtualenv-include-system-site-packages="${VENV_INCLUDE_SYSTEM_SITE}" \
--docker_user="${DOCKER_USER}" \
--docker_user_id="${DOCKER_USER_ID}" \
"${SSH_ARGS[@]}"
echo -e "\e[35;1mimage=${TARGET_IMAGE} >> \${GITHUB_OUTPUT}\e[0m"
echo "image=${TARGET_IMAGE}" >> "${GITHUB_OUTPUT}"
echo -e "\e[35;1mtag=${IMAGE_TAG} >> \${GITHUB_OUTPUT}\e[0m"
echo "tag=${IMAGE_TAG}" >> "${GITHUB_OUTPUT}"
- name: Generate artifacts
id: artifacts
if: github.event_name != 'pull_request'
run: |
MATRIX_OUTPUT_KEY=image
echo "${{ steps.script.outputs.image }}" > "${MATRIX_OUTPUT_KEY}"
sha256sum "${MATRIX_OUTPUT_KEY}" | cut -d " " -f 1 | xargs -I{} echo "artifact={}" >> $GITHUB_OUTPUT
echo -e "\e[35;1mkey=${MATRIX_OUTPUT_KEY} >> \${GITHUB_OUTPUT}\e[0m"
echo "key=${MATRIX_OUTPUT_KEY}" >> $GITHUB_OUTPUT
- name: Write image name
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifacts.outputs.artifact }}
path: ${{ steps.artifacts.outputs.key }}
retention-days: 1
docker_manifest_generation_tue_env:
name: Docker Manifest Generation tue-env
runs-on: ubuntu-latest
needs: [docker_generation_tue_env]
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
- name: Read matrix output
id: read
run: |
result="$(find . -name ${{ needs.docker_generation_tue_env.outputs.key }} -exec cat {} \; | jq --slurp --raw-input 'split("\n")[:-1] | .[] | split(":") | {(.[0]) : [(.[1])]}' | jq -cs '[.[] | to_entries] | flatten | reduce .[] as $dot ({}; .[$dot.key] += $dot.value) | { ${{ needs.docker_generation_tue_env.outputs.key }} : . }' )"
echo -e "\e[35;1mresult=${result} >> \${GITHUB_OUTPUT}\e[0m"
echo "result=${result}" >> $GITHUB_OUTPUT
- name: Generate new manifest files
run: |
ci/docker-manifest-generator.sh \
--images-json='${{ toJSON(steps.read.outputs.result) }}' \
--tag="${{ needs.docker_generation_tue_env.outputs.tag }}"