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

Feat(containers): init lab containers for tech library #14

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
108 changes: 108 additions & 0 deletions .github/workflows/container_build_child.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
# This workflow is triggered by the parent workflow and must not be triggered directly.

name: Reusable build container workflow

env:
# BUILDX_NO_DEFAULT_ATTESTATIONS must be set to build only arm64 and amd64 images.
# The devcontainers/[email protected] build will fail if this env variable is not set.
BUILDX_NO_DEFAULT_ATTESTATIONS: 1

on:
workflow_call:
inputs:
container_name:
required: false
type: string
default: techlib-labs
image_tags:
required: false
type: string
platform:
required: false
type: string
default: linux/arm64/v8,linux/amd64
from_image:
required: false
type: string
default: ghcr.io/aristanetworks/avd/universal
from_variant:
required: false
type: string
default: latest
username:
required: false
type: string
default: avd
user_id:
required: false
type: string
default: 1000
group_id:
required: false
type: string
default: 1000
git_init:
required: false
type: boolean
default: true
clab_version:
required: false
type: string
ceos_lab_version:
required: false
type: string
default: latest

jobs:
build_image:
runs-on: ubuntu-22.04
steps:
- name: Starting container build
run: echo "Starting container build. Be patient. 🐢"
- name: Checkout code ✅
uses: actions/checkout@v4

- name: Build image tags 🏷️
id: build-tags
run: |
if [ -z "${{ inputs.image_tags }}" ]; then
echo "No image tags provided. Building tags."
echo "image_tags=${{ inputs.from_variant }}-clab${{ inputs.clab_version }}-ceos${{ inputs.ceos_lab_version }}" >> $GITHUB_OUTPUT
else
echo "Using provided image tags."
echo "image_tags=${{ inputs.image_tags }}" >> $GITHUB_OUTPUT
fi

- name: Setup QEMU for multi-arch builds 🏗️
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ inputs.platform }}

- name: Setup Docker buildX for multi-arch builds 🏗️
uses: docker/setup-buildx-action@v3

- name: Login to the container registry 🗝️
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pre-build dev container image 🔨
uses: devcontainers/[email protected]
env:
FROM_IMAGE: ${{ inputs.from_image }}
FROM_VARIANT: ${{ inputs.from_variant }}
USERNAME: ${{ inputs.username }}
UID: ${{ inputs.user_id }}
GID: ${{ inputs.group_id }}
CLAB_VERSION: ${{ inputs.clab_version }}
CEOS_LAB_VERSION_ARG: ${{ inputs.ceos_lab_version }}
GIT_INIT_ARG: ${{ inputs.git_init }}
with:
subFolder: containers/${{ inputs.container_name }}
imageName: ghcr.io/${{ github.repository }}/${{ inputs.container_name }}
imageTag: ${{ steps.build-tags.outputs.image_tags }}
platform: ${{ inputs.platform }}
push: always
27 changes: 27 additions & 0 deletions .github/workflows/container_build_parent_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: build container for CVaaS and AVD Demo, EVPN MLAG

on:
push:
branches: [main]
paths:
- .github/workflows/container_build_child.yml
- .github/workflows/container_build_parent_matrix.yml
- containers/**
workflow_dispatch:
branches: [main]

jobs:
build-lab-containers:
uses: ./.github/workflows/container_build_child.yml
strategy:
matrix:
from_image: ["ghcr.io/aristanetworks/avd/universal"]
from_variant: ["python3.11-avd-v4.9.0"]
clab_version: ["0.54.2"]
ceos_lab_version: ["4.32.1F"]
with:
from_image: ${{ matrix.from_image }}
from_variant: ${{ matrix.from_variant }}
clab_version: ${{ matrix.clab_version }}
ceos_lab_version: ${{ matrix.ceos_lab_version }}
36 changes: 36 additions & 0 deletions containers/techlib-labs/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ARG FROM_IMAGE
ARG FROM_VARIANT

FROM ${FROM_IMAGE}:${FROM_VARIANT}

ARG USERNAME
ARG CLAB_VERSION
ARG CEOS_LAB_VERSION_ARG
ARG GIT_INIT_ARG

ENV CEOS_LAB_VERSION=${CEOS_LAB_VERSION_ARG}
ENV GIT_INIT=${GIT_INIT_ARG}

USER root

# install some basic tools inside the container
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
sshpass \
iputils-ping \
htop \
&& rm -rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
&& apt-get clean

# copy postCreate script
COPY ./postCreate.sh /bin/postCreate.sh
RUN chmod +x /bin/postCreate.sh

USER ${USERNAME}

# install the latest containerlab, yamllint, cook-and-cut and eos-downloader
RUN bash -c "$(curl -sL https://get.containerlab.dev)" -- -v ${CLAB_VERSION} \
&& pip3 install --user yamllint \
&& pip install --user "eos-downloader>=0.10.1" \
&& pip install --user passlib
36 changes: 36 additions & 0 deletions containers/techlib-labs/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"build": {
"dockerfile": "Dockerfile",
"args": {
"FROM_IMAGE": "${localEnv:FROM_IMAGE}",
"FROM_VARIANT": "${localEnv:FROM_VARIANT}",
"USERNAME": "${localEnv:USERNAME}",
"CLAB_VERSION": "${localEnv:CLAB_VERSION}",
"CEOS_LAB_VERSION_ARG": "${localEnv:CEOS_LAB_VERSION_ARG}",
"GIT_INIT_ARG": "${localEnv:GIT_INIT_ARG}"
}
},
"customizations": {
"vscode": {
"extensions": [
// git essentials
"piotrpalarz.vscode-gitignore-generator",
"mhutchie.git-graph",
"donjayamanne.githistory",
// spell checker
"streetsidesoftware.code-spell-checker",
// drawio and tldraw
// excalidraw is pre-installed in universal
"hediet.vscode-drawio",
"tldraw-org.tldraw-vscode",
// markdown
"yzhang.markdown-all-in-one",
"bierner.markdown-checkbox",
"DavidAnson.vscode-markdownlint",
// various tools
"tuxtina.json2yaml",
"mutantdino.resourcemonitor"
]
}
}
}
16 changes: 16 additions & 0 deletions containers/techlib-labs/.devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set +e

ardl get eos --image-type cEOS --version ${CEOS_LAB_VERSION} --import-docker

# init demo dir as Git repo if requested for this demo env
if ${GIT_INIT}; then
cd ${CONTAINERWSF}
git init
git config --global --add safe.directory ${PWD}
if [ -z "$(git config user.name)" ]; then git config user.name "Lab User"; fi
if [ -z "$(git config user.email)" ]; then git config user.email [email protected]; fi
git add .
git commit -m "git init"
fi
Loading