From 24cdb1a559430a19257dadd2e3ec2c46fc92511b Mon Sep 17 00:00:00 2001 From: Erik Jaegervall Date: Thu, 7 Mar 2024 14:59:55 +0100 Subject: [PATCH] Improve builds part 2 --- .github/workflows/README.md | 2 - .github/workflows/hvac_integration_test.yml | 6 -- .github/workflows/seat_service.yml | 4 +- hvac_service/README.md | 2 +- seat_service/.devcontainer/devcontainer.json | 4 -- seat_service/Dockerfile | 2 +- seat_service/README.md | 68 ++++++++++++++------ 7 files changed, 51 insertions(+), 37 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 3691610..e24c03b 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -5,8 +5,6 @@ * for sub components like hvac_service and seat_service use pattern: **\_\ eg: hvac_service** -* for overall tasks use pattern: - **\ eg: release** ## Naming of Tags diff --git a/.github/workflows/hvac_integration_test.yml b/.github/workflows/hvac_integration_test.yml index 015c86f..05796ee 100644 --- a/.github/workflows/hvac_integration_test.yml +++ b/.github/workflows/hvac_integration_test.yml @@ -31,13 +31,7 @@ concurrency: jobs: integration-test: - # reduce runtime requirements from libc/libc++ runs-on: ubuntu-20.04 - # container: - # image: ghcr.io/${{ github.repository }}/oci_kuksa-val-services-ci:v0.1.0 - # credentials: - # username: ${{ github.repository_owner }} - # password: ${{ secrets.GITHUB_TOKEN }} steps: - name: Adding github workspace as safe directory diff --git a/.github/workflows/seat_service.yml b/.github/workflows/seat_service.yml index 9a08836..5838152 100644 --- a/.github/workflows/seat_service.yml +++ b/.github/workflows/seat_service.yml @@ -118,7 +118,7 @@ jobs: linux/amd64 linux/arm64 file: ./seat_service/Dockerfile - context: . + context: ./seat_service push: true tags: | ${{ steps.meta.outputs.tags }} @@ -134,7 +134,7 @@ jobs: linux/amd64 linux/arm64 file: ./seat_service/Dockerfile - context: . + context: ./seat_service push: true tags: "ttl.sh/eclipse-kuksa/kuksa-incubation/seat_service-${{github.sha}}" labels: ${{ steps.meta.outputs.labels }} diff --git a/hvac_service/README.md b/hvac_service/README.md index 9304180..4563495 100644 --- a/hvac_service/README.md +++ b/hvac_service/README.md @@ -49,4 +49,4 @@ INFO:hvac_service:datapoints are registered. ### Devcontainer -A dev-container exist, you still need to do `pip install`. +A dev-container exist, you still need to do `pip install` before starting hvac_service. diff --git a/seat_service/.devcontainer/devcontainer.json b/seat_service/.devcontainer/devcontainer.json index 072d84c..fdab652 100644 --- a/seat_service/.devcontainer/devcontainer.json +++ b/seat_service/.devcontainer/devcontainer.json @@ -18,9 +18,5 @@ "twxs.cmake" ] } - }, - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": { - } } } diff --git a/seat_service/Dockerfile b/seat_service/Dockerfile index 591c91a..c1bfd7a 100644 --- a/seat_service/Dockerfile +++ b/seat_service/Dockerfile @@ -18,7 +18,7 @@ ARG TARGETPLATFORM WORKDIR /workspace -COPY seat_service/bin_vservice-seat_*_release.* /workspace +COPY bin_vservice-seat_*_release.* /workspace # FIXME! Binaries are built from another base image, potentially incompatible with ubuntu:latest image # RUN tar -xf bin_vservice-seat_x86_64_release.tar.gz && tar -xf bin_vservice-seat_aarch64_release.tar.gz diff --git a/seat_service/README.md b/seat_service/README.md index aac6cc0..077c14d 100644 --- a/seat_service/README.md +++ b/seat_service/README.md @@ -53,16 +53,12 @@ For `aarch64` hosts or for quickly testing a pull request it is easier to use [G #### Prerequisites +Most existing build scripts rely on that you have Docker installed. +Some scripts also assumes that you use Ubuntu 20.04 as development environment, +by for example building binaries locally and then copying to a docker environment based on Ubuntu 20.04. + 1. Install and configure (if needed) local authentication proxy e.g. CNTLM or Px 1. Install and configure docker: [Get Docker](https://docs.docker.com/get-docker/) -1. Build base development docker. Go to the top-level of the repo - - ``` bash - cd .. - docker build -t oci_kuksa-val-services-ci:latest -f tools/Dockerfile . - # NOTE: If you need to cross compile for different arch: - DOCKER_BUILDKIT=1 docker buildx build --platform linux/arm64 -t oci_kuksa-val-services-ci:arm64 -f tools/Dockerfile --load . - ``` #### Usage on CLI @@ -70,7 +66,8 @@ For `aarch64` hosts or for quickly testing a pull request it is easier to use [G ##### Building on Ubuntu 20.04 -You can use dedicated build docker script [docker-build.sh](./docker-build.sh) if host environment matches target (Ubuntu 20.04): +You can use dedicated build docker script [docker-build.sh](./docker-build.sh) if host environment matches target (Ubuntu 20.04). +Note that you may need to install dependencies - use [.devcontainer/Dockerfile](.devcontainer/Dockerfile) as reference. ``` bash # Linux: [Ubuntu 20.04] @@ -88,39 +85,58 @@ TARGETS: x86_64|amd64, aarch64|amd64 Target arch to build for, if not set - defaults to multiarch ``` -#### Building in DevContainer +##### Creating Docker container for build If you are using different distro / version, you may use the devcontainer to compile seat service binaries. +First build the Docker container -From the checked-out git folder, to enter a shell execute: +``` bash +$ cd seat_service/.devcontainer +$ docker build -f Dockerfile -t seat_service_env:latest . +``` + +From the seat_service folder, use Docker like below where ``is the command you intend to run ``` bash +cd seat_service + # Linux: [x86_64, any version] -docker run --rm -it -v $(pwd):/workspace oci_kuksa-val-services-ci:latest +docker run --rm -it -v $(pwd):/workspace seat_service_env:latest # Windows (cmd) -docker run --rm -it -v %cd%:/workspace oci_kuksa-val-services-ci:latest +docker run --rm -it -v %cd%:/workspace seat_service_env:latest # Windows (Powershell) -docker run --rm -it -v ${PWD}:/workspace oci_kuksa-val-services-ci:latest +docker run --rm -it -v ${PWD}:/workspace seat_service_env:latest ``` ##### Build Seat Service binaries -Building the seat service via dev container must be triggered from the project root folder (seat service is referencing kuksa_data_broker/proto), e.g.: +Building the seat service via dev container must be triggered from the seat_service root folder, e.g.: ``` bash # Linux +cd seat_service + # Cleanup any build artifacts -rm -rf seat_service/bin_vservice-seat_*.tar.gz seat_service/target/ +rm -rf bin_vservice-seat_*.tar.gz target/ -# Generate seat_service/bin_vservice-seat_*.tar.gz files for packing seat service container +# Generate bin_vservice-seat_*.tar.gz files for packing seat service container docker run --rm -it -v $(pwd):/workspace oci_kuksa-val-services-ci:latest /bin/bash -c \ - "cd seat_service/; ./build-release.sh --pack" + "./build-release.sh --pack" # Check if release package is build -ls -la seat_service/bin_vservice-seat_*.tar.gz +ls -la bin_vservice-seat_*.tar.gz +``` + +It shall now be possible to start the service + +``` bash +$ docker run --rm -it -v $(pwd):/workspace xxx:latest target/x86_64/release/install/bin/seat_service +Usage: target/x86_64/release/install/bin/seat_service CAN_IF_NAME [LISTEN_ADDRESS [PORT]] + +Environment: SEAT_DEBUG=1 to enable SeatDataFeeder dumps ``` ##### Build Seat Service container @@ -129,17 +145,27 @@ Build the container using pre-built binaries: `seat_service/bin_vservice-seat_*. ``` bash # Linux -docker build -t seat_service -f seat_service/Dockerfile . +ce seat_service +docker build -t seat_service -f Dockerfile . ``` ### Usage in Visual Studio Code -It is also possible to open the repo as a remote container in VScode using the approach [Developing inside a Container](https://code.visualstudio.com/docs/remote/containers). +It is also possible to open the seat_service directory as a remote container in VScode using the approach +[Developing inside a Container](https://code.visualstudio.com/docs/remote/containers). All needed tools for VScode are automatically installed in this case 1. Install VScode extension with ID ```ms-vscode-remote.remote-containers``` 1. Hit `F1` and type `Remote-Containers: Reopen in Container` + +``` bash +root@aeefe5ca40f5:/workspaces/incubation3/seat_service# ./build-release.sh +root@aeefe5ca40f5:/workspaces/incubation3/seat_service# target/x86_64/release/install/bin/seat_service +Usage: target/x86_64/release/install/bin/seat_service CAN_IF_NAME [LISTEN_ADDRESS [PORT]] + +Environment: SEAT_DEBUG=1 to enable SeatDataFeeder dumps +``` ## Configuration ### Command line arguments