77 pull_request :
88 schedule :
99 - cron : " 0 11 * * *"
10+
11+ env :
12+ BASE_IMAGE_TAG : " ${{ github.head_ref || github.ref_name }}"
13+ VCS_REF : ${{ github.sha }}
14+ GHCR_IMAGE_NAME : " ghcr.io/space-ros/space-ros"
15+ DOCKER_HUB_USERNAME : osrfbot
16+ DOCKER_HUB_TOKEN : ${{ secrets.DOCKER_HUB_RW_TOKEN }}
17+ DOCKER_HUB_IMAGE_NAME : " osrf/space-ros"
18+
1019jobs :
11- build-test :
12- env :
13- VCS_REF : ${{ github.sha }}
20+ define-architecture-matrix :
21+ runs-on : ubuntu-latest
22+ outputs :
23+ architecture-matrix : ${{ steps.define-matrix.arch-matrix}}
24+ steps :
25+ - id : define-matrix
26+ run : |
27+ echo 'arch-matrix=[{"runner": "ubuntu-latest", "arch": "x86"}, {"runner": "ubuntu-20.04-arm", "arch": "arm64"},]' >> "$GITHUB_OUTPUT"
1428
29+ build-test :
1530 runs-on : ubuntu-latest
1631 steps :
1732 - name : Checkout
@@ -33,30 +48,41 @@ jobs:
3348 if-no-files-found : error
3449
3550 space-ros-main-image :
36- runs-on : ubuntu-latest
51+ needs : define-architecture-matrix
52+ strategy :
53+ matrix :
54+ arch-info : ${{ fromJSON(needs.define-architecture-matrix.outputs.architecture-matrix) }}
55+ # Keep in sync with the architecture-matrix arch values.
56+ outputs :
57+ output_x86 : ${{ steps.push_image.outputs.output_x86 }}
58+ output_arm64 : ${{ steps.push_image.outputs.output_arm64 }}
59+ runs-on : ${{ matrix.arch-info.runner }}
3760 env :
38- IMAGE_TAG : " ${{ github.head_ref || github.ref_name }}"
39- VCS_REF : ${{ github.sha }}
40- GHCR_IMAGE_NAME : " ghcr.io/space-ros/space-ros"
41- DOCKER_HUB_USERNAME : osrfbot
42- DOCKER_HUB_TOKEN : ${{ secrets.DOCKER_HUB_RW_TOKEN }}
43- DOCKER_HUB_IMAGE_NAME : " osrf/space-ros"
61+ ARCH_IMAGE_TAG : " ${{ env.BASE_IMAGE_TAG }}-${{ matrix.arch-info.arch }}"
4462
4563 steps :
4664 - name : Checkout
4765 uses : actions/checkout@v3
4866
4967 - name : Set up earthly
5068 run : |
51- sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly
69+ sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-${{ matrix.arch-info.arch }} -O /usr/local/bin/earthly
5270 sudo chmod 755 /usr/local/bin/earthly
5371
54- - name : Build spaceros image without pushing
72+ - name : Login to Docker Hub
73+ uses : docker/login-action@v3
74+ with :
75+ username : ${{ env.DOCKER_HUB_USERNAME }}
76+ password : ${{ env.DOCKER_HUB_TOKEN }}
77+
78+ - name : Build spaceros image and push it to Dockerhub
79+ id : push_image
5580 run : |
5681 earthly --ci --output +push-main-image \
5782 --VCS_REF="$VCS_REF" \
58- --IMAGE_TAG="$IMAGE_TAG " \
83+ --IMAGE_TAG="$ARCH_IMAGE_TAG " \
5984 --IMAGE_NAME="$DOCKER_HUB_IMAGE_NAME"
85+ echo "output_${{ matrix.arch-info.arch }}=$DOCKER_HUB_IMAGE_NAME:$ARCH_IMAGE_TAG" >> "$GITHUB_OUTPUT"
6086
6187 # Login and push the main builds to GHCR
6288 - name : Login to GHCR
@@ -70,35 +96,41 @@ jobs:
7096 - name : Push the main spaceros image to GHCR
7197 if : ${{ github.ref_name == 'main' }}
7298 run : |
73- docker tag "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG " "$GHCR_IMAGE_NAME:$IMAGE_TAG "
74- docker push "$GHCR_IMAGE_NAME:$IMAGE_TAG "
99+ docker tag "$DOCKER_HUB_IMAGE_NAME:$ARCH_IMAGE_TAG " "$GHCR_IMAGE_NAME:$ARCH_IMAGE_TAG "
100+ docker push "$GHCR_IMAGE_NAME:$ARCH_IMAGE_TAG "
75101
76- # Push both tagged releases and the latest main builds to Dockerhub
77- - name : Push spaceros images to Dockerhub
78- if : ${{ github.ref_type == 'tag' || github.ref_name == 'main' }}
79- run : |
80- # We must login using the password and not the action, as the action only supports tokens.
81- echo "$DOCKER_HUB_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
82- docker push "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG"
83102
103+ combine-main-image-manifests :
104+ env :
105+ IMAGE_TAG : " ${{ env.BASE_IMAGE_TAG }}"
106+
107+ runs-on : ubuntu-latest
108+ needs : space-ros-main-image
109+ steps :
110+ - name : Login to Docker Hub
111+ uses : docker/login-action@v3
112+ with :
113+ username : ${{ env.DOCKER_HUB_USERNAME }}
114+ password : ${{ env.DOCKER_HUB_TOKEN }}
115+
116+ - name : Combine Manifests
117+ run : |
118+ docker manifest create osrf/space-ros:${{ github.ref_name }} \
119+ --amend ${{ join(needs.space-ros-main-image.outputs, ' --amend ') }}
120+ docker manifest push $DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG
121+
84122 # Any tagged image should also be marked as "latest"
85123 - name : Push spaceros latest images to Dockerhub
86124 if : ${{ github.ref_type == 'tag' }}
87125 run : |
88126 # We must login using the password and not the action, as the action only supports tokens.
89- echo "$DOCKER_HUB_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
90127 docker tag "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG" "$DOCKER_HUB_IMAGE_NAME:latest"
91128 docker push "$DOCKER_HUB_IMAGE_NAME:latest"
92129
93130 space-ros-dev-image :
94131 runs-on : ubuntu-latest
95132 env :
96- IMAGE_TAG : " ${{ github.head_ref || github.ref_name }}-dev"
97- VCS_REF : ${{ github.sha }}
98- GHCR_IMAGE_NAME : " ghcr.io/space-ros/space-ros"
99- DOCKER_HUB_USERNAME : osrfbot
100- DOCKER_HUB_TOKEN : ${{ secrets.DOCKER_HUB_RW_TOKEN }}
101- DOCKER_HUB_IMAGE_NAME : " osrf/space-ros"
133+ IMAGE_TAG : " ${{ env.BASE_IMAGE_TAG }}-dev"
102134
103135 steps :
104136 - name : Checkout
@@ -116,7 +148,6 @@ jobs:
116148 --IMAGE_TAG="$IMAGE_TAG" \
117149 --IMAGE_NAME="$DOCKER_HUB_IMAGE_NAME"
118150
119- # Only push the main dev builds to GHCR
120151 - name : Login to GHCR
121152 uses : docker/login-action@v3
122153 if : ${{ github.ref_name == 'main' }}
@@ -125,6 +156,7 @@ jobs:
125156 username : ${{ github.actor }}
126157 password : ${{ secrets.GITHUB_TOKEN }}
127158
159+ # Only push the main dev builds to GHCR
128160 - name : Push the dev spaceros image to GHCR
129161 if : ${{ github.ref_name == 'main' }}
130162 run : |
0 commit comments