diff --git a/.github/workflows/pr-docker-build.yml b/.github/workflows/pr-docker-build.yml new file mode 100644 index 000000000..742677dee --- /dev/null +++ b/.github/workflows/pr-docker-build.yml @@ -0,0 +1,44 @@ +name: PR Docker Build Check + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: 'arm64,arm' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + # Enable docker layer caching + buildkitd-flags: --debug + + - name: Build Docker image + uses: docker/build-push-action@v5 + timeout-minutes: 30 + with: + context: ./raspberry_pi + cache-from: type=gha + cache-to: type=gha,mode=max` + platforms: linux/arm64,linux/arm/v7 + push: false + tags: team100-pi:${{ github.sha }} + + # - name: Add PR Comment on Failure + # if: failure() + # uses: actions/github-script@v7 + # with: + # script: | + # github.rest.issues.createComment({ + # issue_number: context.issue.number, + # owner: context.repo.owner, + # repo: context.repo.repo, + # body: '❌ Docker build failed! Please check the workflow logs for details.' + # }) \ No newline at end of file diff --git a/.github/workflows/swerve-100-build.yml b/.github/workflows/swerve-100-build.yml new file mode 100644 index 000000000..3fbe7967b --- /dev/null +++ b/.github/workflows/swerve-100-build.yml @@ -0,0 +1,44 @@ +name: Swerve100 Docker Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v3 + # with: + # platforms: 'arm64,arm' + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 + # with: + # # Enable docker layer caching + # buildkitd-flags: --debug + + - name: Build Docker image + uses: docker/build-push-action@v5 + timeout-minutes: 30 + with: + context: . + # cache-from: type=gha + # cache-to: type=gha,mode=max` + # platforms: linux/arm64,linux/arm/v7 + push: false + tags: team100-pi:${{ github.sha }} + + # - name: Add PR Comment on Failure + # if: failure() + # uses: actions/github-script@v7 + # with: + # script: | + # github.rest.issues.createComment({ + # issue_number: context.issue.number, + # owner: context.repo.owner, + # repo: context.repo.repo, + # body: '❌ Docker build failed! Please check the workflow logs for details.' + # }) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c9f00eae2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Use the same WPILib container as the GitHub Action +FROM wpilib/roborio-cross-ubuntu:2024-22.04 + +# Set working directory +WORKDIR /team100/comp/swerve100 + +# Copy only wrapper files first +COPY comp/swerve100/gradle ./gradle +COPY comp/swerve100/gradlew comp/swerve100/gradlew.bat ./ + +# Make gradlew executable (same as in GitHub Action) +RUN chmod +x gradlew + +# Copy build configuration +COPY comp/swerve100/*.gradle comp/swerve100/gradle.properties ./ + +# Download dependencies using wrapper +RUN ./gradlew + +# Lib doesn't change often; copy before the other code +WORKDIR /team100 +COPY lib ./lib + +# Now copy the rest of your code +WORKDIR /team100/comp/swerve100 +COPY comp/swerve100/src ./src + +# Build and test (same command as in GitHub Action) +RUN ./gradlew build \ No newline at end of file diff --git a/Dockerfile copy b/Dockerfile copy new file mode 100644 index 000000000..e9cfd0a40 --- /dev/null +++ b/Dockerfile copy @@ -0,0 +1,31 @@ +FROM wpilib/roborio-cross-ubuntu:2024-22.04 + +WORKDIR /app + +# Copy only wrapper files first +COPY gradle ./gradle +COPY gradlew gradlew.bat ./ + +# Make gradlew executable +RUN chmod +x gradlew + +# Copy build configuration +COPY *.gradle gradle.properties ./ + + +# Download dependencies using wrapper +RUN --mount=type=cache,target=/root/.gradle ./gradlew --build-cache dependencies +RUN ./gradlew + +# Create a custom gradle.properties to override desktop/simulation settings +RUN echo "includeDesktopSupport=false" > gradle.properties + +# Now copy the rest of your code +COPY src ./src + +# Build with specific options, focusing only on robot code +RUN ./gradlew build --no-daemon \ + -PskipTests \ + -x simulateJava \ + -x test + diff --git a/comp/swerve100/.wpilib/wpilib_preferences.json b/comp/swerve100/.wpilib/wpilib_preferences.json index 652e4a8a8..37f3c653c 100644 --- a/comp/swerve100/.wpilib/wpilib_preferences.json +++ b/comp/swerve100/.wpilib/wpilib_preferences.json @@ -3,4 +3,4 @@ "currentLanguage": "java", "projectYear": "2024beta", "teamNumber": 100 -} +} \ No newline at end of file diff --git a/comp/swerve100/Dockerfile.orig b/comp/swerve100/Dockerfile.orig new file mode 100644 index 000000000..61a34d6bb --- /dev/null +++ b/comp/swerve100/Dockerfile.orig @@ -0,0 +1,46 @@ +FROM eclipse-temurin:17-jdk + +# Install necessary tools +RUN apt-get update && apt-get install -y \ + curl \ + unzip \ + vim \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory in the container +WORKDIR /app + +# Install Gradle +ENV GRADLE_VERSION=8.4 +RUN curl -L https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -o gradle.zip \ + && unzip gradle.zip \ + && rm gradle.zip \ + && mv gradle-${GRADLE_VERSION} /opt/gradle \ + && ln -s /opt/gradle/bin/gradle /usr/bin/gradle + +# Set Gradle environment variables +ENV GRADLE_HOME=/opt/gradle +ENV PATH=$PATH:$GRADLE_HOME/bin + +# Copy just the build.gradle and gradle files +COPY build.gradle settings.gradle gradle.properties ./ +COPY gradle ./gradle +# COPY gradlew ./ + +# Make the gradlew script executable +# RUN chmod +x ./gradlew + +# Download dependencies +RUN --mount=type=cache,target=/root/.gradle gradle --build-cache dependencies + +# Now copy the rest of your code +COPY . . + +# Build the project +# RUN --mount=type=cache,target=/root/.gradle gradle --build-cache build --offline + +# Expose the JMX port +# EXPOSE 1099 + +# Run the Java application +# CMD ["gradle", "run"] diff --git a/comp/swerve100/README.md b/comp/swerve100/README.md index c1cb0f4b9..793d704e1 100644 --- a/comp/swerve100/README.md +++ b/comp/swerve100/README.md @@ -4,3 +4,13 @@ This is the main comp bot repo. Part of the code here was (somewhat distantly) derived from 254 code, and other parts were inspired by Roadrunner. +# Starting Development + +1. Make sure you have Java installed. Download it [here](https://www.oracle.com/java/technologies/downloads/). +1. From your command line you should be able to run: + `./gradlew build` . This should start downloading all the relevant libraries and install them. +1. Visit the WPILib installation instructions [here](https://docs.wpilib.org/en/stable/docs/zero-to-robot/step-2/offline-installation-preparations.html). This is a big file and will take a while to download + install. +1. Once installed, + +# Misc +https://docs.wpilib.org/en/stable/docs/software/vscode-overview/deploying-robot-code.html \ No newline at end of file diff --git a/comp/swerve100/build.gradle b/comp/swerve100/build.gradle index ac85b2003..13aa1eff9 100644 --- a/comp/swerve100/build.gradle +++ b/comp/swerve100/build.gradle @@ -42,7 +42,10 @@ deploy { // or from command line. If not found an exception will be thrown. // You can use getTeamOrDefault(team) instead of getTeamNumber if you // want to store a team number in this file. - team = project.frc.getTeamNumber() + // team = project.frc.getTeamNumber() + // TODO(dmontauk): a better approach would be to have build dependencies pulled separately + // from the actual build. + team = project.frc.getTeamOrDefault(100) debug = project.frc.getDebugOrDefault(false) artifacts { @@ -218,3 +221,14 @@ wpi.java.configureTestTasks(test) tasks.withType(JavaCompile) { options.compilerArgs.add '-XDstringConcat=inline' } + +// Add this at the end of your build.gradle file +task downloadDependencies() { + doLast { + configurations.all { c -> + if (c.canBeResolved) { + c.resolve() + } + } + } +} diff --git a/comp/swerve100/setup_dev_container.sh b/comp/swerve100/setup_dev_container.sh new file mode 100644 index 000000000..0519ecba6 --- /dev/null +++ b/comp/swerve100/setup_dev_container.sh @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/comp/swerve100/swerve100.code-workspace b/comp/swerve100/swerve100.code-workspace index da6075ce1..c1b05f9c7 100644 --- a/comp/swerve100/swerve100.code-workspace +++ b/comp/swerve100/swerve100.code-workspace @@ -11,7 +11,7 @@ "java.configuration.updateBuildConfiguration": "automatic", "java.server.launchMode": "Standard", "terminal.integrated.scrollback": 100000, - "workbench.colorTheme": "Default Light+", + "workbench.colorTheme": "Anysphere", "files.autoSave": "afterDelay", "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx32G -Xms100m -Xlog:disable", "workbench.editor.revealIfOpen": true, diff --git a/raspberry_pi/.devcontainer/Dockerfile b/raspberry_pi/.devcontainer/Dockerfile new file mode 100644 index 000000000..0519ecba6 --- /dev/null +++ b/raspberry_pi/.devcontainer/Dockerfile @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/raspberry_pi/.devcontainer/devcontainer.json b/raspberry_pi/.devcontainer/devcontainer.json new file mode 100644 index 000000000..0519ecba6 --- /dev/null +++ b/raspberry_pi/.devcontainer/devcontainer.json @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/raspberry_pi/.vscode/launch.json b/raspberry_pi/.vscode/launch.json new file mode 100644 index 000000000..8858414db --- /dev/null +++ b/raspberry_pi/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Docker: Attach to Vision App", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/team100" + } + ], + }, + ] +} \ No newline at end of file diff --git a/raspberry_pi/.vscode/settings.json b/raspberry_pi/.vscode/settings.json index c6d4db8f2..ececd0038 100644 --- a/raspberry_pi/.vscode/settings.json +++ b/raspberry_pi/.vscode/settings.json @@ -9,7 +9,7 @@ ], "python.testing.pytestEnabled": false, "python.testing.unittestEnabled": true, - "workbench.colorTheme": "Default Light Modern", + "workbench.colorTheme": "Default Dark Modern", "editor.minimap.enabled": false, "python.analysis.typeCheckingMode": "standard", "mypy-type-checker.reportingScope": "workspace", diff --git a/raspberry_pi/Dockerfile b/raspberry_pi/Dockerfile new file mode 100644 index 000000000..b290a28a3 --- /dev/null +++ b/raspberry_pi/Dockerfile @@ -0,0 +1,65 @@ +# Use the official Raspberry Pi OS image as a base +FROM dtcooper/raspberrypi-os:bookworm + +# Install system dependencies +RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries +RUN apt-get update +RUN apt-get install -y python3-pip +RUN apt-get install -y python3-setuptools +RUN apt-get install -y python3-wheel +RUN apt-get install -y python3-numpy +RUN apt-get install -y libcamera-dev +RUN apt-get install -y python3-aiohttp +RUN apt-get install -y python3-opencv +RUN apt-get install -y python3-venv +RUN apt-get install -y build-essential +RUN apt-get install -y python3-dev + +RUN apt-get clean && rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +# Create a virtual environment +RUN python3 -m venv /team100/venv + +# Activate the virtual environment +ENV PATH="/team100/venv/bin:$PATH" + +# Copy requirements file +COPY requirements.txt /tmp/requirements.txt + +# Install dependencies in the virtual environment +# RUN pip3 install --no-cache-dir -r /tmp/requirements.txt +RUN pip3 install hidapi +RUN pip3 install adafruit-blinka +RUN pip3 install adafruit-circuitpython-lsm6ds +RUN pip3 install debugpy +RUN pip3 install numpy +RUN pip3 install aiohttp +# RUN pip3 install opencv-python +# RUN pip3 install --prefer-binary robotpy-wpiutil +# RUN pip3 install --prefer-binary robotpy-wpimath +# RUN pip3 install --prefer-binary robotpy-wpinet +# RUN pip3 install --prefer-binary robotpy-hal +# RUN pip3 install --prefer-binary robotpy-halsim +# RUN pip3 install --prefer-binary robotpy-commands-v2 +# RUN pip3 install --prefer-binary robotpy +# # Then install the additional robotpy packages +# RUN pip3 install robotpy-cscore +# RUN pip3 install robotpy-apriltag + +# Create app directory +WORKDIR /team100 + +# Copy the app files +COPY app /team100/app +COPY app/config /team100/app/config + +# Copy the runapp.py script +COPY runapp.py /team100/runapp.py + +# Remove any __pycache__ directories +#RUN find /team100 -type d -name "__pycache__" -exec rm -rf {} + +EXPOSE 5678 + +# Set the entrypoint to run the app with debugger +#ENTRYPOINT ["python3", "-m", "debugpy", "--listen", "0.0.0.0:5678", "runapp.py"] diff --git a/raspberry_pi/app/fake_display.py b/raspberry_pi/app/fake_display.py new file mode 100644 index 000000000..64f9bf126 --- /dev/null +++ b/raspberry_pi/app/fake_display.py @@ -0,0 +1,12 @@ +class Display: + def __init__(self, width, height, camera_num) -> None: + pass + + def draw_result(self, image, result_item, pose) -> None: + pass + + def draw_text(self, image, msg, loc) -> None: + pass + + def put_frame(self, img) -> None: + pass diff --git a/raspberry_pi/requirements.txt b/raspberry_pi/requirements.txt new file mode 100644 index 000000000..a9e6e3f6e --- /dev/null +++ b/raspberry_pi/requirements.txt @@ -0,0 +1,6 @@ +hidapi +adafruit-blinka +adafruit-circuitpython-lsm6ds +robotpy +robotpy-cscore +robotpy-apriltag \ No newline at end of file