Build and Test #276
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test | |
on: | |
pull_request: | |
branches: | |
- master | |
paths: | |
- "**/Dockerfile" | |
- "**/entrypoint.sh" | |
- ".github/workflows/test.yml" | |
schedule: | |
- cron: "0 2 * * 0" # Weekly on Sundays at 02:00 | |
workflow_dispatch: | |
env: | |
DOCKER_USERNAME: tiryoh | |
DOCKER_IMAGENAME: ros2-desktop-vnc | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
ros-distro: [foxy, humble, iron, rolling] | |
arch: [arm64, amd64] | |
# runs-on: self-hosted | |
runs-on: ubuntu-latest | |
timeout-minutes: 120 | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: docker/setup-qemu-action@v2 | |
- name: Prepare Docker metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGENAME }} | |
tags: | | |
type=raw,value=${{ matrix.ros-distro }}-${{ matrix.arch }}-{{date 'YYYYMMDDTHHmm'}} | |
type=raw,value=${{ matrix.ros-distro }}-${{ matrix.arch }} | |
flavor: | | |
latest=false | |
prefix= | |
suffix= | |
- name: Parse docker build option | |
id: docker-build-option | |
run: | | |
LABELS=$(cat << EOF | grep -E "=." | sed -e "s/org\./--label org./g" | sed -e "s/--label org\(.*\)=\(.*\)$/--label org\1='\2'/g" | |
${{ steps.meta.outputs.labels }} | |
EOF | |
) | |
echo $LABELS | |
echo "labels=${LABELS}" >> $GITHUB_OUTPUT | |
- name: Build docker image | |
env: | |
DOCKER_TAGNAME: ${{ matrix.ros-distro }}-${{ matrix.arch }} | |
run: | | |
if [[ -d ${DOCKER_TAGNAME%-amd64} ]]; then | |
cd ${DOCKER_TAGNAME%-amd64} && docker buildx build --no-cache --platform=linux/${{ matrix.arch }} --progress=plain ${{ steps.docker-build-option.outputs.labels }} -t $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME . | |
elif [[ -d ${DOCKER_TAGNAME%-arm64} ]]; then | |
cd ${DOCKER_TAGNAME%-arm64} && docker buildx build --no-cache --platform=linux/${{ matrix.arch }} --progress=plain ${{ steps.docker-build-option.outputs.labels }} -t $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME . | |
else | |
exit 1 | |
fi | |
- name: List docker images | |
run: | | |
mkdir -p build_log | |
docker image ls "$DOCKER_USERNAME/*" | tee ./build_log/docker_images.txt | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
with: | |
image-ref: '${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGENAME }}:${{ matrix.ros-distro }}-${{ matrix.arch }}' | |
exit-code: '0' | |
vuln-type: 'os,library' | |
severity: 'CRITICAL,HIGH' | |
format: 'template' | |
template: '@/contrib/sarif.tpl' | |
output: 'trivy-results.sarif' | |
timeout: '20m' | |
- name: Cleanup docker image cache | |
env: | |
DOCKER_TAGNAME: ${{ matrix.ros-distro }}-${{ matrix.arch }} | |
run: | | |
docker rmi $DOCKER_USERNAME/$DOCKER_IMAGENAME:$DOCKER_TAGNAME | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v2 | |
with: | |
sarif_file: 'trivy-results.sarif' | |
wait-for-processing: true |