Skip to content

Commit 5c8be3f

Browse files
committed
ci(stretch3_ws): Add CI build
1 parent ba4ec45 commit 5c8be3f

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Build Docker Image for stretch3-ws
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build Docker Image for template-ws"]
6+
types: [completed]
7+
8+
jobs:
9+
paths-filter:
10+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
11+
runs-on: ubuntu-latest
12+
outputs:
13+
results: ${{ steps.filter.outputs.results }}
14+
original_ref: ${{ steps.set-ref.outputs.original_ref }}
15+
steps:
16+
# Ref: https://github.com/dorny/paths-filter/issues/147#issuecomment-1287800590
17+
- name: Download a single artifact
18+
uses: dawidd6/action-download-artifact@v7
19+
with:
20+
workflow: build-template-ws.yaml
21+
name: original-refs
22+
workflow_conclusion: success
23+
- name: set REF_BASE to env
24+
id: set-ref
25+
run: |
26+
echo "BASE=$(cat base.txt)" >> $GITHUB_ENV
27+
echo "CURRENT_BRANCH=$(cat current-branch.txt)" >> $GITHUB_ENV
28+
echo "original_ref=$(cat current-branch.txt)" >> $GITHUB_OUTPUT
29+
- uses: actions/checkout@v4
30+
- uses: dorny/paths-filter@v3
31+
id: filter
32+
with:
33+
base: ${{ env.BASE }}
34+
ref: ${{ env.CURRENT_BRANCH }}
35+
filters: |
36+
results:
37+
- docker_modules/**
38+
- .github/workflows/build-stretch3-ws.yaml
39+
- stretch3_ws/docker/Dockerfile
40+
- stretch3_ws/docker/.dockerignore
41+
- stretch3_ws/docker/.bashrc
42+
- name: Changes matched
43+
if: steps.filter.outputs.results == 'true'
44+
run: echo "Changes matched, will build image"
45+
- name: Changes didn't match
46+
if: steps.filter.outputs.results != 'true'
47+
run: echo "Changes didn't match, will NOT build image"
48+
docker:
49+
needs: paths-filter
50+
if: ${{ needs.paths-filter.outputs.results == 'true' || startsWith(needs.paths-filter.outputs.original_ref, 'refs/tags/') }}
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Maximize build space
54+
uses: easimon/maximize-build-space@master
55+
with:
56+
build-mount-path: /var/lib/docker/
57+
remove-dotnet: 'true'
58+
remove-android: 'true'
59+
remove-haskell: 'true'
60+
remove-codeql: 'true'
61+
remove-docker-images: 'true'
62+
- name: Restart docker
63+
run: sudo service docker restart
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
- name: Run post install script
67+
run: scripts/post_install.sh
68+
- name: Set up QEMU
69+
uses: docker/setup-qemu-action@v3
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v3
72+
- # Ref: https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-a-registry-using-a-personal-access-token
73+
name: Prepare tag name as environment variable
74+
run: |
75+
# Use the original ref from the triggering workflow
76+
ORIGINAL_REF="${{ needs.paths-filter.outputs.original_ref }}"
77+
# This strips the git ref prefix from the version.
78+
VERSION=$(echo "$ORIGINAL_REF" | sed -e 's,.*/\(.*\),\1,')
79+
# This strips the "v" prefix from the tag name.
80+
[[ "$ORIGINAL_REF" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
81+
# This uses the Docker `latest` tag convention.
82+
[ "$VERSION" == "main" ] && VERSION=latest
83+
# Output the environment variable
84+
# Ref: https://stackoverflow.com/a/57989070
85+
echo "VERSION=$VERSION" >> $GITHUB_ENV
86+
# Print for debugging purpose
87+
echo "VERSION=$VERSION"
88+
- name: Docker meta
89+
id: meta
90+
# Ref: https://github.com/docker/metadata-action
91+
uses: docker/metadata-action@v5
92+
with:
93+
# Link: https://hub.docker.com/repository/docker/j3soon/ros2-stretch3-ws/tags
94+
images: j3soon/ros2-stretch3-ws
95+
tags: |
96+
type=raw,value={{date 'YYYYMMDD'}}
97+
type=raw,value=${{ env.VERSION }}
98+
- name: Login to Docker Hub
99+
uses: docker/login-action@v3
100+
with:
101+
username: j3soon
102+
password: ${{ secrets.DOCKERHUB_TOKEN }}
103+
- name: Pull j3soon/ros2-template-ws (amd64)
104+
run: docker pull --platform linux/amd64 j3soon/ros2-template-ws
105+
- name: Pull j3soon/ros2-template-ws (arm64)
106+
run: docker pull --platform linux/arm64 j3soon/ros2-template-ws
107+
- name: Build image
108+
uses: docker/build-push-action@v6
109+
with:
110+
context: stretch3_ws/docker
111+
cache-from: |
112+
j3soon/ros2-template-ws:buildcache-amd64
113+
j3soon/ros2-template-ws:buildcache-arm64
114+
platforms: linux/amd64
115+
tags: ${{ steps.meta.outputs.tags }}
116+
- name: Push amd64 cache
117+
uses: docker/build-push-action@v6
118+
with:
119+
context: stretch3_ws/docker
120+
cache-from: |
121+
j3soon/ros2-template-ws:buildcache-amd64
122+
j3soon/ros2-template-ws:buildcache-arm64
123+
cache-to: type=registry,ref=j3soon/ros2-stretch3-ws:buildcache-amd64,mode=max
124+
platforms: linux/amd64
125+
tags: ${{ steps.meta.outputs.tags }}
126+
- name: Push image
127+
uses: docker/build-push-action@v6
128+
with:
129+
context: stretch3_ws/docker
130+
cache-from: |
131+
j3soon/ros2-template-ws:buildcache-amd64
132+
j3soon/ros2-template-ws:buildcache-arm64
133+
platforms: linux/amd64
134+
push: true
135+
tags: ${{ steps.meta.outputs.tags }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The docker image of the template workspace is share by most of the workspace, al
7575
| [Tesollo Delto Gripper](https://j3soon.github.io/ros2-essentials/delto-gripper-ws/) | ✔️ | ❌️ | Simulation only | [Yu-Zhong Chen](https://github.com/YuZhong-Chen) |
7676
| [Unitree Go2](https://j3soon.github.io/ros2-essentials/go2-ws/) | ✔️ | ❌️ | Simulation only | [Yu-Zhong Chen](https://github.com/YuZhong-Chen), [Assume Zhan](https://github.com/Assume-Zhan), [Johnson Sun](https://github.com/j3soon) |
7777
| [Unitree H1](https://j3soon.github.io/ros2-essentials/h1-ws/) | ✔️ | ❌️ | Simulation only | [Johnson Sun](https://github.com/j3soon) |
78+
| [Hello Robot Stretch 3](https://j3soon.github.io/ros2-essentials/stretch3-ws/) | ✔️ | ❌️ | Simulation only | [@JustinShih0918](https://github.com/JustinShih0918), [Johnson Sun](https://github.com/j3soon) |
7879

7980
If you have trouble using a workspace, please [open an issue](https://github.com/j3soon/ros2-essentials/issues) and tag the current maintainers mentioned above.
8081

0 commit comments

Comments
 (0)