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

Commit

Permalink
feat[Docker]: Add gitconfig in containers (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
titom73 authored Feb 10, 2021
1 parent 02e226b commit 0cb8d77
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"conventionalCommits.scopes": [
"README"
]
}
3 changes: 3 additions & 0 deletions 3.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ USER avd
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
ENV PATH=$PATH:/home/avd/.local/bin

# Copy gitconfig file
COPY gitconfig /home/avd/.gitconfig

# Install Oh My ZSH to provide improved shell
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
Expand Down
17 changes: 17 additions & 0 deletions 3.6/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
DOCKER_SOCKET=/var/run/docker.sock
DOCKER_GROUP=docker
USER=avd
HOME_AVD=/home/avd/

# Install specific requirement file
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
Expand Down Expand Up @@ -33,6 +34,22 @@ if [ ! -z "${AVD_GID}" ]; then
groupmod -g ${AVD_GID} avd
fi

# 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/[email protected]/g" ${HOME_AVD}/.gitconfig
fi

if [ -S ${DOCKER_SOCKET} ]; then
sudo chmod 666 /var/run/docker.sock &>/dev/null
fi
Expand Down
39 changes: 39 additions & 0 deletions 3.6/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
3 changes: 3 additions & 0 deletions 3.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ USER avd
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
ENV PATH=$PATH:/home/avd/.local/bin

# Copy gitconfig file
COPY gitconfig /home/avd/.gitconfig

# Install Oh My ZSH to provide improved shell
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
Expand Down
17 changes: 17 additions & 0 deletions 3.7/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
DOCKER_SOCKET=/var/run/docker.sock
DOCKER_GROUP=docker
USER=avd
HOME_AVD=/home/avd/

# Install specific requirement file
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
Expand Down Expand Up @@ -33,6 +34,22 @@ if [ ! -z "${AVD_GID}" ]; then
groupmod -g ${AVD_GID} avd
fi

# 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/[email protected]/g" ${HOME_AVD}/.gitconfig
fi

if [ -S ${DOCKER_SOCKET} ]; then
sudo chmod 666 /var/run/docker.sock &>/dev/null
fi
Expand Down
39 changes: 39 additions & 0 deletions 3.7/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
3 changes: 3 additions & 0 deletions 3.8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ USER avd
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
ENV PATH=$PATH:/home/avd/.local/bin

# Copy gitconfig file
COPY gitconfig /home/avd/.gitconfig

# Install Oh My ZSH to provide improved shell
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
Expand Down
17 changes: 17 additions & 0 deletions 3.8/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
DOCKER_SOCKET=/var/run/docker.sock
DOCKER_GROUP=docker
USER=avd
HOME_AVD=/home/avd/

# Install specific requirement file
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
Expand Down Expand Up @@ -33,6 +34,22 @@ if [ ! -z "${AVD_GID}" ]; then
groupmod -g ${AVD_GID} avd
fi

# 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/[email protected]/g" ${HOME_AVD}/.gitconfig
fi

if [ -S ${DOCKER_SOCKET} ]; then
sudo chmod 666 /var/run/docker.sock &>/dev/null
fi
Expand Down
39 changes: 39 additions & 0 deletions 3.8/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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ run: ## run docker image
docker run --rm -it -v $(CURRENT_DIR)/:/projects \
-e AVD_REQUIREMENTS=$(PIP_REQ) \
-e AVD_ANSIBLE=$(ANSIBLE_VERSION) \
-e AVD_GIT_USER=$(git config --get user.name) \
-e AVD_GIT_EMAIL=$(git config --get user.email) \
-e AVD_UID=$(UID) \
-e AVD_GID=$(GID) \
-v /etc/hosts:/etc/hosts $(DOCKER_NAME):$(FLAVOR) ;\
else \
docker run --rm -it -v $(CURRENT_DIR)/:/projects \
-e AVD_REQUIREMENTS=$(PIP_REQ) \
-e AVD_ANSIBLE=$(ANSIBLE_VERSION) \
-e AVD_GIT_USER=$(git config --get user.name) \
-e AVD_GIT_EMAIL=$(git config --get user.email) \
-e AVD_UID=$(UID) \
-e AVD_GID=$(GID) \
-v /etc/hosts:/etc/hosts $(DOCKER_NAME):$(FLAVOR)-$(BRANCH) ;\
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ __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 Down Expand Up @@ -52,6 +54,12 @@ These variables are used in `CMD` to customize container content using [`-e` opt
- `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)

Expand Down
6 changes: 6 additions & 0 deletions _template/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ USER avd
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
ENV PATH=$PATH:/home/avd/.local/bin

# Copy gitconfig file
COPY gitconfig /home/avd/.gitconfig

# Copy gitconfig file
COPY gitconfig /home/avd/.gitconfig

# Install Oh My ZSH to provide improved shell
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
Expand Down
33 changes: 31 additions & 2 deletions _template/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/bin/bash

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

# 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}
sudo -H -u ${USER} pip3 install --upgrade --user -r ${AVD_REQUIREMENTS}
else
echo "Requirement file not found, skipping..."
fi
Expand All @@ -14,7 +18,9 @@ fi
# Install specific ANSIBLE version
if [ ! -z "${AVD_ANSIBLE}" ]; then
echo "Install ansible with version ${AVD_ANSIBLE}"
pip3 install --user ansible==${AVD_ANSIBLE}
# Required for migration from 2.9 to 2.10
sudo -H -u ${USER} pip3 uninstall -y ansible
sudo -H -u ${USER} pip3 install --upgrade --user ansible==${AVD_ANSIBLE}
fi

# Reconfigure AVD User id if set by user
Expand All @@ -28,5 +34,28 @@ if [ ! -z "${AVD_GID}" ]; then
groupmod -g ${AVD_GID} avd
fi

# 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/[email protected]/g" ${HOME_AVD}/.gitconfig
fi

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

export PATH=$PATH:/home/avd/.local/bin
export LC_ALL=C.UTF-8

cd /projects/
su - avd -c "cd /projects && /bin/zsh"
Loading

0 comments on commit 0cb8d77

Please sign in to comment.