Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
intial version of amp-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
alanssitis committed Feb 28, 2022
1 parent fbe8c64 commit 64ef3a0
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 75 deletions.
22 changes: 18 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# ROS build directories
build/
devel/

# AMP-CLI files
AMP_CLI.egg-info/
amp_cli.py
docker/
.dockerignore
setup.py
__pycache__/

# Git files
.git/
.github/
.gitignore
__pycache__/
.gitmodules
README.md
setup.py

# Catkin ignore files
disable_zed.sh
enable_zed.sh

# Docker
docker/
.dockerignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ROS build directories
build/
devel/

# AMP-CLI files
__pycache__/
AMP_CLI.egg-info/

# Catkin ignore files
CATKIN_IGNORE
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ slam\_mode\_goal is intended to put out high-level, ideal cart commands that are
Takes MoveBaseGoal and converts them to cmd_vel to the simulated kart

# Running
* Show available options help
* To build the amp-cli tool, run:
```
. amd64-docker.sh 0
```

To build the docker image, have a second argument behind the number.
* Run intel graphics docker
```
. amd64-docker.sh 1
```
* Run nvidia graphics docker
```
. amd64-docker.sh 2
pip install .
```
* Run `amp-cli` to view the available options.
143 changes: 106 additions & 37 deletions amp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,58 @@ def cli():
"""This is the official AMP Software Sub-Team CLI Tool that helps you
develop on AMP_ASSv2 using docker containers in your current environment.
In order to run it, you must be in the root directory of the AMP_ASSv2 repo
in order for docker files to build properly.
In order to run some of the functions, you must be in the root directory
of the AMP_ASSv2 repo. If there are any features you would like to see,
or bugs that need to be fixed, feel free to open an issue or PR!
"""
pass


@cli.command()
@click.option('-b', '--build', is_flag=True)
@click.option('-b', '--build', is_flag=True,
help='Build the frame container, if not up-to-date.')
@click.option('--display', default='mesa',
type=click.Choice(['mesa', 'nvidia'], case_sensitive=False))
type=click.Choice(['mesa', 'nvidia'], case_sensitive=False),
help='Choose display driver option.')
def devel(build: bool, display: str):
"""Develop with current directory mounted on the container.
"""
print(display)
click.echo('Successfully exited the container')


@cli.command()
@click.option('-b', '--build', is_flag=True,
help='Build a new container.')
@click.option('--display', default='mesa', show_default=True,
type=click.Choice(['mesa', 'nvidia'], case_sensitive=False),
help='Choose display option.')
def scratch(build: bool, display: str):
"""Develop on a fully isolated container.
"""
# Initialize docker client environment
client = docker.from_env()
cwd = os.getcwd()
tag = 'amp-devel:frame-desktop'

# Make sure current directory is AMP_ASSv2
if cwd.split('/')[-1] != 'AMP_ASSv2':
raise click.ClickException(click.style(
'AMP CLI only works inside root directory of the AMP_ASSv2 local repository', fg='red'))
'Devel only works when executed from the root directory of the AMP_ASSv2 local repo.', fg='red'))

tag = f'amp-ass:{display}'
dockerfile = cwd + f'/docker/{display}.Dockerfile'

# Build container
if build:
click.echo('Building containers...')
click.echo('Step 1/2: Building amp-base:default')

click.echo('Step 1/2: Building amp-devel:noetic-desktop.')
try:
_ = client.images.build(
path=cwd, tag='amp-base:default',
dockerfile=(cwd+'/docker/base.Dockerfile'))
path=cwd, tag='amp-devel:noetic-desktop',
dockerfile=(cwd+'/docker/desktop.Dockerfile'))
click.secho(
f' ---> Finished building amp-base:default', fg='yellow')
' ---> Finished building amp-devel:noetic-desktop.', fg='yellow')
except Exception as exception:
raise click.ClickException(exception)

click.echo(f'Step 2/2: Building {tag}')
click.echo(f'Step 2/2: Building {tag}.')
try:
_ = client.images.build(
path=cwd, tag=tag, dockerfile=dockerfile)
click.secho(f' ---> Finished building {tag}', fg='yellow')
path=cwd, tag=tag,
dockerfile=(cwd+'/docker/frame.Dockerfile'))
click.secho(
f' ---> Finished building {tag}.', fg='yellow')
except Exception as exception:
raise click.ClickException(exception)

try:
# Run the contianer
click.echo(f'Running {tag}...')
if display == 'mesa':
container = client.containers.run(
tag, stdin_open=True, tty=True, auto_remove=True,
Expand All @@ -84,15 +75,89 @@ def scratch(build: bool, display: str):
volumes={
'/tmp/.X11-unix': {
'bind': '/tmp/.X11-unix',
'mode': 'rw'
}
'mode': 'rw',
},
cwd: {
'bind': '/amp_ws',
'mode': 'rw',
},
},
privileged=True,
detach=True)
# TODO: NVidia settings
else:
raise click.ClickException('NVidia config WIP')
# Attach to the container
click.echo('Use [<Ctrl> + D] to stop and exit the container.')
click.secho(
f'Entering container {container.name}:{container.short_id}.', fg='blue')
subprocess.run(['docker', 'attach', container.id])
click.secho('Successfully exited and stopped container.', fg='green')
except Exception as exception:
raise click.ClickException(exception)


@cli.command()
@click.option('-b', '--build', is_flag=True,
help='Build the corresponding containers.')
@click.option('--display', default='mesa', show_default=True,
type=click.Choice(['mesa', 'nvidia'], case_sensitive=False),
help='Choose display driver option.')
def scratch(build: bool, display: str):
"""Develop on a fully isolated container.
"""
# Initialize docker client environment
client = docker.from_env()
cwd = os.getcwd()

tag = f'amp-devel:{display}-build'
dockerfile = cwd + f'/docker/{display}.Dockerfile'

# Build container
if build:
# Make sure current directory is AMP_ASSv2
if cwd.split('/')[-1] != 'AMP_ASSv2':
raise click.ClickException(click.style(
'Build only works inside root directory of the AMP_ASSv2 local repository.', fg='red'))

click.echo('Building containers...')

click.echo('Step 1/3: Building amp-devel:noetic-desktop.')
try:
_ = client.images.build(
path=cwd, tag='amp-devel:noetic-desktop',
dockerfile=(cwd+'/docker/desktop.Dockerfile'))
click.secho(
' ---> Finished building amp-devel:noetic-desktop.', fg='yellow')
except Exception as exception:
raise click.ClickException(exception)

click.echo('Step 2/3: Building amp-devel:frame-desktop.')
try:
_ = client.images.build(
path=cwd, tag='amp-devel:frame-desktop',
dockerfile=(cwd+'/docker/frame.Dockerfile'))
click.secho(
' ---> Finished building amp-devel:frame-desktop.', fg='yellow')
except Exception as exception:
raise click.ClickException(exception)

click.echo(f'Step 3/3: Building {tag}.')
try:
_ = client.images.build(
path=cwd, tag=tag, dockerfile=dockerfile)
click.secho(f' ---> Finished building {tag}.', fg='yellow')
except Exception as exception:
raise click.ClickException(exception)

try:
# Run the contianer
click.echo(f'Running {tag}...')
if display == 'mesa':
container = client.containers.run(
tag, stdin_open=True, tty=True, auto_remove=True,
network_mode='host',
name='amp-assv2-scratch',
environment={
'DISPLAY': os.getenv('DISPLAY'),
'QT_X11_NO_MITSHM': 1,
Expand All @@ -101,16 +166,20 @@ def scratch(build: bool, display: str):
volumes={
'/tmp/.X11-unix': {
'bind': '/tmp/.X11-unix',
'mode': 'rw'
}
'mode': 'rw',
},
},
privileged=True,
detach=True)
click.secho(
f'Entering container {container.name}:{container.short_id}', fg='blue')

# TODO: NVidia settings
else:
raise click.ClickException('NVidia config WIP')
# Attach to the container
click.echo('Use [<Ctrl> + D] to stop and exit the container.')
click.secho(
f'Entering container {container.name}:{container.short_id}.', fg='blue')
subprocess.run(['docker', 'attach', container.id])
click.secho('Successfully exited and stopped container', fg='green')
click.secho('Successfully exited and stopped container.', fg='green')

except Exception as exception:
raise click.ClickException(exception)
17 changes: 0 additions & 17 deletions docker/base.Dockerfile

This file was deleted.

5 changes: 5 additions & 0 deletions docker/desktop.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ros:noetic-ros-base

RUN apt-get update && apt-get install -y --no-install-recommends \
ros-noetic-desktop \
&& rm -rf /var/lib/apt/lists/*
18 changes: 18 additions & 0 deletions docker/frame.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM amp-devel:noetic-desktop
SHELL ["/bin/bash", "-c"]
WORKDIR /amp_ws

RUN apt-get update && apt-get install -q -y --no-install-recommends \
tmux \
curl \
wget \
vim \
libgl1-mesa-glx \
libgl1-mesa-dri \
mesa-utils \
unzip \
&& rm -rf /var/lib/apt/list/* \
&& rosdep update

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
11 changes: 8 additions & 3 deletions docker/mesa.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
FROM amp-base:default
FROM amp-devel:frame-desktop
SHELL ["/bin/bash", "-c"]
WORKDIR /amp_ws

COPY . .
COPY src ./src
COPY .catkin_workspace .

RUN . /opt/ros/noetic/setup.bash && \
rosdep install --from-paths src -r -y && \
catkin_make && echo "source /amp_ws/devel/setup.bash" >> ~/.bashrc
catkin_make
RUN echo "source /amp_ws/devel/setup.bash" >> ~/.bashrc

ENTRYPOINT ["/ros_entrypoint.sh"]
CMD ["bash"]
6 changes: 6 additions & 0 deletions ros_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"
exec "$@"
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
install_requires=[
'click',
'docker',
'os',
'subprocess',
],
entry_points={
'console_scripts': [
Expand Down

0 comments on commit 64ef3a0

Please sign in to comment.