From b46723788c3b7f9661fd76c0824e0934abd78bda Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Sun, 3 Oct 2021 21:13:34 +0200 Subject: [PATCH] added container and apk package build --- .github/workflows/cicd.yml | 3 ++- .goreleaser.yml | 19 +++++++++++----- docs/install.md | 45 +++++++++++++++++++++++++++++++++----- goreleaser.dockerfile | 17 ++++++++++++++ 4 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 goreleaser.dockerfile diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 7411fd100..613276fd7 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -13,6 +13,7 @@ env: GOVER: 1.16.5 CGO_ENABLED: 0 MKDOCS_MATERIAL_VER: 7.2.2 + GORELEASER_VER: v0.180.3 jobs: file-changes: @@ -227,7 +228,7 @@ jobs: - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 with: - version: v0.155.0 + version: ${{ env.GORELEASER_VER }} args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index cabcb9be2..c785d67c0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -4,7 +4,8 @@ project_name: containerlab builds: - - env: + - id: clab-bin + env: - CGO_ENABLED=0 ldflags: - -s -w -X github.com/srl-labs/containerlab/cmd.version={{.Version}} -X github.com/srl-labs/containerlab/cmd.commit={{.ShortCommit}} -X github.com/srl-labs/containerlab/cmd.date={{.Date}} @@ -14,6 +15,15 @@ builds: - amd64 hooks: post: upx "{{ .Path }}" +dockers: + - goos: linux + goarch: amd64 + image_templates: + # if version starts with v0.0.0 this is a beta build, for which we don't apply the `latest` tag and apply `beta` tag instead + - '{{ $pfx := slice .Version 0 6}}{{- if eq $pfx "v0.0.0"}}ghcr.io/srl-labs/clab:beta{{else}}ghcr.io/srl-labs/clab:latest{{- end }}' + - 'ghcr.io/srl-labs/clab:{{ replace .Version "v" ""}}' + dockerfile: goreleaser.dockerfile + skip_push: false archives: - replacements: linux: Linux @@ -26,7 +36,7 @@ snapshot: publishers: - name: fury.io deb/rpm packages ids: - - containerlab # this id belongs to nfpm section and is used to only upload artifacts from nfpm + - containerlab-nfpms # this id belongs to nfpm section and is used to only upload artifacts from nfpm dir: "{{ dir .ArtifactPath }}" cmd: curl -F package=@{{ .ArtifactName }} https://{{ .Env.FURY_TOKEN }}@push.fury.io/netdevops/ release: @@ -39,7 +49,7 @@ changelog: - "^test:" nfpms: - - id: containerlab + - id: containerlab-nfpms file_name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" package_name: containerlab maintainer: Wim Henderickx , Karim Radhouani , Roman Dodin @@ -51,12 +61,11 @@ nfpms: formats: - rpm - deb + - apk bindir: /usr/bin contents: - src: ./lab-examples dst: /etc/containerlab/lab-examples - # - src: ./tools - # dst: /etc/containerlab/tools - src: ./templates dst: /etc/containerlab/templates - src: /usr/bin/containerlab diff --git a/docs/install.md b/docs/install.md index 88fa266d1..1b95ffcec 100644 --- a/docs/install.md +++ b/docs/install.md @@ -42,6 +42,8 @@ It is possible to install official containerlab releases via public APT/YUM repo yum install containerlab ``` +=== "APK" + Download `.apk` package from [Github releases](https://github.com/srl-labs/containerlab/releases). ??? "Manual package installation" Alternatively, users can manually download the deb/rpm package from the [Github releases](https://github.com/srl-labs/containerlab/releases) page. @@ -61,6 +63,42 @@ It is possible to install official containerlab releases via public APT/YUM repo The package installer will put the `containerlab` binary in the `/usr/bin` directory as well as create the `/usr/bin/clab -> /usr/bin/containerlab` symlink. The symlink allows the users to save on typing when they use containerlab: `clab `. +### Container +Containerlab is also available in a container packaging. The latest containerlab release can be pulled with: + +``` +docker pull ghcr.io/srl-labs/clab +``` + +To pick any of the released versions starting from release 0.19.0, use the version number as a tag, for example: `docker pull ghcr.io/srl-labs/clab:0.19.0` + +Since containerlab itself deploys containers and creates veth pairs, its run instructions are a bit more complex, but still it is a copy-paste-able command. + +For example, if your lab files are contained within the current working directory - `$(pwd)` - then you can launch containerlab container as follows: + +```bash +docker run --rm -it --privileged \ + --network host \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /var/run/netns:/var/run/netns \ + -v /etc/hosts:/etc/hosts \ + --pid="host" \ + -v $(pwd):$(pwd) \ + -w $(pwd) \ + ghcr.io/srl-labs/clab bash +``` + +Within the started container you can use the same `containerlab deploy/destroy/inspect` commands to manage your labs. + +!!!note + Containerlab' container command is itself `containerlab`, so you can deploy a lab without invoking a shell, for example: + ```bash + docker run --rm -it --privileged \ + # + -w $(pwd) \ + ghcr.io/srl-labs/clab deploy -t somelab.clab.yml + ``` + ### Manual installation If the linux distributive can't install deb/rpm packages, containerlab can be installed from the archive: @@ -102,8 +140,6 @@ Once installed, issue `sudo service docker start` to start the docker service in ### Mac OS Running containerlab on Mac OS is possible[^4] by means of a separate docker image with containerlab inside. -The container image `ghcr.io/srl-labs/clab:latest`[^5] contains the 0.16.2 version of containerlab at the time of this writing. - To use this container use the following command: ```shell linenums="1" @@ -122,7 +158,7 @@ docker run --rm -it --privileged \ The first command in the snippet above sets the working directory which you intend to use on your Mac OS. The `~/clab` in the example above expands to `/Users//clab` and means that we intent to have our containerlab labs to be stored in this directory. !!!note - 1. It is best to create a directory under the `~/some/path` unless you know what to do[^6] + 1. It is best to create a directory under the `~/some/path` unless you know what to do[^5] 2. vrnetlab based nodes will not be able to start, since Docker VM does not support virtualization. When the container is started, you will have a bash shell opened with the directory contents mounted from the Mac OS. There you can use `containerlab` commands right away. @@ -228,5 +264,4 @@ To build containerlab from source: [^2]: Most containerized NOS will require >1 vCPU. RAM size depends on the lab size. Architecture: AMD64. [^3]: No need to uninstall Docker Desktop, just make sure that it is not integrated with WSL2 machine that you intend to use with containerlab. Moreover, you can make it even work with Docker Desktop with a [few additional steps](https://twitter.com/networkop1/status/1380976461641834500/photo/1), but installing docker-ce into the WSL maybe more intuitive. [^4]: kudos to Michael Kashin who [shared](https://github.com/srl-labs/containerlab/issues/577#issuecomment-895847387) this approach with us -[^5]: later we will incorporate the container image build into our release tool chain, so that you could always get the latest containerlab inside that image. For now, if the upgraded version is needed, just do `clab version upgrade` inside the container. -[^6]: otherwise make sure to add a custom shared directory to the docker on mac. \ No newline at end of file +[^5]: otherwise make sure to add a custom shared directory to the docker on mac. \ No newline at end of file diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile new file mode 100644 index 000000000..98c610491 --- /dev/null +++ b/goreleaser.dockerfile @@ -0,0 +1,17 @@ +FROM alpine:3 + +LABEL maintainer="Roman Dodin " +LABEL documentation="https://containerlab.srlinux.dev" +LABEL repo="https://github.com/srl-labs/containerlab" + +RUN apk add --no-cache bash \ + curl \ + docker-cli \ + git \ + openssh \ + make + +COPY containerlab_*.apk /tmp/ +RUN apk add --allow-untrusted /tmp/containerlab_*.apk && rm -f /tmp/containerlab_*.apk + +CMD ["/usr/bin/containerlab", "help"]