Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.

Avd2.2.0 cvp3.0.0 debian #21

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
34 changes: 3 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![](https://img.shields.io/badge/Arista-CVP%20Automation-blue) ![](https://img.shields.io/badge/Arista-EOS%20Automation-blue) ![GitHub](https://img.shields.io/github/license/arista-netdevops-community/docker-avd-base) ![Docker Pulls](https://img.shields.io/docker/pulls/avdteam/base) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/avdteam/base/latest) ![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/avdteam/base/latest)

# AVD Base Image

Image with all python requirements installed to then run [__Arista Validated Design__](https://github.com/aristanetworks/ansible-avd) collection with a minimal configuration overhead. It can be used to support local development using following workflow
Expand All @@ -10,9 +11,6 @@ __Docker image:__ [`avdteam/base`](https://hub.docker.com/repository/docker/avdt
__Table of content__
- [AVD Base Image](#avd-base-image)
- [Description](#description)
- [Available Tags](#available-tags)
- [Stable version](#stable-version)
- [Deprecated](#deprecated)
- [Available variables](#available-variables)
- [How to leverage image](#how-to-leverage-image)
- [Arista Validated Design](#arista-validated-design)
Expand All @@ -26,41 +24,15 @@ __Table of content__

## Description

### Available Tags

- [`3.6`](3.6/Dockerfile)*
- [`3.7`](3.7/Dockerfile)
- [`3.8`](3.8/Dockerfile) / (latest)

#### Stable version

- `3.6-v<git-tag>`
- `3.7-v<git-tag>`
- `3.8-v<git-tag>`

#### Deprecated

- [`centos-7`](centos-7/Dockerfile) (deprecated)
- [`centos-8`](centos-8/Dockerfile) (deprecated)
``

Current image used in AVD development: `avdteam/base:3.6`

### Available variables

These variables are used in `CMD` to customize container content using [`-e` option of docker](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e---env---env-file) cli:

- `AVD_REQUIREMENTS`: Path to a `requirements.txt` to install during container startup.
- `AVD_ANSIBLE`: Ansible version to install in container when booting up
- `AVD_UID`: set __uid__ for avd user in container.
- `AVD_GID`: set __gid__ for avd user in container.
- `AVD_GIT_USER`: Username to configure in .gitconfig file.
- Can be set with `AVD_GIT_USER=$(git config --get user.name)`
- `AVD_GIT_EMAIL`: Email to configure in .gitconfig file.
- Can be set with `AVD_GIT_EMAIL=$(git config --get user.email)`



To see how to customize your container with these options, you can refer to [How to install ansible and Python requirements page](docs/run-options.md)

## How to leverage image
Expand Down Expand Up @@ -122,8 +94,8 @@ You can also configure your shell with an alias to make it easy to start contain
```shell
# Configure alias in bashrc
alias avd-shell='docker run -it --rm \
-v ${PWD}/:/projects \
avdteam/base:latest zsh'
-v ${PWD}/:/projects \
avdteam/base:latest zsh'

# Run alias command
$ avd-shell
Expand Down
87 changes: 87 additions & 0 deletions avd2.2.0_cvp3.0.0_debian/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
FROM python:3.9.5-slim

# install tools permanently
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
make \
wget \
curl \
less \
git \
zsh \
vim \
sudo \
sshpass \
git-extras \
openssh-client \
&& rm -rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
&& apt-get clean

# install docker in docker and docker-compose
RUN curl -fsSL https://get.docker.com | sh \
&& curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose

# add AVD user
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd \
&& echo 'avd ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
# add docker and sudo to avd group
&& usermod -aG docker avd \
&& usermod -aG sudo avd
USER avd
ENV HOME=/home/avd
ENV PATH=$PATH:/home/avd/.local/bin

WORKDIR /home/avd

# install zsh
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
&& echo 'PROMPT="%{$fg[red]%}A$fg[green]%}V$fg[blue]%}D 🐳 %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)"' >> /home/avd/.zshrc \
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> ${HOME}/.zshrc \
&& echo 'eval `ssh-agent -s`' >> $HOME/.zshrc \
&& echo 'export TERM=xterm-256color' >> $HOME/.zshrc \
&& echo "export LC_ALL=C.UTF-8" >> $HOME/.zshrc \
&& echo "export LANG=C.UTF-8" >> $HOME/.zshrc \
&& echo 'export PATH=$PATH:/home/avd/.local/bin' >> $HOME/.zshrc

# ^ ^ ^
# | | | The section above usually remains unchanged between releases

# | | | The section below will be updated for every release
# V V V

# add entrypoint script
COPY ./entrypoint.sh /bin/entrypoint.sh
RUN sudo chmod +x /bin/entrypoint.sh
# use ENTRYPOINT instead of CMD to ensure that entryscript is always executed
ENTRYPOINT [ "/bin/entrypoint.sh" ]

# add AVD gitconfig to be used if container is not called as VScode devcontainer
COPY ./gitconfig /home/avd/gitconfig-avd-base-template

# change this for every release
ENV _AVD_VERSION="v2.2.0"
ENV _CVP_VERSION="v3.0.0"

# labels to be changed for every release
LABEL maintainer="Arista Ansible Team <ansible@arista.com>"
LABEL com.example.version="2.0.0"
LABEL vendor1="Arista"
LABEL com.example.release-date="2021-06-28"
LABEL com.example.version.is-production="False"

# clone AVD and CVP collections
RUN _CURL=$(which curl) \
&& _GIT=$(which git) \
&& _REPO_AVD="https://github.com/aristanetworks/ansible-avd.git" \
&& _REPO_CVP="https://github.com/aristanetworks/ansible-cvp.git" \
&& ${_GIT} clone --depth 1 --branch ${_AVD_VERSION} --single-branch ${_REPO_AVD} /home/avd/ansible-avd \
&& ${_GIT} clone --depth 1 --branch ${_CVP_VERSION} --single-branch ${_REPO_CVP} /home/avd/ansible-cvp \
&& pip3 install --user --no-cache-dir -r /home/avd/ansible-avd/ansible_collections/arista/avd/requirements.txt \
&& pip3 install --user --no-cache-dir -r /home/avd/ansible-avd/ansible_collections/arista/avd/requirements-dev.txt \
&& pip3 install --user --no-cache-dir -r /home/avd/ansible-cvp/ansible_collections/arista/cvp/requirements.txt \
&& pip3 install --user --no-cache-dir -r /home/avd/ansible-cvp/ansible_collections/arista/cvp/requirements-dev.txt

# if not running as VScode devcontainer, start in projects
WORKDIR /home/avd/projects
43 changes: 43 additions & 0 deletions avd2.2.0_cvp3.0.0_debian/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

DOCKER_SOCKET=/var/run/docker.sock
DOCKER_GROUP=docker
USER=avd
HOME_AVD=/home/avd

GITCFGFILE=${HOME_AVD}/.gitconfig

# if container is called as devcontainer from VScode, .gitconfig must be present
if [ -f ${GITCFGFILE} ]; then
rm -f ${HOME_AVD}/gitconfig-avd-base-template
# if no .gitconfig created by VScode, copy AVD base template and edit
else
mv ${HOME_AVD}/gitconfig-avd-base-template ${HOME_AVD}/.gitconfig
# Update gitconfig with username and email
if [ -n "${AVD_GIT_USER}" ]; then
echo "Update gitconfig with ${AVD_GIT_USER}"
sed -i "s/USERNAME/${AVD_GIT_USER}/g" ${HOME_AVD}/.gitconfig
else
echo "Update gitconfig with default username"
sed -i "s/USERNAME/AVD Base USER/g" ${HOME_AVD}/.gitconfig
fi
if [ -n "${AVD_GIT_EMAIL}" ]; then
echo "Update gitconfig with ${AVD_GIT_EMAIL}"
sed -i "s/USER_EMAIL/${AVD_GIT_EMAIL}/g" ${HOME_AVD}/.gitconfig
else
echo "Update gitconfig with default email"
sed -i "s/USER_EMAIL/avd-base@arista.com/g" ${HOME_AVD}/.gitconfig
fi
fi

if [ -S ${DOCKER_SOCKET} ]; then
sudo chmod 666 /var/run/docker.sock &>/dev/null
fi

# execute command from docker cli if any
if [ ${@+True} ]; then
exec "$@"
# otherwise just enter zsh
else
exec zsh
fi
39 changes: 39 additions & 0 deletions avd2.2.0_cvp3.0.0_debian/gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[user]
name = USERNAME
email = USER_EMAIL
[alias]
# Generic command
rollback = reset --hard
recommit = commit --amend --no-edit
commit-unsafe = commit --no-verify
undo = reset HEAD~1 --mixed
uncommit = reset --soft HEAD~1

# Misc command
refresh = !git pull --rebase --prune $@
conflicts = !git ls-files -u | cut -f 2 | sort -u
push-current = push -u origin HEAD

# Logging & History
last = log --stat -1 HEAD
graph = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
logs = log --oneline --decorate --color

# In Fork model
forigin = fetch origin
fupstream = fetch upstream
fetch-all = !sh -c 'for remote in $(git remote);do git fetch remote;done'

[core]
excludesfile = ~/.gitignore_global
[commit]
template = ~/.stCommitMsg
[pull]
rebase = true
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[pager]
branch = false
44 changes: 9 additions & 35 deletions docs/avd-vscode-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This how-to explains how to leverage __avdteam/base__ image as shell under [VSco
__Table of content__
- [How to use AVD image with VSCODE](#how-to-use-avd-image-with-vscode)
- [About](#about)
- [Configure AVD environment](#configure-avd-environment)
- [Devcontainer with docker image](#devcontainer-with-docker-image)
- [Requirements](#requirements)
- [Configure devcontainer](#configure-devcontainer)
Expand All @@ -17,38 +16,6 @@ __Table of content__
- [Configure devcontainer](#configure-devcontainer-1)
- [Open content in container](#open-content-in-container-1)

## Configure AVD environment

Before running all code with a container, we have to download current AVD ecosystem with the following command:

- On Linux or Macos:

```shell
$ curl -fsSL https://get.avd.sh | sh
```

- On Windows:

```shell
PS C:\Users\User> Invoke-WebRequest -OutFile install.sh -Uri \
https://raw.githubusercontent.com/arista-netdevops-community/avd-install/master/install.sh

PS C:\Users\User> bash install.sh
```

This script git clone AVD and CVP collection as well as example repository to get started with example.

```shell
$ cd ansible-arista

$ ls -al
total 24
-rw-rw-r-- 1 tom tom 2517 Jul 20 09:09 Makefile
drwxrwxr-x 8 tom tom 4096 Jul 20 09:09 ansible-avd
drwxrwxr-x 8 tom tom 4096 Jul 20 09:09 ansible-avd-cloudvision-demo
drwxrwxr-x 9 tom tom 4096 Jul 20 09:09 ansible-cvp
```

## Devcontainer with docker image

### Requirements
Expand Down Expand Up @@ -82,7 +49,6 @@ Copy following content to `devcontainer.json`:
"image": "avdteam/base:3.6",

"settings": {
"terminal.integrated.shell.linux": "/bin/zsh",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.flake8Path": "/root/.local/bin/flake8",
Expand Down Expand Up @@ -111,13 +77,21 @@ Copy following content to `devcontainer.json`:
"ms-python.vscode-pylance",
"tht13.python"
],

"containerEnv": {
"ANSIBLE_CONFIG": "./ansible.cfg"
}
},

"remoteUser": "avd"
}

```

If any custom container modifications are required:

1. Use "postCreateCommand" to install any missing requirements or custom Ansible version.
2. Use bind mount to mount custom ansible-avd and ansible-cvp collections instead of default `/home/avd/ansible-avd` or `/home/avd/ansible-cvp`

### Open content in container

After you configured `.devcontainer/devcontainer.json` correctly, you can open VScode and start local container with following actions:
Expand Down
28 changes: 0 additions & 28 deletions docs/image-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,6 @@ __Docker image:__ [`avdteam/base`](https://hub.docker.com/repository/docker/avdt
- Requirements from [arista.cvp](https://github.com/aristanetworks/ansible-cvp)
- Requirements from [arista.avd](https://github.com/aristanetworks/ansible-avd)

### Installed during container startup

- [`CMD`](./../_template/entrypoint.sh) configured to support ENV configuration.

CMD script example:

```shell
#!/bin/bash

# Install specific requirement file
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
if [ -f ${AVD_REQUIREMENTS} ]; then
echo "Install new requirements from ${AVD_REQUIREMENTS}"
pip3 install --user -r ${AVD_REQUIREMENTS}
else
echo "Requirement file not found, skipping..."
fi
fi

# Install specific ANSIBLE version
if [ ! -z "${AVD_ANSIBLE}" ]; then
echo "Install ansible with version ${AVD_ANSIBLE}"
pip3 install --user ansible==${AVD_ANSIBLE}
fi

exec /bin/zsh
```

## Build local images

You can use this repository to build your own version to test lib upgrade or a new flavor. it creates an image based on:
Expand Down
Loading