diff --git a/.github/workflows/build-and-push-docker.yaml b/.github/workflows/build-and-push-docker.yaml deleted file mode 100644 index 06f9fbb9..00000000 --- a/.github/workflows/build-and-push-docker.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build and Push Docker Image - -on: - push: - branches: - - main - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - - steps: - - name: Check out the repository - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - with: - platforms: 'linux/amd64,linux/arm64,linux/arm/v7' - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to the Container registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Read version from file - run: | - cat version >> $GITHUB_ENV - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - push: true - tags: | - ghcr.io/kit-mrt/arbitration_graphs:latest - ghcr.io/kit-mrt/arbitration_graphs:${{ env.VERSION }} diff --git a/.github/workflows/bump-version-and-create-release-and-push-docker-images.yaml b/.github/workflows/bump-version-and-create-release-and-push-docker-images.yaml new file mode 100644 index 00000000..861d335c --- /dev/null +++ b/.github/workflows/bump-version-and-create-release-and-push-docker-images.yaml @@ -0,0 +1,185 @@ +name: Bump version, create and test release, and push Docker images +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + compute-version: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + new_tag: ${{ steps.bump_version.outputs.new_tag }} + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Read version from file + run: | + # Read the version from the version file, only store the number (without the 'v') + INITIAL_VERSION=$(source version && echo ${VERSION#v}) + echo "Current version: $INITIAL_VERSION" + echo "INITIAL_VERSION=${INITIAL_VERSION}" >> $GITHUB_ENV + + - name: Bump version + id: bump_version + uses: anothrNick/github-tag-action@v1 + env: + DEFAULT_BUMP: minor + DRY_RUN: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + INITIAL_VERSION: ${{ env.INITIAL_VERSION }} + WITH_V: true + + + update-version-file: + needs: compute-version + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Check out the repository + uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.DEPLOY_KEY }} + + - name: Update version file with new version + run: | + echo "New version: ${{ needs.compute-version.outputs.new_tag }}" + echo "VERSION=${{ needs.compute-version.outputs.new_tag }}" > version + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git add version + git commit -m "chore: update version file to ${{ needs.compute-version.outputs.new_tag }}" + git push + + - name: Push new tag + run: | + git tag ${{ needs.compute-version.outputs.new_tag }} + git push origin ${{ needs.compute-version.outputs.new_tag }} + + + create-release: + needs: [compute-version, update-version-file] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Check out the repository and pull the new tag + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ needs.compute-version.outputs.new_tag }} + + - name: Build release packages + uses: docker/build-push-action@v6 + with: + context: . + push: false + tags: | + release_builder + target: release + + - name: Copy release packages + run: | + mkdir -p /tmp/artifacts/ + docker run --rm -v /tmp/artifacts:/tmp/artifacts release_builder cp -r /release /tmp/artifacts/ + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + artifacts: "/tmp/artifacts/release/*" + tag: ${{ needs.compute-version.outputs.new_tag }} + body: ${{ github.event.pull_request.body }} + + build-and-run-release-tests: + needs: [compute-version, create-release] + runs-on: ubuntu-latest + steps: + - name: Build release core test Docker image + uses: docker/build-push-action@v6 + with: + build-args: | + RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/download/${{ needs.compute-version.outputs.new_tag }} + push: false + tags: release_tester_core + target: release_test_core + + - name: Run core unit tests with/against released version + run: | + docker run --rm release_tester_core + + - name: Build release gui test Docker image + uses: docker/build-push-action@v6 + with: + build-args: | + RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/download/${{ needs.compute-version.outputs.new_tag }} + push: false + tags: release_tester_gui + target: release_test_gui + + - name: Run gui unit tests with/against released version + run: | + docker run --rm release_tester_gui + + build-and-push-images: + needs: [compute-version, build-and-run-release-tests] + runs-on: ubuntu-latest + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: 'linux/amd64,linux/arm64,linux/arm/v7' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push core library Docker image + uses: docker/build-push-action@v6 + with: + push: true + tags: | + ghcr.io/kit-mrt/arbitration_graphs:latest + ghcr.io/kit-mrt/arbitration_graphs:${{ needs.compute-version.outputs.new_tag }} + target: install + + - name: Build and push Pacman demo Docker image + uses: docker/build-push-action@v6 + with: + build-args: | + VERSION=${{ needs.compute-version.outputs.new_tag }} + context: demo + file: demo/Dockerfile + push: true + tags: | + ghcr.io/kit-mrt/arbitration_graphs_pacman_demo:latest + ghcr.io/kit-mrt/arbitration_graphs_pacman_demo:${{ needs.compute-version.outputs.new_tag }} + target: demo + + - name: Build and push Pacman tutorial Docker image + uses: docker/build-push-action@v6 + with: + build-args: | + VERSION=${{ needs.compute-version.outputs.new_tag }} + context: demo + file: demo/Dockerfile + push: true + tags: | + ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:latest + ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:${{ needs.compute-version.outputs.new_tag }} + target: tutorial + diff --git a/.github/workflows/run-unit-tests.yaml b/.github/workflows/run-unit-tests.yaml new file mode 100644 index 00000000..a3850bb7 --- /dev/null +++ b/.github/workflows/run-unit-tests.yaml @@ -0,0 +1,53 @@ +name: Run unit tests + +on: + push: + +jobs: + build-and-run-unit-tests: + runs-on: ubuntu-latest + + steps: + - name: Check out the repository + uses: actions/checkout@v4 + + - name: Read version from file + run: | + cat version >> $GITHUB_ENV + + - name: Build and core library Docker image using current repo state + uses: docker/build-push-action@v6 + with: + push: false + tags: | + ghcr.io/kit-mrt/arbitration_graphs:${{ env.VERSION }} + target: install + + - name: Build core library unit test Docker image + uses: docker/build-push-action@v6 + with: + push: false + tags: | + ghcr.io/kit-mrt/arbitration_graphs_tests:${{ env.VERSION }} + target: unit_test + + - name: Run library unit tests + run: | + docker run --rm ghcr.io/kit-mrt/arbitration_graphs_tests:${{ env.VERSION }} + + - name: Build Pacman demo unit test Docker image + uses: docker/build-push-action@v6 + with: + build-args: | + VERSION=${{ env.VERSION }} + context: demo + file: demo/Dockerfile + push: false + tags: | + ghcr.io/kit-mrt/arbitration_graphs_pacman_demo_tests:latest + ghcr.io/kit-mrt/arbitration_graphs_pacman_demo_tests:${{ env.VERSION }} + target: unit_test + + - name: Run demo unit tests + run: | + docker run --rm ghcr.io/kit-mrt/arbitration_graphs_pacman_demo_tests:${{ env.VERSION }} diff --git a/Dockerfile b/Dockerfile index 83420625..58d12da9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,8 @@ +# ========== +# Base image +# ========== + + FROM ubuntu:22.04 AS base ARG DEBIAN_FRONTEND=noninteractive @@ -33,6 +38,10 @@ RUN dpkg -i /tmp/debfiles/*.deb && \ rm -rf /tmp/debfiles +# =========== +# Development +# =========== + FROM base AS devel @@ -42,10 +51,107 @@ USER blinky WORKDIR /home/blinky/ +# ========== +# Unit tests +# ========== + +FROM base AS unit_test + +COPY CMakeLists.txt /tmp/arbitration_graphs/ +COPY LICENSE /tmp/arbitration_graphs/ +COPY README.md /tmp/arbitration_graphs/ +COPY cmake /tmp/arbitration_graphs/cmake +COPY gui /tmp/arbitration_graphs/gui +COPY include /tmp/arbitration_graphs/include +COPY test /tmp/arbitration_graphs/test +COPY version /tmp/arbitration_graphs/version + +WORKDIR /tmp/arbitration_graphs/build + +RUN cmake -DBUILD_TESTS=true .. && \ + cmake --build . -j9 + +# Run unit tests +CMD ["cmake", "--build", ".", "--target", "test"] + + +# ======= +# Release +# ======= + +FROM base AS release + +COPY CMakeLists.txt /tmp/arbitration_graphs/ +COPY LICENSE /tmp/arbitration_graphs/ +COPY README.md /tmp/arbitration_graphs/ +COPY version /tmp/arbitration_graphs/ +COPY cmake /tmp/arbitration_graphs/cmake +COPY gui /tmp/arbitration_graphs/gui +COPY include /tmp/arbitration_graphs/include + +WORKDIR /tmp/arbitration_graphs/build + +RUN cmake .. && \ + cmake --build . && \ + cmake --build . --target package && \ + mv packages /release && \ + rm -rf /tmp/arbitration_graphs + + +# ============= +# Release tests +# ============= + +FROM base AS release_test_core + +ARG RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/latest/download/ + +# This downloads the latest arbitration_graph debian release and adds it to the docker image +# This "bloats" the image. But otherwise, we'd have to installing wget and ca-certificates +# temporarily to download and install the package in one docker layer… +ADD ${RELEASE_DOWNLOAD_URL}/libarbitration-graphs-core-dev.deb /tmp/debfiles/ + +# Install arbitration_graphs core library from release debian package +RUN dpkg -i /tmp/debfiles/*.deb && \ + rm -rf /tmp/debfiles + +COPY test /tmp/arbitration_graphs_test +WORKDIR /tmp/arbitration_graphs_test/build + +RUN cmake .. && \ + cmake --build . -j9 + +CMD ["cmake", "--build", ".", "--target", "test"] + +FROM base AS release_test_gui + +ARG RELEASE_DOWNLOAD_URL=https://github.com/KIT-MRT/arbitration_graphs/releases/latest/download/ + +# This downloads the latest arbitration_graph debian release and adds it to the docker image +# This "bloats" the image. But otherwise, we'd have to installing wget and ca-certificates +# temporarily to download and install the package in one docker layer… +ADD ${RELEASE_DOWNLOAD_URL}/libarbitration-graphs-core-dev.deb /tmp/debfiles/ +ADD ${RELEASE_DOWNLOAD_URL}/libarbitration-graphs-gui-dev.deb /tmp/debfiles/ + +# Install arbitration_graphs gui from release debian package +RUN dpkg -i /tmp/debfiles/*.deb && \ + rm -rf /tmp/debfiles + +COPY gui/test /tmp/arbitration_graphs_test +WORKDIR /tmp/arbitration_graphs_test/build + +RUN cmake .. && \ + cmake --build . -j9 + +CMD ["cmake", "--build", ".", "--target", "test"] + + +# ======= +# Install +# ======= FROM base AS install -# Install arbitration_graphs COPY CMakeLists.txt /tmp/arbitration_graphs/ COPY LICENSE /tmp/arbitration_graphs/ COPY README.md /tmp/arbitration_graphs/ @@ -55,9 +161,10 @@ COPY gui /tmp/arbitration_graphs/gui COPY include /tmp/arbitration_graphs/include COPY test /tmp/arbitration_graphs/test -RUN mkdir /tmp/arbitration_graphs/build && \ - cd /tmp/arbitration_graphs/build && \ - cmake .. && \ +WORKDIR /tmp/arbitration_graphs/build + +RUN cmake .. && \ cmake --build . && \ cmake --install . && \ - rm -rf /tmp/arbitration_graphs \ No newline at end of file + rm -rf /tmp/arbitration_graphs + diff --git a/README.md b/README.md index 0c89b9ee..f1c92ac6 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,31 @@ We will shortly add a [tutorial](https://github.com/KIT-MRT/arbitration_graphs/p ## Installation -From easy to advanced: +### Prerequisites -### Using Docker image +First make sure all dependencies are installed: +- [glog](https://github.com/google/glog) +- [Googletest](https://github.com/google/googletest) (optional, if you want to build unit tests) +- [yaml-cpp](https://github.com/jbeder/yaml-cpp) +- [util_caching](https://github.com/KIT-MRT/util_caching) +- [Crow](https://crowcpp.org) (optional, needed for GUI only) + +See also the [`Dockerfile`](./Dockerfile) for how to install these packages under Debian or Ubuntu. + +### Installation using Debian package (recommended) + +We provide a Debian package for easy installation on Debian-based distributions. +Download the latest `.deb` packages for the [core library](https://github.com/KIT-MRT/arbitration_graphs/releases/latest/download/libarbitration-graphs-core-dev.deb) +and optionally for [the gui](https://github.com/KIT-MRT/arbitration_graphs/releases/latest/download/libarbitration-graphs-gui-dev.deb) install them with `dpkg`: + +```bash +sudo dpkg -i libarbitration-graphs-core-dev.deb +sudo dpkg -i libarbitration-graphs-gui-dev.deb +``` + +### Using Docker image with pre-installed library -We provide a Docker image with the library already installed globally. +We provide a Docker image with the library and all dependencies already installed globally. ```bash docker pull ghcr.io/kit-mrt/arbitration_graphs @@ -91,16 +111,7 @@ find_package(arbitration_graphs REQUIRED) ### Building from source using CMake -First make sure all dependencies are installed: -- [glog](https://github.com/google/glog) -- [Googletest](https://github.com/google/googletest) (optional, if you want to build unit tests) -- [yaml-cpp](https://github.com/jbeder/yaml-cpp) -- [util_caching](https://github.com/KIT-MRT/util_caching) -- [Crow](https://crowcpp.org) (optional, needed for GUI only) - -See also the [`Dockerfile`](./Dockerfile) for how to install these packages under Debian or Ubuntu. - -Now, clone the repository: +Clone the repository: ```bash git clone https://github.com/KIT-MRT/arbitration_graphs.git diff --git a/demo/Dockerfile b/demo/Dockerfile index 1fc477ee..2f9e68ba 100644 --- a/demo/Dockerfile +++ b/demo/Dockerfile @@ -30,6 +30,25 @@ WORKDIR /home/blinky/demo CMD [ "/bin/bash" ] + +FROM tutorial AS unit_test + +COPY --chown=blinky:blinky cmake /home/blinky/demo/cmake +COPY --chown=blinky:blinky include /home/blinky/demo/include +COPY --chown=blinky:blinky src /home/blinky/demo/src +COPY --chown=blinky:blinky test /home/blinky/demo/test +COPY --chown=blinky:blinky CMakeLists.txt /home/blinky/demo/CMakeLists.txt + +WORKDIR /home/blinky/demo/build + +RUN cmake -DBUILD_TESTS=true .. && \ + cmake --build . -j8 + +# Run unit tests +CMD ["cmake", "--build", ".", "--target", "test"] + + + FROM tutorial AS demo COPY --chown=blinky:blinky cmake /home/blinky/demo/cmake diff --git a/demo/docker-compose.yaml b/demo/docker-compose.yaml index fea43e6e..f18bde66 100644 --- a/demo/docker-compose.yaml +++ b/demo/docker-compose.yaml @@ -1,11 +1,6 @@ services: tutorial: image: ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:$VERSION - build: - context: . - args: - - VERSION=$VERSION - target: tutorial env_file: .env ports: - "8080:8080" @@ -22,11 +17,6 @@ services: demo: image: ghcr.io/kit-mrt/arbitration_graphs_pacman_demo:$VERSION - build: - context: . - args: - - VERSION=$VERSION - target: demo env_file: .env ports: - "8080:8080" diff --git a/docker-compose.yaml b/docker-compose.yaml index 26bfbcf3..480c7684 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,14 +1,15 @@ services: arbitration_graphs: image: ghcr.io/kit-mrt/arbitration_graphs:$VERSION - build: . env_file: .env + arbitration_graphs_devel: build: context: . target: devel extends: service: arbitration_graphs - image: arbitration_graphs_devel + image: arbitration_graphs_devel:$VERSION volumes: - .:/home/blinky/arbitration_graphs +