如何在 Arduino Due 上本地运行 CI 管道中的单元测试

问题描述 投票:0回答:0

我想在 Arduino Due 上使用本地运行程序运行我的 Bitbucket CI 管道的单元测试。我已经设法设置了在本地运行器上运行单元测试的 Bitbucket 管道。我用我自己的

Dockerfile

# Dockerfile

FROM infinitecoding/platformio-for-ci:latest

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install the PlatformIO Atmel SAM platform as well as other dependencies
RUN curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | tee /lib/udev/rules.d/99-platformio-udev.rules \
    && cd /app \
    && pio pkg install \
    && pio pkg install -g --tool "platformio/tool-bossac@~1.10700.0" \
    && pio pkg install -g --tool "platformio/tool-scons@~4.40400.0"

# Start the application
CMD ["bash"]

我用

docker build -t platformio-atmelsam-due .
构建它,然后将其上传到 docker hub。然后,我在
bitbucket-pipelines.yml

中使用它
# bitbucket-pipelines.yml

image: <my-namespace>/platformio-atmelsam-due

pipelines:
  default:
    - parallel:
      - step:
          name: 'Build and Test'
          runs-on:
            - self.hosted
            - linux
          script:
            - chmod a+x ./scripts/build.sh
            - ./scripts/build.sh
      - step:
...

其中

<my-namespace>
当然是换成我的docker hub账户名。在
./scripts/build.sh
文件中,我在
native
环境中运行测试,因此在本地运行器中运行。这一切都很好。 现在我想将它更改为在
due
环境中运行,因此通过 USB 连接到本地运行器的 Arduino Due。

当我使用

docker run -it --device=/dev/ttyACM3 platformio-atmelsam-due
在本地机器上手动运行我的 docker 镜像时,然后在 Arduino 上运行单元测试。但是,它需要
--device
选项,我无法在 Bitbucket 管道中传递它。

我已经尝试通过在管道中添加另一个步骤来构建 docker 镜像,如下所示:

image: <my-namespace>/platformio-atmelsam-due

pipelines:
  default:
    - step:
          name: 'Build Docker'
          runs-on:
            - self.hosted
            - linux
          script:
            - export DOCKER_BUILDKIT=0
            - docker run -t --device=/dev/ttyACM3 platformio-atmelsam-due
          services:
            - docker
    - parallel:
      - step:
          name: 'Build and Test'
          runs-on:
            - self.hosted
            - linux
          script:
            - chmod a+x ./scripts/build.sh
            - ./scripts/build.sh
      - step: ...

但是,这不起作用(它因

docker: Error response from daemon: authorization denied by plugin pipelines: --devices is not allowed.
而失败)。但即使成功了,这一步也会花费很长时间,并且会大大减慢我的 CI 过程。

所以我的问题是,有没有比在 CI 管道中构建 docker 镜像更好的方法?我能以某种方式将 tty 访问权限“烘焙”到 docker 镜像中吗?

docker continuous-integration bitbucket-pipelines platformio arduino-due
© www.soinside.com 2019 - 2024. All rights reserved.