Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codespaces p2 #26

Merged
merged 34 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bfd249b
testing
davidban77 Jul 8, 2024
b25a7f4
testing with make ci-build
davidban77 Jul 8, 2024
b67f902
testing debug
davidban77 Jul 8, 2024
9b36a5b
testing another way
davidban77 Jul 8, 2024
29f82ea
testing another way2
davidban77 Jul 8, 2024
8a017b5
testing wiht some progress
davidban77 Jul 8, 2024
9dd99c5
testing wiht some progress2
davidban77 Jul 8, 2024
d3804fc
testing wiht some progress3
davidban77 Jul 8, 2024
2d0fe04
testing wiht some progress4
davidban77 Jul 8, 2024
2edda65
testing wiht some progress5
davidban77 Jul 8, 2024
1ff5c4d
testing wiht some progress6
davidban77 Jul 8, 2024
b6241c5
testing wiht some progress7
davidban77 Jul 8, 2024
1631675
testing wiht some progress7
davidban77 Jul 8, 2024
0ee1e89
testing wiht some progress8
davidban77 Jul 8, 2024
13bfb12
testing wiht some progress9
davidban77 Jul 8, 2024
89d3b24
testing wiht some progress10
davidban77 Jul 8, 2024
078ea41
testing wiht some progress11
davidban77 Jul 8, 2024
27d25c8
testing aver
davidban77 Jul 8, 2024
3d26c09
testing aver2
davidban77 Jul 8, 2024
6819942
testing aver3
davidban77 Jul 8, 2024
971f48d
testing aver4
davidban77 Jul 8, 2024
0ae6d57
testing aver5
davidban77 Jul 8, 2024
197e84c
chore: Update Dockerfile and devcontainer-build.yml
davidban77 Jul 9, 2024
a649ba9
testing aver6
davidban77 Jul 9, 2024
cb2c613
testing aver7
davidban77 Jul 9, 2024
54a105a
testing aver8
davidban77 Jul 9, 2024
b871e01
testing aver9
davidban77 Jul 9, 2024
97f8325
testing aver10
davidban77 Jul 9, 2024
bb02187
testing aver11
davidban77 Jul 9, 2024
44b325c
testing aver12
davidban77 Jul 9, 2024
b035ab2
testing
davidban77 Jul 11, 2024
40092a4
testing2
davidban77 Jul 11, 2024
fc4461e
refactoring tests
davidban77 Jul 12, 2024
def5ac1
redirecting button
davidban77 Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .devcontainer.json/Dockerfile

This file was deleted.

30 changes: 0 additions & 30 deletions .devcontainer.json/devcontainer.json

This file was deleted.

42 changes: 42 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM mcr.microsoft.com/devcontainers/python:3.11-bookworm

RUN echo "deb [trusted=yes] https://netdevops.fury.site/apt/ /" | \
tee -a /etc/apt/sources.list.d/netdevops.list

# install containerlab and tools
RUN apt update && \
apt install -y --no-install-recommends containerlab \
btop \
gh \
iputils-ping \
tcpdump \
iproute2 \
qemu-kvm \
dnsutils \
telnet

# Install gNMIc
RUN bash -c "$(curl -sL https://get-gnmic.openconfig.net)"

# Add empty docker config files to avoid clab warnings for root user
RUN mkdir -p /root/.docker && echo "{}" > /root/.docker/config.json

# Maintain SSH_AUTH_SOCK env var when using sudo
RUN mkdir -p /etc/sudoers.d && echo 'Defaults env_keep += "SSH_AUTH_SOCK"' > /etc/sudoers.d/ssh_auth_sock

# vscode user is created in the MS devcontainer image
USER vscode

ENV PATH="$PATH:/home/vscode/.local/bin"

# Create ssh key for vscode user to enable passwordless ssh to devices
RUN ssh-keygen -t ecdsa -b 256 -N "" -f ~/.ssh/id_ecdsa && \
mkdir -p /home/vscode/.docker && \
echo "{}" > /home/vscode/.docker/config.json

COPY --chown=vscode:vscode --chmod=700 . /netobs

RUN pip install --upgrade pip && \
cd /netobs && \
pip install . && \
rm -r /netobs/*
9 changes: 9 additions & 0 deletions .devcontainer/batteries-included/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"image": "ghcr.io/network-observability/netobs-devcontainer:dev",
"hostRequirements": {
"cpus": 4,
"memory": "8gb",
"storage": "32gb"
},
"postStartCommand": "netobs lab prepare --scenario batteries-included"
}
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"build": {
"dockerfile": "./Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"dockerDashComposeVersion": "none"
},
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},
"postCreateCommand": "cp example.env .env && netobs docker build"
}
21 changes: 15 additions & 6 deletions .github/workflows/devcontainer-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,39 @@ name: Build and Push Dev Container
on:
push:
branches:
- main
- df/gh-actions

jobs:
netobs-devcontainer:
# permissions: write-all
runs-on: ubuntu-22.04

steps:
- name: Checkout code
uses: actions/checkout@v4

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
- name: local test
run: |
echo "Hello, World!"
ls -al
echo $PWD
ls -al /home/runner/work/network-observability-lab/network-observability-lab/.devcontainer/devcontainer.json

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log into registry ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push devcontainer image
uses: devcontainers/[email protected]
with:
imageName: ghcr.io/network-observability-lab/netobs-devcontainer
# cacheFrom: ghcr.io/network-observability-lab/netobs-devcontainer
imageName: ghcr.io/network-observability/netobs-devcontainer
imageTag: latest
# cacheFrom: ghcr.io/network-observability/netobs-devcontainer
# tags: yourusername/yourrepository:tag # Replace with your Docker image tag
push: always
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,7 @@ terraform.tfstate
terraform.tfstate.backup
local

*keep_api_key
*keep_api_key

# Dev Containers
.devcontainer/dev
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/network-observability/network-observability-lab?quickstart=1&devcontainer_path=.devcontainer%2Fbatteries-included%2Fdevcontainer.json)
# Network Observability Lab

This repository contains the resources for building and managing an observability stack within a network lab environment, specifically designed for the "Modern Network Observability" book. It includes scripts, configuration files, and documentation to set up and operate various observability tools like Prometheus, Grafana Loki, and others, helping you implement and learn about network observability practices in a practical, hands-on manner.
Expand Down
11 changes: 3 additions & 8 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# NetObs utility
########################################
LAB_SCENARIO=batteries-included
LAB_SUDO=false
# Replace CEOS_IMAGE with your own ceos image version
CEOS_IMAGE=ceos:4.31.2F

########################################
# Terraform
########################################
TF_VAR_digitalocean_token="your_token"
LAB_SUDO=true
# Replace if needed CEOS_IMAGE with your own ceos image version
# CEOS_IMAGE=ceos:4.31.2F

########################################
# Network Agent (Telegraf)
Expand Down
26 changes: 26 additions & 0 deletions netobs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,32 @@ def containerlab_inspect(
# --------------------------------------#


@docker_app.command(rich_help_panel="Docker Stack Management", name="build")
def docker_build(
scenario: Annotated[NetObsScenarios, typer.Option(help="Scenario to execute command", envvar="LAB_SCENARIO")],
services: Annotated[list[str], typer.Option(help="Service(s) to build")] = [],
verbose: Annotated[bool, typer.Option(help="Verbose mode")] = False,
):
"""Build necessary containers.

[u]Example:[/u]

To build all services:
[i]netobs docker build --scenario batteries-included[/i]

To build a specific service:
[i]netobs docker build telegraf-01 --scenario batteries-included[/i]
"""
console.log(f"Building service(s): [orange1 i]{services}", style="info")
run_docker_compose_cmd(
action="build",
filename=Path(f"./chapters/{scenario.value}/docker-compose.yml"),
services=services if services else [],
verbose=verbose,
task_name="build stack",
)


@docker_app.command(rich_help_panel="Docker Stack Management", name="exec")
def docker_exec(
service: Annotated[str, typer.Argument(help="Service to execute command")],
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "netobs"
version = "0.0.12"
version = "0.0.13"
description = "Utilities and Management Tools for Network Observability Book"
requires-python = ">=3.9"
license = {text = "MIT"}
Expand Down Expand Up @@ -38,7 +38,7 @@ readme = {file = ["README.md"]}

[tool.black]
line-length = 120
target-version = ['py39', 'py310']
target-version = ['py39', 'py310', 'py311']
include = '\.pyi?$'
exclude = '''
(
Expand Down