From 07fde44155699765ecf38e38c9c4b231c4f62438 Mon Sep 17 00:00:00 2001 From: pa Date: Tue, 23 Jul 2024 11:05:37 +0200 Subject: [PATCH] init lab containers for tech library --- .github/workflows/container_build_child.yml | 108 ++++++++++++++++++ .../container_build_parent_matrix.yml | 27 +++++ .../techlib-labs/.devcontainer/Dockerfile | 36 ++++++ .../.devcontainer/devcontainer.json | 36 ++++++ .../techlib-labs/.devcontainer/postCreate.sh | 16 +++ 5 files changed, 223 insertions(+) create mode 100644 .github/workflows/container_build_child.yml create mode 100644 .github/workflows/container_build_parent_matrix.yml create mode 100644 containers/techlib-labs/.devcontainer/Dockerfile create mode 100644 containers/techlib-labs/.devcontainer/devcontainer.json create mode 100644 containers/techlib-labs/.devcontainer/postCreate.sh diff --git a/.github/workflows/container_build_child.yml b/.github/workflows/container_build_child.yml new file mode 100644 index 0000000..cb92287 --- /dev/null +++ b/.github/workflows/container_build_child.yml @@ -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/ci@v0.3 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/ci@v0.3 + 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 diff --git a/.github/workflows/container_build_parent_matrix.yml b/.github/workflows/container_build_parent_matrix.yml new file mode 100644 index 0000000..82b21e3 --- /dev/null +++ b/.github/workflows/container_build_parent_matrix.yml @@ -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 }} diff --git a/containers/techlib-labs/.devcontainer/Dockerfile b/containers/techlib-labs/.devcontainer/Dockerfile new file mode 100644 index 0000000..f2abb9d --- /dev/null +++ b/containers/techlib-labs/.devcontainer/Dockerfile @@ -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 diff --git a/containers/techlib-labs/.devcontainer/devcontainer.json b/containers/techlib-labs/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b3819b2 --- /dev/null +++ b/containers/techlib-labs/.devcontainer/devcontainer.json @@ -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" + ] + } + } +} \ No newline at end of file diff --git a/containers/techlib-labs/.devcontainer/postCreate.sh b/containers/techlib-labs/.devcontainer/postCreate.sh new file mode 100644 index 0000000..4951e25 --- /dev/null +++ b/containers/techlib-labs/.devcontainer/postCreate.sh @@ -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 user@one-click.lab; fi + git add . + git commit -m "git init" +fi \ No newline at end of file