diff --git a/.github/workflows/build-rock.yaml b/.github/workflows/build-rock.yaml new file mode 100644 index 0000000..d17e8af --- /dev/null +++ b/.github/workflows/build-rock.yaml @@ -0,0 +1,35 @@ +name: Build rock on PR + +on: + workflow_dispatch: {} + pull_request: + branches: + - main + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Determine any rockcraft.yaml changed in the PR + id: changed-files + uses: tj-actions/changed-files@v44 + with: + files: "./rockcraft.yaml" + + - name: Setup LXD + if: steps.changed-files.outputs.any_changed + uses: canonical/setup-lxd@v0.1.1 + with: + channel: latest/stable + + - name: Install dependencies + if: steps.changed-files.outputs.any_changed + run: | + sudo snap install --classic rockcraft + - name: Build ROCK + if: steps.changed-files.outputs.any_changed + run: | + rockcraft pack --verbose diff --git a/.github/workflows/rock-release-dev.yaml b/.github/workflows/rock-release-dev.yaml new file mode 100644 index 0000000..e1e7f9b --- /dev/null +++ b/.github/workflows/rock-release-dev.yaml @@ -0,0 +1,66 @@ +# The workflow canonical/observability/.github/workflows/rock-release-dev.yaml@main +# https://github.com/canonical/observability/blob/34b7edb56094e8e3f01200ce49e01bf9dd6688ac/.github/workflows/rock-release-dev.yaml +# does not allow setting a GHCR repo where to publish at the moment. +# We thus copy it below and adapt it. + +name: Build ROCK and release dev or branch tag to GHCR + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + main: + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Find the *latest* rockcraft.yaml + id: find-latest + run: | + latest_rockcraft_file=$(find $GITHUB_WORKSPACE -name "rockcraft.yaml" | sort -V | tail -n1) + rockcraft_dir=$(dirname ${latest_rockcraft_file#\./}) + echo "latest-dir=$rockcraft_dir" >> $GITHUB_OUTPUT + - name: Build ROCK + uses: canonical/craft-actions/rockcraft-pack@main + with: + path: "${{ steps.find-latest.outputs.latest-dir }}" + verbosity: verbose + id: rockcraft + + - name: Upload locally built ROCK artifact + uses: actions/upload-artifact@v4 + with: + name: ros2bag-fileserver + path: ${{ steps.rockcraft.outputs.rock }} + retention-days: 7 + + - name: Upload ROCK to ghcr.io + run: | + if [[ ${{ github.ref }} == 'refs/heads/main' ]] + then + TAG=dev + else + TAG=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + TAG=$(echo $TAG | sed "s|\/|\_|") + fi + sudo skopeo --insecure-policy copy oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) docker://ghcr.io/ubuntu-robotics/ros2bag-fileserver:$TAG --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" + - name: Generate digest + run: | + digest=$(skopeo inspect oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) --format '{{.Digest}}') + echo "digest=${digest#*:}" >> "$GITHUB_OUTPUT" + - name: Install Syft + run: | + curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin + - name: Create SBOM + run: syft $(realpath ${{ steps.rockcraft.outputs.rock }}) -o spdx-json=ros2bag-fileserver.sbom.json + + - name: Upload SBOM + uses: actions/upload-artifact@v4 + with: + name: ros2bag-fileserver-sbom + path: "ros2bag-fileserver.sbom.json" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43c6239 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.rock diff --git a/README.md b/README.md index ae7afb1..4cff682 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ #ROS 2 bag file server +This repository is hosting the rock to build the ROS 2 bag file server. +This rock is meant to be working with the [ros2bag-fileserver-k8s-operator](https://github.com/ubuntu-robotics/ros2bag-fileserver-k8s-operator). + +## How to build + +Build the rock: +``` +rockcraft pack +``` +Add the rock to the local docker images: +``` +sudo /snap/rockcraft/current/bin/skopeo --insecure-policy copy oci-archive:ros2bag-fileserver_0.1_amd64.rock docker-daemon:ros2bag-fileserver:dev +``` + diff --git a/rock/local/Caddyfile b/rock/local/Caddyfile new file mode 100644 index 0000000..09ae31f --- /dev/null +++ b/rock/local/Caddyfile @@ -0,0 +1,16 @@ +:80 { + # Set this path to your site's directory. + root * /var/lib/caddy-fileserver + + # Enable the static file server. + file_server browse + header { + Access-Control-Allow-Origin * + Access-Control-Allow-Methods GET, POST, PUT, DELETE, OPTIONS + Access-Control-Allow-Headers * + } + + log { + output file /var/log/access.log + } +} diff --git a/rockcraft.yaml b/rockcraft.yaml new file mode 100644 index 0000000..b494373 --- /dev/null +++ b/rockcraft.yaml @@ -0,0 +1,38 @@ +name: ros2bag-fileserver +summary: The ROS 2 bag fileserver +description: | + The ROS 2 bag fileserver to host + mcap files +version: '0.1' +license: GPL-3.0 + +base: ubuntu@22.04 +build-base: ubuntu@22.04 +platforms: + amd64: + +package-repositories: +- components: [main] + formats: [deb] + key-id: 65760C51EDEA2017CEA2CA15155B6D79CA56EA34 + key-server: keyserver.ubuntu.com + suites: [any-version] + type: apt + url: https://dl.cloudsmith.io/public/caddy/stable/deb/debian + +services: + ros2bag-fileserver: + override: replace + startup: enabled + command: /usr/bin/caddy run --config /srv/Caddyfile + +# Parts section +parts: + caddy: + plugin: dump + source: rock/local + stage-packages: [rsync, caddy] + overlay-packages: [openssh-server] + organize: + 'Caddyfile' : srv/ +