Skip to content

Commit

Permalink
Merge pull request space-ros#212 from space-ros/push-main-image
Browse files Browse the repository at this point in the history
Add CI step to push Docker image to ghcr.io if building main
  • Loading branch information
eholum committed Sep 13, 2024
2 parents 96f86fe + ea160e4 commit 19a0266
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/earthly-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up earthly
run: |
sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly
Expand All @@ -42,10 +48,14 @@ jobs:
run: |
earthly --ci --output +sources
earthly --ci +image
- name: Push spaceros image
- name: Push tagged spaceros images to Dockerhub
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }}
if: ${{ github.ref_type == 'tag' }}
run: |
echo $DOCKER_HUB_TOKEN | docker login --username osrfbot --password-stdin
earthly --ci --push +image --tag=${{ github.ref_name }}
earthly --ci --push +push-image --TAG="osrf/space-ros:${{ github.ref_name }}" --LATEST="osrf/space-ros:latest"
- name: Push the main spaceros image to GHCR
if: ${{ github.ref_name == 'main' }}
run: |
earthly --ci --push +push-image --TAG="ghcr.io/space-ros/space-ros:main" --LATEST=""
13 changes: 11 additions & 2 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ build-testing:
image:
FROM +rosdep
ARG VCS_REF
ARG tag='latest'
ARG VERSION="latest"

# Specify the docker image metadata
LABEL org.label-schema.schema-version="1.0"
Expand All @@ -276,4 +276,13 @@ image:
COPY docker/entrypoint.sh /ros_entrypoint.sh
ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
SAVE IMAGE --push osrf/space-ros:latest osrf/space-ros:$tag
SAVE IMAGE osrf/space-ros:${VERSION}

# Target for prepping image(s) to be pushed to remote registries.
push-image:
FROM +image

# This can be overridden with a blank string to prevent pushing to the registry.
ARG LATEST="osrf/space-ros:latest"
ARG TAG
SAVE IMAGE --push ${LATEST} ${TAG}
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

VCS_REF="$(git rev-parse HEAD)"
VERSION=preview
VERSION="$(git rev-parse --abbrev-ref HEAD)"

# Exit script with failure if build fails
set -eo pipefail
Expand All @@ -13,7 +13,8 @@ echo ""
rm -rf src
earthly +sources
earthly +image \
--VCS_REF="$VCS_REF"
--VCS_REF="${VCS_REF}" \
--VERSION="${VERSION}"

echo ""
echo "##### Done! #####"
Expand Down

0 comments on commit 19a0266

Please sign in to comment.