forked from ubi-agni/ros-builder-action
-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (64 loc) · 2.64 KB
/
docker.build.yaml
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
name: reusable docker build workflow
on:
# make this workflow reusable (and only so)
workflow_call:
inputs:
CONTEXT:
type: string
description: context sub folder in .github/docker
required: true
IMAGE:
type: string
description: image tag
required: false
ROS_DISTRO:
type: string
description: ROS distribution
required: false
default: one
DEB_DISTRO:
type: string
description: The Debian/Ubuntu distribution codename to compile for.
required: false
default: jammy
# Define environment variables from input, from configuration variables, or defaults - in this order!
# All inputs (declared above) are deliberately optional and don't provide an explicit default.
# Thus, if an input is not explicitly provided, we can fall back to the configuration variable here (var.* context).
# This variable context originates from the _calling_ workflow. Finally, a hard-coded default is given.
# https://docs.github.com/en/actions/learn-github-actions/variables#defining-configuration-variables-for-multiple-workflows
env:
IMAGE: ${{ inputs.IMAGE || format('ubiagni/ros:{0}-{1}', inputs.DEB_DISTRO, inputs.CONTEXT) }}
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: rhaschke/docker-run-action@main
name: Check for apt updates
continue-on-error: true
id: apt
with:
image: ${{ env.IMAGE }}
run: |
apt-get update
have_updates=$(apt-get --simulate upgrade | grep -q "^0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.$" && echo false || echo true)
echo "no_cache=$have_updates" >> "$GITHUB_OUTPUT"
test "$have_updates" = "true" && echo "Updates available. Disabling docker cache." || echo "No updates available. Using docker cache."
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .github/docker/${{ inputs.CONTEXT }}
build-args: ROS_DISTRO=${{ inputs.ROS_DISTRO }} DEB_DISTRO=${{ inputs.DEB_DISTRO }}
push: true
no-cache: ${{ steps.apt.outputs.no_cache || github.event_name == 'workflow_dispatch' }}
cache-from: type=registry,ref=${{ env.IMAGE }}
cache-to: type=inline
tags: ${{ env.IMAGE }}