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 support for Dev Containers in VS Code #15

Merged
merged 6 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions SkyScan.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"docker.host": "ssh:https://[email protected]"
}
}
8 changes: 8 additions & 0 deletions adsb-mqtt/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "ADSB to MQTT",
"dockerComposeFile": ["../docker-compose.yml", "./docker-compose.adsb-mqtt.devcontainer.yml"],
"service": "adsb-mqtt",
"shutdownAction": "none",
// Open the sub-folder with the source code
"workspaceFolder": "/workspace"
}
2 changes: 1 addition & 1 deletion adsb-mqtt/adsb-mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def main():

logging.info("---[ Starting %s ]---------------------------------------------" % sys.argv[0])

planes = pd.read_csv("/app/data/aircraftDatabase.csv") #,index_col='icao24')
planes = pd.read_csv("/data/aircraftDatabase.csv") #,index_col='icao24')
logging.info("Printing table")
logging.info(planes)

Expand Down
9 changes: 9 additions & 0 deletions adsb-mqtt/docker-compose.adsb-mqtt.devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.7'

services:
adsb-mqtt:
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
- /home/pi/Projects/SkyScan/adsb-mqtt:/workspace:cached # Additional bind mount
- /home/pi/Projects/SkyScan/data:/data:cached
working_dir: /workspace
2 changes: 1 addition & 1 deletion adsb-mqtt/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ ADD *.txt /app/
RUN pip3 install -r requirements.txt
ADD *.py /app/
ADD mqtt_wrapper /app/mqtt_wrapper/
CMD ./adsb-mqtt.py -H 192.168.1.218 -m 192.168.1.218 -t skyscan/planes/json
#CMD ./adsb-mqtt.py -H 192.168.1.218 -m 192.168.1.218 -t skyscan/planes/json

1 change: 1 addition & 0 deletions adsb-mqtt/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./adsb-mqtt.py -H piaware -m mqtt -t skyscan/planes/json
Binary file added assets/docker-host.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/extension-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/open-folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions axis-ptz/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Axis PTZ Camera Controller",
"dockerComposeFile": ["../docker-compose.yml","./docker-compose.axis-ptz.devcontainer.yml"],
"service": "axis-ptz",
"shutdownAction": "none",
// Open the sub-folder with the source code
"workspaceFolder": "/workspace"
}
8 changes: 8 additions & 0 deletions axis-ptz/docker-compose.axis-ptz.devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.7'

services:
axis-ptz:
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
- /home/pi/Projects/SkyScan/axis-ptz:/workspace:cached # Additional bind mount
working_dir: /workspace
1 change: 1 addition & 0 deletions axis-ptz/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./camera.py -m mqtt -t skyscan/flight/json -u ${AXIS_USERNAME} -p ${AXIS_PASSWORD} -a ${AXIS_IP} -z ${CAMERA_ZOOM} -s ${CAMERA_MOVE_SPEED} -d ${CAMERA_DELAY}
66 changes: 66 additions & 0 deletions devcontainers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# How to get started using Dev Containers

This should work for the standard setup of SkyScan. There is a dev laptop, where you write code and a Pi that is running the code.

## Requirements

The basic overview on developing inside a remote container is here: https://code.visualstudio.com/docs/remote/containers-advanced#_developing-inside-a-container-on-a-remote-docker-host

- **Docker**: Both the Laptop and the Pi should have a recent version of Docker installed on them.
- **VS Code**: Should be installed on the Dev Laptop.
- **Passwordless SSH**: You should be able to SSH to the Pi using your RSA Key.
- Here is how you setup SSH on the Pi: https://www.raspberrypi.org/documentation/remote-access/ssh/
- Here is how you make it passwordless: https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md

## Setting things up

1. Figure out the IP Address for the Pi. This should stay static.
1. Install the SkyScan repo on the Pi. I have been installing it at: `/home/pi/Projects/SkyScan`
1. `mkdir -p /home/pi/Projects`
1. `cd /home/pi/Projects`
1. `git clone https://github.com/IQTLabs/SkyScan.git`
1. You can install it to other Directories, but you will need to modify some of the config files so it gets mapping into the containers correctly.
1. On the Dev Laptop:
1. Open up VSCode
1. Goto **File** and **Open Workspace** and select the SkyScan Workspace in the repo folder
1. Goto **View** and **Extensions**
1. Search for *Remote - Containers* and install it
1. Now open the **Extension Settings** for the extension:
![Extension Settings](./assets/extension-settings.png)
1. Select *Workspace Settings** and search for **Docker:Host**
![settings](./assets/docker-host.png)
1. Enter the command to SSH to the Pi. My Pi is at *192.168.1.47*, so I have the following command: `ssh:https://[email protected]`

1. Make sure you `.env` file is correctly configured. I am pretty sure that the .env is read in off the Dev Laptop, so you need to have it there. If you figure out it is reading the .env off the Pi, let me know.

## Running Things

It is pretty easy to get things running. I have found it is best to make sure all of the SkyScan containers are stopped on the Pi. This is because you do not want the Container you are going to be working on to be already running. You will want to be able to start and stop the process through the command line inside the terminal. The Dev Container setup starts a dummy process instead of the default Command. This lets you stop the main process without Docker Compose killing the whole container when it is stopped.

In short, go to the Pi, go to the SkyScan folder and run `docker-compose down`.

I have setup Dev Containers for 3 different SkyScan containers:
- tracker
- absd-mqtt
- axis-ptz

The Dev Container extends the default Docker Compose. It maps the folder with the Container's Python code into the **/workspace** folder inside the Container. Any changes you make in VS Code will be saved into the git repo for SkyScan on the Pi. If you have installed SkyScan into a different location on the Pi, you will need to update the **docker-compose** files in each of these folders on your Dev Laptop, eg **axis-ptz/docker-compose.axis-ptz.devcontainer.yml**.

When you start things, VS Code will spin up all of the Containers needed, along with a Dev Container for the one you are working on. Right now, I think you can only work on a single Container at a time. It maybe possible to Open a Second VS Code Window and start working on a second container, but I am not sure how you stop the Python Command started by the first window. Just stick to working on one Container at a time and you will be good.

## Let's Do This!

To open a Dev Container:
1. Click the Green Square in the lower left hand corner.
1. Then select **Open folder in container...**
1. After that select the folder for the container you want to open (tracker, axis-ptz, adsb-mqtt)
![open folder](./assets/open-folder.png)

After you do this, VS Code should start to bring up the containers on the Pi. You can check on them by logging into the Pi over SSH and running: `docker ps`. You can also follow along by checking out the logs. The initial load can take a while because the Pandas package has to be built from scratch. Once everything has finished, open the terminal by going to: **View** and **Terminal**. Then create a new terminal by clicking on the `+` in the Terminal window pane.

You should end up at **/workspace**. You are inside your selected container, which is running on the Pi. The **/workspace** folder is mapped into the container, so any changes you make will be saved locally on the Pi. You can use VS Code to open up different files and makes edits. When you are ready to run things, simple run `./start.sh` on the command line in the terminal. This will launch the Python program for the container you are working on using the default command line parameters. All of the environment variables should be brought into the Container (you can check by running `env`) and applied as parameters with you run `./start.sh`.

To stop the program, simply hit: **ctrl+c**

When you are all done, you can click on the Green Square in the lower left hand corner and select **Close Remote Connection**.

43 changes: 21 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ services:

tracker:
build: ./tracker
entrypoint: "./flighttracker.py -m mqtt -H piaware -l ${LAT} -L ${LONG} -a ${ALT} -P skyscan/planes/json -T skyscan/flight/json -M ${MIN_ELEVATION} -c ${CAMERA_LEAD}"
command: "./flighttracker.py -m mqtt -H piaware -l ${LAT} -L ${LONG} -a ${ALT} -P skyscan/planes/json -T skyscan/flight/json -M ${MIN_ELEVATION} -c ${CAMERA_LEAD}"
volumes:
- ./data:/app/data
- ./data:/data
depends_on:
- mqtt
restart: unless-stopped

# adsb-mqtt:
# build: ./adsb-mqtt
# entrypoint: "./adsb-mqtt.py -H piaware -m mqtt -t skyscan/planes/json"
# volumes:
# - ./data:/app/data
# depends_on:
# - mqtt
# - piaware
# restart: unless-stopped
adsb-mqtt:
build: ./adsb-mqtt
command: "./adsb-mqtt.py -H piaware -m mqtt -t skyscan/planes/json"
volumes:
- ./data:/data
depends_on:
- mqtt
- piaware
restart: unless-stopped

# pan-tilt-pi:
# build: ./pan-tilt-pi
Expand All @@ -38,7 +38,7 @@ services:

axis-ptz:
build: ./axis-ptz
entrypoint: "./camera.py -m mqtt -t skyscan/flight/json -u ${AXIS_USERNAME} -p ${AXIS_PASSWORD} -a ${AXIS_IP} -z ${CAMERA_ZOOM} -s ${CAMERA_MOVE_SPEED} -d ${CAMERA_DELAY}"
command: "./camera.py -m mqtt -t skyscan/flight/json -u ${AXIS_USERNAME} -p ${AXIS_PASSWORD} -a ${AXIS_IP} -z ${CAMERA_ZOOM} -s ${CAMERA_MOVE_SPEED} -d ${CAMERA_DELAY}"
volumes:
- ./capture:/app/capture
depends_on:
Expand All @@ -49,7 +49,6 @@ services:
build: ./piaware
tty: true
container_name: piaware
restart: always
devices:
- /dev/bus/usb:/dev/bus/usb
ports:
Expand All @@ -69,7 +68,6 @@ services:
image: mikenye/tar1090:latest
tty: true
container_name: tar1090
restart: always
environment:
- TZ=${TZ}
- BEASTHOST=piaware
Expand All @@ -81,18 +79,19 @@ services:
tmpfs:
- /run:exec,size=64M
- /var/log

mqtt:
build: ./mqtt
ports:
- "9001:9001"
- "1883:1883"
restart: unless-stopped

egi:
build: ./egi
entrypoint: bash -c "gpsd ${GPS_SERIAL} -F /var/run/gpsd.sock && python3 egi_mqtt.py -m mqtt -l ${LAT} -L ${LONG} -a ${ALT} -r ${ROLL} -p ${PITCH} -y ${YAW}"
devices:
- /dev/ttyACM0
depends_on:
- mqtt
restart: unless-stopped
# egi:
# build: ./egi
# entrypoint: bash -c "gpsd ${GPS_SERIAL} -F /var/run/gpsd.sock && python3 egi_mqtt.py -m mqtt -l ${LAT} -L ${LONG} -a ${ALT} -r ${ROLL} -p ${PITCH} -y ${YAW}"
# devices:
# - /dev/ttyACM0
# depends_on:
# - mqtt
# restart: unless-stopped
8 changes: 8 additions & 0 deletions tracker/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Plane Tracker",
"dockerComposeFile": ["../docker-compose.yml","./docker-compose.tracker.devcontainer.yml"], //"../docker-compose.devcontainer.yml",
"service": "tracker",
"shutdownAction": "none",
// Open the sub-folder with the source code
"workspaceFolder": "/workspace", //"/workspace/tracker",
}
11 changes: 11 additions & 0 deletions tracker/docker-compose.tracker.devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.7'

services:
tracker:
command: /bin/sh -c "while sleep 1000; do :; done"
volumes:
- /home/pi/Projects/SkyScan/tracker:/workspace:cached # Additional bind mount
- /home/pi/Projects/SkyScan/data:/data:cached # Additional bind mount
working_dir: /workspace
env_file: .env

2 changes: 1 addition & 1 deletion tracker/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ ADD *.txt /app/
RUN pip3 install -r requirements.txt
ADD *.py /app/
ADD mqtt_wrapper /app/mqtt_wrapper/
CMD ./flighttracker.py -H 192.168.1.218 -m broker.hivemq.com -t skyscan
#CMD ./flighttracker.py -H 192.168.1.218 -m broker.hivemq.com -t skyscan

2 changes: 1 addition & 1 deletion tracker/flighttracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def main():
'%(message)s')

logging.info("---[ Starting %s ]---------------------------------------------" % sys.argv[0])
planes = pd.read_csv("/app/data/aircraftDatabase.csv") #,index_col='icao24')
planes = pd.read_csv("/data/aircraftDatabase.csv") #,index_col='icao24')
logging.info("Printing table")
logging.info(planes)

Expand Down
1 change: 1 addition & 0 deletions tracker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./flighttracker.py -m mqtt -H piaware -l ${LAT} -L ${LONG} -a ${ALT} -P skyscan/planes/json -T skyscan/flight/json -M ${MIN_ELEVATION} -c ${CAMERA_LEAD}