Skip to content

Earthly build

Earthly build #207

name: Earthly build
on:
workflow_dispatch:
push:
branches: ["main"]
tags: ["*"]
pull_request:
schedule:
- cron: "0 11 * * *"
jobs:
build-test:
env:
VCS_REF: ${{ github.sha }}
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
compression-level: 0
space-ros-main-image:
runs-on: ubuntu-latest
env:
IMAGE_TAG: "${{ github.head_ref || github.ref_name }}"
VCS_REF: ${{ github.sha }}
GHCR_IMAGE_NAME: "ghcr.io/space-ros/space-ros"
DOCKER_HUB_USERNAME: osrfbot
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }}
DOCKER_HUB_IMAGE_NAME: "osrf/space-ros"
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-amd64 -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="$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
if: ${{ github.ref_name == 'main' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push the main 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 latest main builds to Dockerhub
- name: Push spaceros images to Dockerhub
if: ${{ github.ref_type == 'tag' || github.ref_name == 'main' }}
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"
# Any tagged image should also be marked as "latest"
- name: Push spaceros latest images to Dockerhub
if: ${{ github.ref_type == 'tag' }}
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:
runs-on: ubuntu-latest
env:
IMAGE_TAG: "${{ github.head_ref || github.ref_name }}-dev"
VCS_REF: ${{ github.sha }}
GHCR_IMAGE_NAME: "ghcr.io/space-ros/space-ros"
DOCKER_HUB_USERNAME: osrfbot
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }}
DOCKER_HUB_IMAGE_NAME: "osrf/space-ros"
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"
# Only push the main dev builds to GHCR
- 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 }}
- 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' }}
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"