Skip to content

Commit

Permalink
feat: add source code and GitHub Actions CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jason53415 committed Oct 14, 2024
1 parent b18f6f1 commit 3c8c10c
Show file tree
Hide file tree
Showing 43 changed files with 2,645 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.devcontainer/
.git/
.github/
.idea/
.vscode/
scripts/
.dockerignore
.gitignore
.gitmodules
Dockerfile
LICENSE
README.md
87 changes: 87 additions & 0 deletions .github/workflows/docker_publish_ghcr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This YAML file is refered to
# https://youtu.be/RgZyX-e6W9E?si=iISxsuXEZKma4SVv
# https://youtu.be/Tx1UElRhELg?si=MrbyhgWCwlGVtgyD

name: Docker Image CI for GitHub Container Registry (GHCR)

on:
push:
tags:
- '*' # Triggered on new tag

env:
# Use docker.io for Docker Hub if empty
# Here we use GitHub Container Registry (GHCR) to store our images
REGISTRY: ghcr.io

jobs:
build_and_publish:
runs-on: ubuntu-latest
name: Build and Push Docker Image

steps:
# This is going to pull our code from the repository
# into the actions runner in order to build the image
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
# Choose one method
# 1. Use login-action
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# 2. Use command line
# run: |
# docker login ${{ env.REGISTRY }} --username ${{ github.actor }} --password ${{ secrets.DOCKER_PAT }}

# Set image name to lowercase repository name
- name: Set image name
run: |
IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
# Choose one method
# 1. Use build-push-action
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} , ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
# TODO: Improve pipeline with https://docs.docker.com/build/ci/github-actions/multi-platform/
platforms: linux/arm64,linux/amd64 # ,linux/arm/v7
# 2. Use command lines
# run: docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} -f ./Dockerfile --push .
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
devel/
logs/
build/
bin/
msg_gen/
srv_gen/
msg/*Action.msg
msg/*ActionFeedback.msg
msg/*ActionGoal.msg
msg/*ActionResult.msg
msg/*Feedback.msg
msg/*Goal.msg
msg/*Result.msg
msg/_*.py
build_isolated/
devel_isolated/

# Generated by dynamic reconfigure
*.cfgc
/cfg/cpp/
/cfg/*.py

# Ignore generated docs
*.dox
*.wikidoc

# eclipse stuff
.project
.cproject

# qcreator stuff
CMakeLists.txt.user

srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user

/planning/cfg
/planning/docs
/planning/src

*~

# Emacs
.#*

# Catkin custom files
CATKIN_IGNORE
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ghcr.io/otischung/pros_ai_image:1.3.6
ENV ROS2_WS=/workspaces
ENV ROS_DOMAIN_ID=1
ENV ROS_DISTRO=humble
ARG THREADS=4
ARG TARGETPLATFORM

##### Copy Source Code #####
COPY . /tmp

##### Environment Settings #####
WORKDIR ${ROS2_WS}

##### colcon Installation #####
# Copy source code
RUN mv /tmp/src/yolov8 ${ROS2_WS}/src/yolov8 && \
### YOLOv8 Installation ###
pip3 install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu && \
pip3 install --no-cache-dir ncnn ultralytics typing-extensions opencv-python && \
source /opt/ros/humble/setup.bash && \
colcon build --packages-select yolov8_msgs --symlink-install && \
colcon build --packages-select yolov8_ros --symlink-install && \
colcon build --packages-select yolov8_bringup --symlink-install && \
##### Post-Settings #####
# Clear tmp and cache
rm -rf /tmp/* && \
rm -rf /temp/* && \
rm -rf /var/lib/apt/lists/*

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

export set=false
export IMG_NAME="pros_jetson_driver_image"
export ECR_URL="ghcr.io/screamlab"
export TODAY=$(date +%Y%m%d)
export DOCKER_CLI_EXPERIMENTAL=enabled

# Function to display a usage message
usage() {
echo "Usage: $0 -j <threads>"
exit 0
}

# Parse command-line options
while [ "$#" -gt 0 ]; do
case "$1" in
-j)
threads="$2"
set=true
shift 2
;;
-h)
usage
shift
exit 0
;;
--help)
usage
exit 0
;;
*)
usage
;;
esac
done

# The regular expression matches digits only
# Ref: https://www.cyberciti.biz/faq/bash-see-check-input-number-integer-in-linux-script/
if ! [[ "$threads" =~ ^[0-9]+$ ]] && ! [[ "$threads" =~ ^[-][0-9]+$ ]]; then
echo "$0 - $threads is NOT an integer. Ignoring."
set=false
fi

if [ "$set" = true ]; then
docker build \
--tag $ECR_URL/$IMG_NAME:latest \
--tag $ECR_URL/$IMG_NAME:$TODAY \
--build-arg THREADS=$threads \
-f ./Dockerfile .
else
docker build \
--tag $ECR_URL/$IMG_NAME:latest \
--tag $ECR_URL/$IMG_NAME:$TODAY \
-f ./Dockerfile .
fi
44 changes: 44 additions & 0 deletions scripts/local_buildx_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

export IMG_NAME="pros_jetson_driver_image"
export ECR_URL="ghcr.io/screamlab"
export TAG=$(date +%Y%m%d)
export DOCKER_CLI_EXPERIMENTAL=enabled

# Function to display a usage message
usage() {
echo "Usage: $0 -t <tag>"
exit 0
}

# Parse command-line options
while [ "$#" -gt 0 ]; do
case "$1" in
-t)
TAG="$2"
shift 2
;;
-h)
usage
shift
exit 0
;;
--help)
usage
exit 0
;;
*)
usage
;;
esac
done

echo "Using tag: $TAG"
docker run --rm --privileged tonistiigi/binfmt:latest
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-*
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder
docker buildx inspect --bootstrap
docker buildx build --no-cache --platform=linux/arm64,linux/amd64 --push \
--tag $ECR_URL/$IMG_NAME:$TAG \
-f ./Dockerfile .
93 changes: 93 additions & 0 deletions src/yolov8/models/yolov8n_ncnn_model/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
description: Ultralytics YOLOv8n model trained on coco.yaml
author: Ultralytics
date: '2024-08-28T01:15:03.558971'
version: 8.2.82
license: AGPL-3.0 License (https://ultralytics.com/license)
docs: https://docs.ultralytics.com
stride: 32
task: detect
batch: 1
imgsz:
- 640
- 640
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush
Binary file not shown.
Loading

0 comments on commit 3c8c10c

Please sign in to comment.