-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (141 loc) · 5.29 KB
/
reusable-build-push.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
name: Reusable workflow to build and push multi-arch images
on:
workflow_call:
inputs:
ros_distro:
required: false
type: string
default: "iron"
force:
required: false
type: boolean
default: false
secrets:
token:
description: "The GitHub token passed from the caller workflow"
required: true
env:
ROS2_WS_PATH: ros2_ws
jobs:
check-version:
name: Check if the version has been updated
outputs:
has_changed: ${{ steps.check.outputs.has_changed }}
version: ${{ steps.versions.outputs.new_version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- id: versions
run: |
git show HEAD^:$ROS2_WS_PATH/VERSION.${{ inputs.ros_distro }} 2>/dev/null
if [[ $? == 0 ]]; then
PREV_VERSION=$(git show HEAD^:$ROS2_WS_PATH/VERSION.${{ inputs.ros_distro }})
else
PREV_VERSION=0.0.0
fi
NEW_VERSION=$(git show HEAD:$ROS2_WS_PATH/VERSION.${{ inputs.ros_distro }})
echo "prev_version=${PREV_VERSION}" >> $GITHUB_OUTPUT
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
shell: bash
- uses: aica-technology/.github/.github/actions/compare-versions@v1.0.2
id: check
with:
previous_version: ${{ steps.versions.outputs.prev_version }}
new_version: ${{ steps.versions.outputs.new_version }}
metadata:
needs: check-version
if: ${{ needs.check-version.outputs.has_changed == 'true' || inputs.force }}
runs-on: ubuntu-latest
name: Metadata
outputs:
image_name: ${{ steps.ensure-image.outputs.image_name }}
image_tags: ${{ steps.tags.outputs.image_tags }}
build_flags: ${{ steps.tags.outputs.build_flags }}
git_tag: ${{ steps.tags.outputs.git_tag }}
steps:
- uses: aica-technology/.github/.github/actions/ghcr-ensure-prefix@v0.6.0
id: ensure-image
with:
image_name: aica-technology/ros2-ws
- id: tags
run: |
BUILD_FLAGS=()
ROS_DISTRO=${{ inputs.ros_distro }}
BUILD_FLAGS+=(--build-arg ROS_DISTRO=${ROS_DISTRO})
if [ ${ROS_DISTRO} == iron ]; then
# use a specific SHA256 digest for repeatability
# -> ros:iron from September 02, 2023
BASE_IMAGE=docker.io/library/ros@sha256
BASE_TAG=6df9b084cb7e918455df628126b2b647d2ad2e4b0e979fb8fbc525a610573bbb
else
BASE_IMAGE=docker.io/library/ros
BASE_TAG=${ROS_DISTRO}
fi
BUILD_FLAGS+=(--build-arg BASE_IMAGE=${BASE_IMAGE})
BUILD_FLAGS+=(--build-arg BASE_TAG=${BASE_TAG})
VERSION_TAG="v${{ needs.check-version.outputs.version }}"
if [[ "${VERSION_TAG}" == *"-"* ]]; then
IMAGE_TAGS="${VERSION_TAG},${VERSION_TAG}-${ROS_DISTRO}"
GIT_TAG=""
else
IMAGE_TAGS="${VERSION_TAG},${VERSION_TAG}-${ROS_DISTRO}","${ROS_DISTRO}"
GIT_TAG="${VERSION_TAG}-${ROS_DISTRO}"
fi
BUILD_FLAGS+=(--build-arg VERSION=${VERSION_TAG}-${ROS_DISTRO})
echo "::debug::Using base image tag ${BASE_TAG}"
echo "Build flags: ${BUILD_FLAGS[@]}"
echo "Image tags: ${IMAGE_TAGS}"
echo "Git tag: ${GIT_TAG}"
echo "build_flags=${BUILD_FLAGS[@]}" >> $GITHUB_OUTPUT
echo "image_tags=${IMAGE_TAGS}" >> $GITHUB_OUTPUT
echo "git_tag=${GIT_TAG}" >> $GITHUB_OUTPUT
build:
needs: metadata
strategy:
matrix:
arch: [amd64, arm64]
include:
- image: ubuntu-latest
- image: buildjet-2vcpu-ubuntu-2204-arm
arch: arm64
runs-on: ${{ matrix.image }}
name: Build and publish (${{ matrix.arch }})
steps:
- uses: actions/checkout@v3
- run: |
CONFIG_PATH=$ROS2_WS_PATH/config
mkdir -p ${CONFIG_PATH}
cp common/sshd_entrypoint.sh ${CONFIG_PATH}/
cp common/config.rviz ${CONFIG_PATH}/
- uses: aica-technology/.github/.github/actions/list-add-suffixes@v0.6.1
id: merge-tags
with:
list: ${{ needs.metadata.outputs.image_tags }}
suffixes: ${{ matrix.arch }}
glue_separator: "-"
- uses: aica-technology/.github/.github/actions/ghcr-build@v0.6.1
with:
image_name: ${{ needs.metadata.outputs.image_name }}
image_tags: ${{ steps.merge-tags.outputs.list }}
build_context_path: $ROS2_WS_PATH
dockerfile_path: ros2_ws/Dockerfile
build_flags: ${{ needs.metadata.outputs.build_flags }}
token: ${{ secrets.GITHUB_TOKEN }}
multi-arch:
runs-on: ubuntu-latest
name: Merge into a multi-arch image
needs: [metadata, build]
steps:
- uses: aica-technology/.github/.github/actions/ghcr-manifest-merge@v0.6.1
with:
image_name: ${{ needs.metadata.outputs.image_name }}
image_tags: ${{ needs.metadata.outputs.image_tags }}
archs: amd64,arm64
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create git tag
if: ${{ needs.metadata.outputs.git_tag != '' }}
uses: aica-technology/.github/.github/actions/git-tag@v0.8.1
with:
tag: ${{ needs.metadata.outputs.git_tag }}