Skip to content

Commit e952a3c

Browse files
authored
lab-base 2.0 (#89)
* add unified entrypoint * add settings for containerlab * update build workflow * fixes and image with uid 1009 * add then * fix dockerfile * add aliases back * remove codespaces check for entrypoint cli * add defaults to entrypoint * fix gids
1 parent 65f19c1 commit e952a3c

File tree

10 files changed

+221
-71
lines changed

10 files changed

+221
-71
lines changed

.cp/copier.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ceos_lab_version:
103103
type: str
104104
help: Please select the cEOS-lab version.
105105
when: "{{ 'lab' | _in(templates) }}"
106-
choices: ["4.32.3M"]
106+
choices: ["4.34.2F"]
107107

108108
clab_version:
109109
type: str

.devcontainer/cvaas-cvaas-and-avd-demo--evpn-mlag/devcontainer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
"image": "ghcr.io/${localEnv:GITHUB_REPOSITORY}/lab-base:python3.11-avd-v5.1.0-clab0.65.1-rev1.3",
2+
"image": "ghcr.io/${localEnv:GITHUB_REPOSITORY}/lab-base:python3.11-avd-v5.5.1-clab0.69.3-rev2.0",
33
// containerEnv set the variables applied to entire container
44
"containerEnv": {
55
"ARISTA_TOKEN": "${localEnv:ARTOKEN}",
6-
"CEOS_LAB_VERSION": "4.32.3M",
6+
"CEOS_LAB_VERSION": "4.34.2F",
77
"CV_API_TOKEN": "${localEnv:CV_API_TOKEN}",
88
"CONTAINERWSF": "${containerWorkspaceFolder}",
9-
"GITHUB_REPOSITORY": "${localEnv:GITHUB_REPOSITORY}"
9+
"GITHUB_REPOSITORY": "${localEnv:GITHUB_REPOSITORY}",
10+
"PASSWORD": "${localEnv:CODER_PASSWORD}"
1011
},
1112
"secrets": {
1213
"CV_API_TOKEN": {
@@ -28,7 +29,7 @@
2829
"storage": "64gb"
2930
},
3031
"onCreateCommand": "chmod +x /cvaas-cvaas-and-avd-demo--evpn-mlag/addAliases.sh; /cvaas-cvaas-and-avd-demo--evpn-mlag/addAliases.sh",
31-
"postCreateCommand": "postCreate.sh; make start",
32+
"postCreateCommand": "/bin/entrypoint",
3233
"workspaceMount": "source=${localWorkspaceFolder}/labs/${containerWorkspaceFolder},target=/${containerWorkspaceFolder},type=bind",
3334
"workspaceFolder": "/cvaas-cvaas-and-avd-demo--evpn-mlag",
3435
"containerUser": "avd"

.github/workflows/container_build_child.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ jobs:
6868
run: |
6969
if [ -z "${{ inputs.image_tags }}" ]; then
7070
echo "No image tags provided. Building tags."
71-
echo "image_tags=${{ inputs.from_variant }}-clab${{ inputs.clab_version }}-rev${{ inputs.container_revision }}" >> $GITHUB_OUTPUT
71+
if [ "${{ inputs.user_id }}" != "1000" ]; then
72+
echo "image_tags=${{ inputs.from_variant }}-clab${{ inputs.clab_version }}-rev${{ inputs.container_revision }}-uid${{ inputs.user_id }}" >> $GITHUB_OUTPUT
73+
else
74+
echo "image_tags=${{ inputs.from_variant }}-clab${{ inputs.clab_version }}-rev${{ inputs.container_revision }}" >> $GITHUB_OUTPUT
75+
fi
7276
else
7377
echo "Using provided image tags."
7478
echo "image_tags=${{ inputs.image_tags }}" >> $GITHUB_OUTPUT
@@ -111,7 +115,7 @@ jobs:
111115
- name: Pre-build dev container image 🔨
112116
uses: devcontainers/ci@v0.3
113117
# Only build and push the image if at least one of the image tags does not exist.
114-
if: steps.check-image.outputs.exit_code != 0
118+
# if: steps.check-image.outputs.exit_code != 0
115119
env:
116120
FROM_IMAGE: ${{ inputs.from_image }}
117121
FROM_VARIANT: ${{ inputs.from_variant }}

.github/workflows/container_build_parent_matrix.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ jobs:
2525
from_image: ["ghcr.io/aristanetworks/avd/universal"]
2626
from_variant: ["python3.11-avd-v5.5.1"]
2727
clab_version: ["0.69.3"]
28+
user_id: ["1000", "1009"]
29+
include:
30+
- user_id: "1000"
31+
group_id: "1000"
32+
- user_id: "1009"
33+
group_id: "1009"
2834
with:
2935
from_image: ${{ matrix.from_image }}
3036
from_variant: ${{ matrix.from_variant }}
3137
clab_version: ${{ matrix.clab_version }}
38+
user_id: ${{ matrix.user_id }}
39+
group_id: ${{ matrix.group_id }}
3240
# the rev number will be updated with each run
3341
# 1.1 - initial version
3442
# 1.2:
@@ -49,4 +57,9 @@ jobs:
4957
# - Add ContainerLab 0.68.0
5058
# 1.7:
5159
# - Add ContainerLab 0.69.3
52-
container_revision: "1.7"
60+
# 2.0:
61+
# - Add ARM support
62+
# - Add code-server install for VSCode Web UI without supporting tools
63+
# - Switch to unified entrypoint
64+
# - Add image with UID 1009 for arista.labs
65+
container_revision: "2.0"

containers/lab-base/.devcontainer/Dockerfile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ ARG USERNAME
77
ARG CLAB_VERSION
88
ARG CEOS_LAB_VERSION_ARG
99
ARG GIT_INIT_ARG
10+
ARG UID
11+
ARG GID
1012

1113
ENV CEOS_LAB_VERSION=${CEOS_LAB_VERSION_ARG}
1214
ENV GIT_INIT=${GIT_INIT_ARG}
1315

1416
USER root
1517

18+
ENV OLD_GID="1000"
19+
RUN sed -i -e "s/\(${USERNAME}:[^:]*:\)[^:]*:[^:]*/\1${UID}:${GID}/" /etc/passwd; \
20+
sed -i -e "s/\([^:]*:[^:]*:\)${GID}:/\1${GID}:/" /etc/group; \
21+
chown -R $UID:$GID /home/$USERNAME
22+
1623
# install some basic tools inside the container
1724
RUN apt-get update \
1825
&& apt-get install -y --no-install-recommends \
@@ -23,11 +30,10 @@ RUN apt-get update \
2330
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
2431
&& apt-get clean
2532

26-
# copy postCreate script
27-
COPY ./postCreate.sh /bin/postCreate.sh
28-
RUN chmod +x /bin/postCreate.sh
29-
# copy terminals script
30-
COPY ./terminals.sh /bin/terminals.sh
33+
# copy code-server entrypoint
34+
COPY ./entrypoint.sh /bin/entrypoint
35+
RUN chmod +x /bin/entrypoint
36+
ENTRYPOINT [ "/bin/entrypoint" ]
3137

3238
USER ${USERNAME}
3339

@@ -36,3 +42,15 @@ RUN bash -c "$(curl -sL https://get.containerlab.dev)" -- -v ${CLAB_VERSION} \
3642
&& pip3 install --user yamllint \
3743
&& pip install --user "eos-downloader>=0.10.1" \
3844
&& pip install --user passlib
45+
46+
# install coder and extensions
47+
RUN curl -fsSL https://code-server.dev/install.sh | sh -s -- --version="4.103.1" \
48+
&& code-server --install-extension srl-labs.vscode-containerlab --force \
49+
&& code-server --install-extension tuxtina.json2yaml --force
50+
51+
USER root
52+
# add global workspace settings for code-server
53+
COPY ./settings.json /home/${USERNAME}/.local/share/code-server/User
54+
RUN chown ${USERNAME} /home/${USERNAME}/.local/share/code-server/User/settings.json
55+
56+
USER ${USERNAME}

containers/lab-base/.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"USERNAME": "${localEnv:USERNAME}",
88
"CLAB_VERSION": "${localEnv:CLAB_VERSION}",
99
"CEOS_LAB_VERSION_ARG": "${localEnv:CEOS_LAB_VERSION_ARG}",
10-
"GIT_INIT_ARG": "${localEnv:GIT_INIT_ARG}"
10+
"GIT_INIT_ARG": "${localEnv:GIT_INIT_ARG}",
11+
"UID": "${localEnv:UID}",
12+
"GID": "${localEnv:GID}"
1113
}
1214
},
1315
"customizations": {
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env bash
2+
3+
set +e
4+
5+
# use VSCode script to start Docker
6+
/usr/local/share/docker-init.sh
7+
8+
# for D-in-D case container engine will be always Docker
9+
# however we do not want to hardcode it for future cases
10+
if [ "$(command -v podman)" ]; then
11+
CONTAINER_ENGINE="podman"
12+
elif [ "$(command -v docker)" ]; then
13+
CONTAINER_ENGINE="docker"
14+
else
15+
echo "ERROR: Failed to find container engine. Please install docker or podman." >&2
16+
exit 1
17+
fi
18+
19+
# always prune old containers to clean the lab on laptops
20+
${CONTAINER_ENGINE} container prune -f
21+
22+
if [ -z "${CEOS_IMAGE_FULLPATH}" ]; then
23+
CEOS_IMAGE_FULLPATH="${CONTAINERWSF}/cEOS*tar.xz"
24+
fi
25+
if [ -z "${CEOS_MD5_FULLPATH}" ]; then
26+
CEOS_MD5_FULLPATH="${CONTAINERWSF}/cEOS*tar.xz.sha512sum"
27+
fi
28+
# check if ceos-lab image already present
29+
if [ -z "$(${CONTAINER_ENGINE} image ls | grep 'arista/ceos')" ]; then
30+
if [ "${ARISTA_TOKEN}" ]; then
31+
# `uname -m` is used to find platform architecture
32+
# currently we check for arm64 and aarch64 and expect everything else to be an x86 machine
33+
echo "$(uname -m)"
34+
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
35+
ardl get eos --format cEOSarm --version ${CEOS_LAB_VERSION} --import-docker
36+
${CONTAINER_ENGINE} tag arista/ceos:${CEOS_LAB_VERSION} arista/ceos:latest
37+
else
38+
ardl get eos --format cEOS --version ${CEOS_LAB_VERSION} --import-docker
39+
${CONTAINER_ENGINE} tag arista/ceos:${CEOS_LAB_VERSION} arista/ceos:latest
40+
fi
41+
# confirm that cEOS image was deleted just in case ardl failed to do that
42+
rm -rf ${CEOS_IMAGE_FULLPATH} >/dev/null 2>&1
43+
rm -rf ${CEOS_MD5_FULLPATH} >/dev/null 2>&1
44+
else
45+
# if ARISTA_TOKEN is not defined - we'll try find image in the workspace cEOS*.tar.xz
46+
if [ -e ${CEOS_IMAGE_FULLPATH} ]; then
47+
${CONTAINER_ENGINE} import ${CEOS_IMAGE_FULLPATH} arista/ceos:latest
48+
rm ${CEOS_IMAGE_FULLPATH}
49+
# also delete SHA if it was copied, currently we do not check if archive was broken
50+
rm -rf ${CEOS_MD5_FULLPATH} >/dev/null 2>&1
51+
echo "WARNING: cEOS-lab image was successfully imported from the workspace."
52+
else
53+
echo "WARNING: arista.com token was not defined and cEOS-lab image is not present in container workspace!"
54+
fi 2>/dev/null
55+
fi
56+
else
57+
echo "WARNING: cEOS-lab image already present. Skipping the image pull/download."
58+
fi
59+
60+
# add aliases if any were defined
61+
if [ -f "${CONTAINERWSF}/addAliases.sh" ]; then
62+
chmod +x ${CONTAINERWSF}/addAliases.sh
63+
${CONTAINERWSF}/addAliases.sh
64+
fi
65+
66+
# when running on Codespaces, replace any Github variables in lab files
67+
if ${CODESPACES}; then
68+
# replace all markdown vars in demo directory
69+
if [ "${GITHUB_REPOSITORY}" ]; then
70+
grep -rl '{{gh.repo_name}}' . --exclude-dir .git | xargs sed -i 's/{{gh.repo_name}}/'"${GITHUB_REPOSITORY##*/}"'/g'
71+
grep -rl '{{gh.org_name}}' . --exclude-dir .git | xargs sed -i 's/{{gh.org_name}}/'"${GITHUB_REPOSITORY%%/*}"'/g'
72+
grep -rl '{{gh.repository}}' . --exclude-dir .git | xargs sed -i 's@{{gh.repository}}@'"${GITHUB_REPOSITORY}"'@g'
73+
else
74+
# if not running on Codespaces and GITHUB_REPOSITORY is not set - set aristanetworks/acLabs by default
75+
grep -rl '{{gh.repo_name}}' . --exclude-dir .git | xargs sed -i 's/{{gh.repo_name}}/'"acLabs"'/g'
76+
grep -rl '{{gh.org_name}}' . --exclude-dir .git | xargs sed -i 's/{{gh.org_name}}/'"aristanetworks"'/g'
77+
grep -rl '{{gh.repository}}' . --exclude-dir .git | xargs sed -i 's@{{gh.repository}}@'"aristanetworks/acLabs"'@g'
78+
fi
79+
fi
80+
81+
# update URL in clab init configs if set
82+
if [ "${CVURL}" ]; then
83+
grep -rl '{{cv_url}}' . --exclude-dir .git | xargs sed -i 's@{{cv_url}}@'"${CVURL}"'@g'
84+
# check for legacy labs using hardcoded URL
85+
grep -rl 'cv-staging.corp.arista.io' . --exclude-dir .git | xargs sed -i 's@cv-staging.corp.arista.io@'"${CVURL}"'@g'
86+
else
87+
# set defaul url to staging if nothing is defined
88+
grep -rl '{{cv_url}}' . --exclude-dir .git | xargs sed -i 's@{{cv_url}}@'"cv-staging.corp.arista.io"'@g'
89+
fi
90+
91+
if [ "${CV_API_TOKEN}" ]; then
92+
if [ "${CVURL}" ]; then
93+
CVTOKEN=$(curl -H "Authorization: Bearer ${CV_API_TOKEN}" "https://www.${CVURL}/api/v3/services/admin.Enrollment/AddEnrollmentToken" -d '{"enrollmentToken":{"reenrollDevices":["*"],"validFor":"24h"}}' | sed -n 's|.*"token":"\([^"]*\)".*|\1|p')
94+
else
95+
CVTOKEN=$(curl -H "Authorization: Bearer ${CV_API_TOKEN}" "https://www.cv-staging.corp.arista.io/api/v3/services/admin.Enrollment/AddEnrollmentToken" -d '{"enrollmentToken":{"reenrollDevices":["*"],"validFor":"24h"}}' | sed -n 's|.*"token":"\([^"]*\)".*|\1|p')
96+
fi
97+
if [ "${CVTOKEN}" ]; then
98+
echo "$CVTOKEN" > ${CONTAINERWSF}/clab/cv-onboarding-token
99+
else
100+
echo "ERROR: failed to generate onboarding token!"
101+
fi
102+
else
103+
# add default to avoid clab failing due to missing file
104+
echo "CAFECAFE" > ${CONTAINERWSF}/clab/cv-onboarding-token
105+
fi
106+
107+
if [ -f "${CONTAINERWSF}/postCreate.sh" ]; then
108+
chmod +x ${CONTAINERWSF}/postCreate.sh
109+
${CONTAINERWSF}/postCreate.sh
110+
# delete postCreate.sh after use to avoid confusing lab user
111+
rm ${CONTAINERWSF}/postCreate.sh
112+
fi
113+
114+
# init demo dir as Git repo if requested for this demo env
115+
if ${GIT_INIT:-false}; then
116+
cd ${CONTAINERWSF}
117+
# if not a git repo already - init
118+
if [ -z "$(git status 2>/dev/null)" ]; then
119+
git init
120+
git config --global --add safe.directory ${PWD}
121+
if [ -z "$(git config user.name)" ]; then git config user.name "Lab User"; fi
122+
if [ -z "$(git config user.email)" ]; then git config user.email user@one-click.lab; fi
123+
git add .
124+
git commit -m "git init"
125+
fi
126+
fi
127+
128+
if [ -z "${CODE_SERVER_BIND_ADDR}" ]; then
129+
CODE_SERVER_BIND_ADDR="0.0.0.0:8080"
130+
fi
131+
code-server --bind-addr ${CODE_SERVER_BIND_ADDR} --auth password --disable-telemetry --disable-update-check --disable-workspace-trust "${CONTAINERWSF}" &
132+
133+
# check if image is still missing and print a warning
134+
if [ -z "$(${CONTAINER_ENGINE} image ls | grep 'arista/ceos')" ]; then
135+
echo "WARNING: cEOS-lab image download failed. Try to upload and import it manually."
136+
echo " Please make sure that image is imported with a correct name - arista/ceos:latest"
137+
echo " The lab will not auto start! Run 'make start' when image is ready."
138+
else
139+
cd ${CONTAINERWSF}
140+
make start
141+
fi
142+
143+
# on Codespaces this will not work correctly
144+
if ! ${CODESPACES:-false}; then
145+
# Execute command from docker cli if any.
146+
if [ ${@+True} ]; then
147+
exec "$@"
148+
# Otherwise just enter sh or zsh.
149+
else
150+
if [ -f "/bin/zsh" ]; then
151+
exec zsh
152+
else
153+
exec sh
154+
fi
155+
fi
156+
fi

containers/lab-base/.devcontainer/postCreate.sh

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"workbench.startupEditor": "readme"
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"containerlab": {
3+
"showWelcomePage": false,
4+
"node": {
5+
"sshUserMapping": {
6+
"ceos": "arista"
7+
}
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)