Skip to content

Commit

Permalink
added container and apk package build
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Oct 3, 2021
1 parent 374b690 commit b467237
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand Down
19 changes: 14 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 <wim.henderickx@nokia.com>, Karim Radhouani <medkarimrdi@gmail.com>, Roman Dodin <dodin.roman@gmail.com>
Expand All @@ -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
Expand Down
45 changes: 40 additions & 5 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 <command>`.

### 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 \
# <run options omitted>
-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:

Expand Down Expand Up @@ -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"
Expand All @@ -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/<username>/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.
Expand Down Expand Up @@ -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.
[^5]: otherwise make sure to add a custom shared directory to the docker on mac.
17 changes: 17 additions & 0 deletions goreleaser.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:3

LABEL maintainer="Roman Dodin <dodin.roman@gmail.com>"
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"]

0 comments on commit b467237

Please sign in to comment.