-
Notifications
You must be signed in to change notification settings - Fork 5
163 lines (157 loc) · 6.11 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
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"
- ros-distro: galactic
ros-version: 2
platform: "amd64"
- ros-distro: humble
ros-version: 2
platform: "amd64"
base-image: "ubuntu:22.04"
outputs:
key: ${{ steps.artifacts.outputs.key }}
tag: ${{ steps.script.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Login to Docker registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 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: |
GITHUB_REF=${GITHUB_REF#refs/heads/}
GITHUB_REF=${GITHUB_REF#refs/tags/}
BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF}}
PULLREQUEST=${{ github.event.number }}
PULLREQUEST=${PULLREQUEST:-false}
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
IMAGE_FLAVOR=${{ matrix.flavor }}
IMAGE_FLAVOR=${IMAGE_FLAVOR:+"-${IMAGE_FLAVOR}"}
TARGET_IMAGE="${{ env.REGISTRY }}/tue-robotics/tue-env-ros-${{ matrix.ros-distro }}${IMAGE_FLAVOR}:${IMAGE_TAG}-${{ matrix.platform }}"
SSH_KEY="${{ secrets.SSH_DEPLOY_KEY }}"
SSH_KNOWN_HOSTS="github.com"
SSH_ARG=()
if [[ -n "${SSH_KEY}" ]]
then
SSH_KEY_PATH="${HOME}/.ssh/ci_ssh_key"
mkdir -p "${HOME}"/.ssh
echo "${SSH_KEY}" > "${SSH_KEY_PATH}"
chmod 600 "${SSH_KEY_PATH}"
eval $(ssh-agent -s)
SSH_ARG+=("--ssh" "--ssh-key=${SSH_KEY_PATH}")
fi
if [[ -n "${SSH_KNOWN_HOSTS}" ]]
then
echo -e "\e[35m\e[1mmkdir -p ${HOME}/.ssh\e[0m"
mkdir -p ${HOME}/.ssh
for host in ${SSH_KNOWN_HOSTS}
do
echo -e "\e[35m\e[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
ci/build-docker-image.sh \
--image="${TARGET_IMAGE}" \
--branch="${BRANCH}" \
--commit="${GITHUB_SHA}" \
--push_image="true" \
--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 }}" \
"${SSH_ARG[@]}"
echo -e "\e[35m\e[1mimage=${TARGET_IMAGE} >> \$GITHUB_OUTPUT\e[0m"
echo "image=${TARGET_IMAGE}" >> $GITHUB_OUTPUT
echo -e "\e[35m\e[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[35m\e[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@v3
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@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v3
- 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[35m\e[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 }}"