nokia / srlinux-container-image

Freely distributed official SR Linux container image
https://learn.srlinux.dev
BSD 3-Clause "New" or "Revised" License
52 stars 8 forks source link

Run SR Linux as a service for GitHub actions #5

Closed vincentbernat closed 7 months ago

vincentbernat commented 7 months ago

Hey!

I am trying to use SR Linux as part of GitHub actions:

jobs:
  build-linux:
    services:
      srlinux:
        image: ghcr.io/nokia/srlinux:23.7.1
        ports:
          - 57400:57400
          - 57401:22
        options: "--privileged --user=root"

Unfortunately, there is no way to specify a command and the default one for the image is /bin/bash. We can specify the entrypoint, but it needs to be a command without arguments. If I pass just --entrypoint=/opt/srlinux/bin/sr_linux I don't get the network configuration. The command executed by GitHub is:

  /usr/bin/docker create --name 2cfdc039b1784ff78dcfc822f32393b0_ghcrionokiasrlinux2371_816cd6 --label 17eddf --network github_network_c5149df44a6341378dfd86e57bea7c25 --network-alias srlinux -p 57400:57400 -p 57401:22 --privileged --user=root --entrypoint=/opt/srlinux/bin/sr_linux -e GITHUB_ACTIONS=true -e CI=true ghcr.io/nokia/srlinux:23.7.1

Maybe the entrypoint could execute /opt/srlinux/bin/sr_linux when it detects GITHUB_ACTIONS=true?

hellt commented 7 months ago

Hi Vincent This comes to me as a limitation of this action. Fine tuning the entropion per each CI service is not a practical approach.

A few options to consider that easily solve this: 1 Use containerlab 2 build an image with a custom entry point per you need

vincentbernat commented 7 months ago

GitHub requires images to be publicly available to be used as a service, this makes it difficult to build an image with a custom entry point (I would have to push it to a registry, making it difficult to run from pull requests that are not mine). There is an open discussion about customizing the command, but it seems to be stuck as most images have a default command that run the service.

What about a second tag with "-ci" appended to it that would override the command? BTW, you could also add an healthcheck:

FROM ghcr.io/nokia/srlinux:23.7.1
CMD /opt/srlinux/bin/sr_linux
HEALTHCHECK --interval=5s CMD test -f /etc/opt/srlinux/devices/app_ephemeral.mgmt_server.ready_for_config

As for using containerlab, it seems to be an nth rabbit hole to dig just to be able to test a gNMI implementation.

hellt commented 7 months ago

You can build an image with a custom entry point and push it to your gh registry as a public image.

Or leverage containerlab. It very well may be that you're spending 10x more time trying to deal with gh actions way than running containerlab.

Health check is a universally good idea 👍