Skip to content

Build main image on arm (#206) #36

Build main image on arm (#206)

Build main image on arm (#206) #36

name: Earthly build

Check failure on line 1 in .github/workflows/earthly-build.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/earthly-build.yaml

Invalid workflow file

(Line: 26, Col: 5): Unexpected value 'runs_on', (Line: 24, Col: 5): Required property is missing: runs-on
on:
workflow_dispatch:
push:
branches: ["main"]
tags: ["*"]
pull_request:
schedule:
- cron: "0 11 * * *"
# Ensures that only one workflow per branch will run at a time
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
env:
VCS_REF: ${{ github.sha }}
GHCR_IMAGE_NAME: "ghcr.io/space-ros/space-ros"
DOCKER_HUB_USERNAME: osrfbot
DOCKER_HUB_IMAGE_NAME: "osrf/space-ros"
jobs:
sanitize-docker-tag:
outputs:
tag_name: ${{ steps.sanitize.outputs.tag_name }}
runs_on: ubuntu-latest
env:
IMAGE_TAG: "${{ github.head_ref || github.ref_name }}"
steps:
- name: Sanitize Github Refs
id: sanitize
run: echo "tag_name=${IMAGE_TAG//\//-}" >> "$GITHUB_OUTPUT"
build-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up earthly
run: |
sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly
sudo chmod 755 /usr/local/bin/earthly
- name: Build Test Space ROS
id: build
run: |
earthly --ci --output +build-test
echo "archivename=$(basename log/build_results_archives/build_results_*.tar.bz2)" >> $GITHUB_ENV
- name: Upload build results archive
uses: actions/upload-artifact@v4
with:
name: ${{env.archivename}}
path: log/build_results_archives/${{env.archivename}}
if-no-files-found: error
space-ros-main-image:
needs: sanitize-docker-tag
strategy:
fail-fast: false
matrix:
include:
- runner: "ubuntu-latest"
arch: "amd64"
- runner: "ubuntu-24.04-arm"
arch: "arm64"
outputs:
output_amd64: ${{ steps.push_image.outputs.output_amd64 }}
output_arm64: ${{ steps.push_image.outputs.output_arm64 }}
runs-on: ${{ matrix.runner }}
permissions:
packages: write
env:
ARCH_IMAGE_TAG: "${{ needs.sanitize-docker-tag.tag_name }}-${{ matrix.arch }}"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Sanitize image tag
run: echo "IMAGE_TAG=${IMAGE_TAG//\//-}" >> "$GITHUB_ENV"
- name: Set up earthly
run: |
sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-${{ matrix.arch }} -O /usr/local/bin/earthly
sudo chmod 755 /usr/local/bin/earthly
- name: Build spaceros image without pushing
run: |
earthly --ci --output +push-main-image \
--VCS_REF="$VCS_REF" \
--IMAGE_TAG="$ARCH_IMAGE_TAG" \
--IMAGE_NAME="$DOCKER_HUB_IMAGE_NAME"
# Login and push the main builds to GHCR
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push the main spaceros image to GHCR
id: push_image
env:
FULL_GHCR_IMAGE_NAME: "${{ env.GHCR_IMAGE_NAME }}:${{ env.ARCH_IMAGE_TAG }}"
run: |
docker tag "$DOCKER_HUB_IMAGE_NAME:$ARCH_IMAGE_TAG" "$FULL_GHCR_IMAGE_NAME"
docker push "$FULL_GHCR_IMAGE_NAME"
echo "output_${{ matrix.arch }}=$FULL_GHCR_IMAGE_NAME" >> "$GITHUB_OUTPUT"
combine-main-image-manifests:
needs: [sanitize-docker-tag, space-ros-main-image]
if: ${{ github.ref_type == 'tag' || github.ref_name == 'main' }}
runs-on: ubuntu-latest
permissions:
packages: write
env:
IMAGE_TAG: "${{ needs.sanitize-docker-tag.tag_name }}"
steps:
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Push both tagged releases and the latest main builds to Dockerhub
- name: Push spaceros images to Dockerhub with combined manifests
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }}
run: |
# We must login using the password and not the action, as the action only supports tokens.
echo "$DOCKER_HUB_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
docker buildx imagetools create \
--tag "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG" \
${{ join(needs.space-ros-main-image.outputs, ' ') }}
# Any tagged image should also be marked as "latest"
- name: Push spaceros latest images to Dockerhub
if: ${{ github.ref_type == 'tag' }}
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }}
run: |
# We must login using the password and not the action, as the action only supports tokens.
echo "$DOCKER_HUB_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
docker tag "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG" "$DOCKER_HUB_IMAGE_NAME:latest"
docker push "$DOCKER_HUB_IMAGE_NAME:latest"
space-ros-dev-image:
needs: sanitize-docker-tag
runs-on: ubuntu-latest
env:
IMAGE_TAG: "${{ needs.sanitize-docker-tag.tag_name }}-dev"
steps:
# Prevent the GitHub runner from running out of disk space.
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@v1.3.1
- name: Checkout
uses: actions/checkout@v3
- name: Sanitize image tag
run: echo "IMAGE_TAG=${IMAGE_TAG//\//-}" >> "$GITHUB_ENV"
- name: Set up earthly
run: |
sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly
sudo chmod 755 /usr/local/bin/earthly
- name: Build spaceros dev image without pushing
run: |
earthly --ci --output +push-dev-image \
--VCS_REF="$VCS_REF" \
--IMAGE_TAG="$IMAGE_TAG" \
--IMAGE_NAME="$DOCKER_HUB_IMAGE_NAME"
- name: Login to GHCR
uses: docker/login-action@v3
if: ${{ github.ref_name == 'main' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Only push the main dev builds to GHCR
- name: Push the dev spaceros image to GHCR
if: ${{ github.ref_name == 'main' }}
run: |
docker tag "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG" "$GHCR_IMAGE_NAME:$IMAGE_TAG"
docker push "$GHCR_IMAGE_NAME:$IMAGE_TAG"
# Push both tagged releases and the main dev builds to Dockerhub
- name: Push spaceros images to Dockerhub
if: ${{ github.ref_type == 'tag' || github.ref_name == 'main' }}
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }}
run: |
# We must login using the password and not the action, as the action only supports tokens.
echo "$DOCKER_HUB_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
docker push "$DOCKER_HUB_IMAGE_NAME:$IMAGE_TAG"