Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker #4

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Docker

on:
push:
branches:
- master
pull_request:
paths:
- 'snp**'
- 'docker/Dockerfile'
- '.github/workflows/docker.yml'
Yolnan marked this conversation as resolved.
Show resolved Hide resolved
release:
types:
- released

jobs:
ci:
name: ${{ matrix.distro }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
distro: [foxy, humble, rolling]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PUSH_DOCKER_IMAGE: ${{ github.ref == 'refs/heads/master' || github.event_name == 'release' }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker meta-information
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
prefix=
suffix=
tags: |
type=ref,event=branch,prefix=${{ matrix.distro }}-
type=ref,event=pr,prefix=${{ matrix.distro }}-
type=semver,pattern={{major}}.{{minor}},prefix=${{ matrix.distro }}-

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/Dockerfile
build-args: |
TAG=${{ matrix.distro }}-0.21
Yolnan marked this conversation as resolved.
Show resolved Hide resolved
ROS_DISTRO=${{ matrix.distro }}
push: ${{ env.PUSH_DOCKER_IMAGE }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
30 changes: 30 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG TAG
FROM ghcr.io/ros-industrial-consortium/scan_n_plan_workshop:${TAG}

SHELL ["/bin/bash", "-c"]

ENV DEBIAN_FRONTEND noninteractivej

USER root

# Install Python dependencies
RUN python3 -m pip install open3d pyquaternion --upgrade
marip8 marked this conversation as resolved.
Show resolved Hide resolved

# Bind mount the source directory so as not to unnecessarily copy source code into the docker image
ARG WORKSPACE_DIR=/opt/snp_automate_2022
RUN --mount=type=bind,target=${WORKSPACE_DIR}/src/snp_automate_2022 \
apt update -y -qq \
&& source /opt/snp/install/setup.bash \
Yolnan marked this conversation as resolved.
Show resolved Hide resolved
&& vcs import ${WORKSPACE_DIR}/src < ${WORKSPACE_DIR}/src/snp_automate_2022/dependencies.repos --shallow \
&& rosdep install \
--from-paths ${WORKSPACE_DIR}/src \
-iry \
--skip-keys libvtk
marip8 marked this conversation as resolved.
Show resolved Hide resolved

# Build the repository
# Bind mount the source directory so as not to unnecessarily copy source code into the docker image
RUN --mount=type=bind,target=${WORKSPACE_DIR}/src/snp_automate_2022 \
source /opt/snp/install/setup.bash \
&& cd ${WORKSPACE_DIR} \
&& colcon build --cmake-args \
&& rm -rf build log
28 changes: 28 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SNP Automate 2022 Docker

## Create the Docker image
### Download
Download a pre-built Docker image from the container registry:

```
docker login ghcr.io
docker pull ghcr.io/ros-industrial-consortium/scan_n_plan_workshop:<tag>
```

### Build
Build the Docker image using `docker-compose`:

```commandLine
cd docker
docker compose build
```

## Run the docker image
Run the Docker image using `docker-compose`:

```commandLine
cd docker
CURRENT_UID=$(id -u):$(id -g) docker compose up
```

> Note: by default the docker image runs as a non-root user, so the environment variable `CURRENT_UID` must be supplied as shown above
32 changes: 32 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3'
services:
snp_automate_2022:
build:
context: ..
dockerfile: docker/Dockerfile
args:
- TAG=foxy-master
environment:
DISPLAY: $DISPLAY
XAUTHORITY: $XAUTHORITY
NVIDIA_DRIVER_CAPABILITIES: all
ROS_LOG_DIR: /tmp
marip8 marked this conversation as resolved.
Show resolved Hide resolved
container_name: snp_automate_2022
image: ghcr.io/ros-industrial-consortium/snp_automate_2022:foxy-master
stdin_open: true
tty: true
network_mode: host
privileged: true
user: ${CURRENT_UID} # CURRENT_UID=$(id -u):$(id -g)
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- /etc/hosts:/etc/hosts
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
marip8 marked this conversation as resolved.
Show resolved Hide resolved
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
marip8 marked this conversation as resolved.
Show resolved Hide resolved
Loading