diff --git a/.github/workflows/docker-build-push.yaml b/.github/workflows/docker-build-push.yaml index 2f1864a..dd33ddb 100644 --- a/.github/workflows/docker-build-push.yaml +++ b/.github/workflows/docker-build-push.yaml @@ -3,6 +3,7 @@ name: Build and Push Docker Image (native amd64 & arm64) on: push: branches: ["main", "workflow"] + pull_request: env: REGISTRY: ghcr.io @@ -12,6 +13,8 @@ jobs: build: strategy: matrix: + ros_distro: [humble, jazzy] + arch: [amd64, arm64] include: - arch: amd64 runner: ubuntu-latest @@ -34,20 +37,34 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push image (${{ matrix.platform }}) + - name: Set image tags + id: vars + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + BRANCH_NAME="${{ github.head_ref }}" + SAFE_BRANCH=$(echo "$BRANCH_NAME" | tr '/' '-' | tr '[:upper:]' '[:lower:]') + echo "TAG=-$SAFE_BRANCH" >> $GITHUB_OUTPUT + else + echo "TAG=" >> $GITHUB_OUTPUT + fi + + - name: Build and push image (${{ matrix.ros_distro }} - ${{ matrix.platform }}) uses: docker/build-push-action@v5 with: context: . - file: ./images/ros-core.Dockerfile + file: ./images/ros-core-${{ matrix.ros_distro }}.Dockerfile push: true platforms: ${{ matrix.platform }} tags: | - ghcr.io/high-flyers/ros-core:latest - ghcr.io/high-flyers/ros-core:${{ matrix.arch }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }}-${{ matrix.arch }}${{ steps.vars.outputs.TAG }} manifest: + strategy: + matrix: + ros_distro: [humble, jazzy] runs-on: ubuntu-latest needs: build + if: github.event_name == 'push' permissions: packages: write steps: @@ -58,9 +75,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Create and push multi-arch manifest + - name: Create and push multi-arch manifest for ${{ matrix.ros_distro }} run: | docker buildx imagetools create \ - -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }} \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }}-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.ros_distro }}-arm64 diff --git a/images/ros-core.Dockerfile b/images/ros-core-humble.Dockerfile similarity index 92% rename from images/ros-core.Dockerfile rename to images/ros-core-humble.Dockerfile index fbef40c..89685e5 100644 --- a/images/ros-core.Dockerfile +++ b/images/ros-core-humble.Dockerfile @@ -1,11 +1,15 @@ # Syntax: docker/dockerfile:1.4 FROM --platform=$BUILDPLATFORM ubuntu:22.04 -ARG ROS_DISTRO=humble ARG USERNAME=hf -ARG USER_UID=1000 +ARG USER_UID=1001 ARG USER_GID=${USER_UID} +ENV ROS_DISTRO=humble +ENV USERNAME=${USERNAME} +ENV USER_UID=${USER_UID} +ENV USER_GID=${USER_GID} + RUN sed -i 's/# \(.*universe\)/\1/' /etc/apt/sources.list RUN apt-get update && apt-get -y --quiet --no-install-recommends install \ @@ -45,6 +49,6 @@ RUN sudo apt-get update && sudo apt-get upgrade -y \ tmux \ && sudo rm -rf /var/lib/apt/lists/* -RUN echo "source \"/opt/ros/${ROS_DISTRO}/setup.bash\"" >> "/home/${USERNAME}/.bashrc" +RUN echo "source \"/opt/ros/${ROS_DISTRO}/setup.bash\"" >> "/home/${USERNAME}/.bashrc" CMD ["/bin/bash"] diff --git a/images/ros-core-jazzy.Dockerfile b/images/ros-core-jazzy.Dockerfile new file mode 100644 index 0000000..2ed296b --- /dev/null +++ b/images/ros-core-jazzy.Dockerfile @@ -0,0 +1,54 @@ +# Syntax: docker/dockerfile:1.4 +FROM --platform=$BUILDPLATFORM ubuntu:24.04 + +ARG USERNAME=hf +ARG USER_UID=1001 +ARG USER_GID=${USER_UID} + +ENV ROS_DISTRO=jazzy +ENV USERNAME=${USERNAME} +ENV USER_UID=${USER_UID} +ENV USER_GID=${USER_GID} + +RUN sed -i 's/# \(.*universe\)/\1/' /etc/apt/sources.list + +RUN apt-get update && apt-get -y --quiet --no-install-recommends install \ + build-essential \ + cmake \ + curl \ + git \ + python3-pip \ + python3-dev \ + gcc \ + locales \ + software-properties-common \ + sudo \ + && rm -rf /var/lib/apt/lists/* + + +RUN locale-gen en_US en_US.UTF-8 && \ + update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 && \ + echo "export LANG=en_US.UTF-8" >> /etc/profile.d/locale.sh + +RUN curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg +RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" > /etc/apt/sources.list.d/ros2.list + +RUN groupadd --gid ${USER_GID} ${USERNAME} \ + && useradd -s /bin/bash --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} \ + && echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} \ + && chmod 0440 /etc/sudoers.d/${USERNAME} + +USER ${USERNAME} +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN sudo apt-get update && sudo apt-get upgrade -y \ + && sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \ + ros-${ROS_DISTRO}-ros-base \ + ros-dev-tools \ + vim \ + tmux \ + && sudo rm -rf /var/lib/apt/lists/* + +RUN echo "source \"/opt/ros/${ROS_DISTRO}/setup.bash\"" >> "/home/${USERNAME}/.bashrc" + +CMD ["/bin/bash"]