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

Commit 02e226b

Browse files
authored
Merge pull request #10 from arista-netdevops-community/feature-uid
2 parents 63d065d + d12c267 commit 02e226b

File tree

10 files changed

+233
-55
lines changed

10 files changed

+233
-55
lines changed

3.6/Dockerfile

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
FROM python:3.6-slim as BUILDER
22

3+
WORKDIR /tmp
4+
35
# FROM python:3.7-slim AS compile-image
46
RUN apt-get update
57
RUN apt-get install -y --no-install-recommends build-essential gcc wget git
68

7-
ENV PATH=/root/.local/bin:$PATH
9+
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd
10+
USER avd
11+
12+
ENV PATH=$PATH:/home/avd/.local/bin
813
RUN pip3 install --upgrade pip
914
RUN wget --quiet https://raw.githubusercontent.com/aristanetworks/ansible-avd/devel/development/requirements.txt
1015
RUN pip3 install --user -r requirements.txt
@@ -25,6 +30,7 @@ LABEL com.example.version.is-production="False"
2530
ARG TERM=xterm
2631

2732
ENV DEBIAN_FRONTEND noninteractive
33+
ENV PROJECT_DIR /projects/
2834

2935
# Install dependencies.
3036
RUN apt-get update \
@@ -39,24 +45,40 @@ RUN apt-get update \
3945
sshpass \
4046
git-extras \
4147
openssh-client \
48+
sudo \
4249
&& rm -rf /var/lib/apt/lists/* \
4350
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
4451
&& apt-get clean
4552

46-
COPY --from=BUILDER /root/.local/ /root/.local
47-
COPY entrypoint.sh /bin/entrypoint.sh
48-
RUN chmod +x /bin/entrypoint.sh
53+
RUN curl -fsSL https://get.docker.com | sh
54+
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd
55+
RUN usermod -aG docker avd\
56+
&& usermod -aG sudo avd \
57+
&& echo "avd ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
4958

50-
# Create the /project directory and add it as a mountpoint
51-
WORKDIR /projects
52-
VOLUME ["/projects"]
59+
USER avd
60+
61+
# Copy python collection
62+
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
63+
ENV PATH=$PATH:/home/avd/.local/bin
5364

5465
# Install Oh My ZSH to provide improved shell
5566
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
5667
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
5768
&& echo 'eval `ssh-agent -s`' >> $HOME/.zshrc \
58-
&& echo 'export TERM=xterm' >> $HOME/.zshrc
69+
&& echo 'export TERM=xterm' >> $HOME/.zshrc \
70+
&& echo "export LC_ALL=C.UTF-8" >> $HOME/.zshrc \
71+
&& echo "export LANG=C.UTF-8" >> $HOME/.zshrc \
72+
&& echo "export LC_ALL=C.UTF-8" >> $HOME/.zshrc \
73+
&& echo "export LANG=C.UTF-8" >> $HOME/.zshrc \
74+
&& echo 'export PATH=$PATH:/home/avd/.local/bin' >> $HOME/.zshrc
75+
76+
# Set default folder
77+
WORKDIR /projects
78+
VOLUME ["/projects"]
5979

6080
# Use ZSH as default shell with default oh-my-zsh theme
61-
ENV PATH=$PATH:/root/.local/bin
81+
USER root
82+
COPY entrypoint.sh /bin/entrypoint.sh
83+
RUN chmod +x /bin/entrypoint.sh
6284
CMD [ "/bin/entrypoint.sh" ]

3.6/entrypoint.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/bin/bash
22

3+
DOCKER_SOCKET=/var/run/docker.sock
4+
DOCKER_GROUP=docker
5+
USER=avd
6+
37
# Install specific requirement file
48
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
59
if [ -f ${AVD_REQUIREMENTS} ]; then
610
echo "Install new requirements from ${AVD_REQUIREMENTS}"
7-
pip3 install --user -r ${AVD_REQUIREMENTS}
11+
sudo -H -u ${USER} pip3 install --upgrade --user -r ${AVD_REQUIREMENTS}
812
else
913
echo "Requirement file not found, skipping..."
1014
fi
@@ -13,7 +17,28 @@ fi
1317
# Install specific ANSIBLE version
1418
if [ ! -z "${AVD_ANSIBLE}" ]; then
1519
echo "Install ansible with version ${AVD_ANSIBLE}"
16-
pip3 install --user ansible==${AVD_ANSIBLE}
20+
# Required for migration from 2.9 to 2.10
21+
sudo -H -u ${USER} pip3 uninstall -y ansible
22+
sudo -H -u ${USER} pip3 install --upgrade --user ansible==${AVD_ANSIBLE}
23+
fi
24+
25+
# Reconfigure AVD User id if set by user
26+
if [ ! -z "${AVD_UID}" ]; then
27+
echo "Update uid for user avd with ${AVD_UID}"
28+
usermod -u ${AVD_UID} avd
29+
fi
30+
31+
if [ ! -z "${AVD_GID}" ]; then
32+
echo "Update gid for group avd with ${AVD_GID}"
33+
groupmod -g ${AVD_GID} avd
34+
fi
35+
36+
if [ -S ${DOCKER_SOCKET} ]; then
37+
sudo chmod 666 /var/run/docker.sock &>/dev/null
1738
fi
1839

19-
exec /bin/zsh
40+
export PATH=$PATH:/home/avd/.local/bin
41+
export LC_ALL=C.UTF-8
42+
43+
cd /projects/
44+
su - avd -c "cd /projects && /bin/zsh"

3.7/Dockerfile

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
FROM python:3.7-slim as BUILDER
22

3+
WORKDIR /tmp
4+
35
# FROM python:3.7-slim AS compile-image
46
RUN apt-get update
57
RUN apt-get install -y --no-install-recommends build-essential gcc wget git
68

7-
ENV PATH=/root/.local/bin:$PATH
9+
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd
10+
USER avd
11+
12+
ENV PATH=$PATH:/home/avd/.local/bin
813
RUN pip3 install --upgrade pip
914
RUN wget --quiet https://raw.githubusercontent.com/aristanetworks/ansible-avd/devel/development/requirements.txt
1015
RUN pip3 install --user -r requirements.txt
@@ -25,6 +30,7 @@ LABEL com.example.version.is-production="False"
2530
ARG TERM=xterm
2631

2732
ENV DEBIAN_FRONTEND noninteractive
33+
ENV PROJECT_DIR /projects/
2834

2935
# Install dependencies.
3036
RUN apt-get update \
@@ -43,20 +49,33 @@ RUN apt-get update \
4349
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
4450
&& apt-get clean
4551

46-
COPY --from=BUILDER /root/.local/ /root/.local
47-
COPY entrypoint.sh /bin/entrypoint.sh
48-
RUN chmod +x /bin/entrypoint.sh
52+
RUN curl -fsSL https://get.docker.com | sh
53+
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd
54+
RUN usermod -aG docker avd\
55+
&& usermod -aG sudo avd \
56+
&& echo "avd ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
4957

50-
# Create the /project directory and add it as a mountpoint
51-
WORKDIR /projects
52-
VOLUME ["/projects"]
58+
USER avd
59+
60+
# Copy python collection
61+
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
62+
ENV PATH=$PATH:/home/avd/.local/bin
5363

5464
# Install Oh My ZSH to provide improved shell
5565
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
5666
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
5767
&& echo 'eval `ssh-agent -s`' >> $HOME/.zshrc \
58-
&& echo 'export TERM=xterm' >> $HOME/.zshrc
68+
&& echo 'export TERM=xterm' >> $HOME/.zshrc \
69+
&& echo "export LC_ALL=C.UTF-8" >> $HOME/.zshrc \
70+
&& echo "export LANG=C.UTF-8" >> $HOME/.zshrc \
71+
&& echo 'export PATH=$PATH:/home/avd/.local/bin' >> $HOME/.zshrc
72+
73+
# Set default folder
74+
WORKDIR /projects
75+
VOLUME ["/projects"]
5976

6077
# Use ZSH as default shell with default oh-my-zsh theme
61-
ENV PATH=$PATH:/root/.local/bin
78+
USER root
79+
COPY entrypoint.sh /bin/entrypoint.sh
80+
RUN chmod +x /bin/entrypoint.sh
6281
CMD [ "/bin/entrypoint.sh" ]

3.7/entrypoint.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/bin/bash
22

3+
DOCKER_SOCKET=/var/run/docker.sock
4+
DOCKER_GROUP=docker
5+
USER=avd
6+
37
# Install specific requirement file
48
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
59
if [ -f ${AVD_REQUIREMENTS} ]; then
610
echo "Install new requirements from ${AVD_REQUIREMENTS}"
7-
pip3 install --user -r ${AVD_REQUIREMENTS}
11+
sudo -H -u ${USER} pip3 install --upgrade --user -r ${AVD_REQUIREMENTS}
812
else
913
echo "Requirement file not found, skipping..."
1014
fi
@@ -13,7 +17,28 @@ fi
1317
# Install specific ANSIBLE version
1418
if [ ! -z "${AVD_ANSIBLE}" ]; then
1519
echo "Install ansible with version ${AVD_ANSIBLE}"
16-
pip3 install --user ansible==${AVD_ANSIBLE}
20+
# Required for migration from 2.9 to 2.10
21+
sudo -H -u ${USER} pip3 uninstall -y ansible
22+
sudo -H -u ${USER} pip3 install --upgrade --user ansible==${AVD_ANSIBLE}
23+
fi
24+
25+
# Reconfigure AVD User id if set by user
26+
if [ ! -z "${AVD_UID}" ]; then
27+
echo "Update uid for user avd with ${AVD_UID}"
28+
usermod -u ${AVD_UID} avd
29+
fi
30+
31+
if [ ! -z "${AVD_GID}" ]; then
32+
echo "Update gid for group avd with ${AVD_GID}"
33+
groupmod -g ${AVD_GID} avd
34+
fi
35+
36+
if [ -S ${DOCKER_SOCKET} ]; then
37+
sudo chmod 666 /var/run/docker.sock &>/dev/null
1738
fi
1839

19-
exec /bin/zsh
40+
export PATH=$PATH:/home/avd/.local/bin
41+
export LC_ALL=C.UTF-8
42+
43+
cd /projects/
44+
su - avd -c "cd /projects && /bin/zsh"

3.8/Dockerfile

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
FROM python:3.8-slim as BUILDER
22

3+
WORKDIR /tmp
4+
35
# FROM python:3.7-slim AS compile-image
46
RUN apt-get update
57
RUN apt-get install -y --no-install-recommends build-essential gcc wget git
68

7-
ENV PATH=/root/.local/bin:$PATH
9+
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd
10+
USER avd
11+
12+
ENV PATH=$PATH:/home/avd/.local/bin
813
RUN pip3 install --upgrade pip
914
RUN wget --quiet https://raw.githubusercontent.com/aristanetworks/ansible-avd/devel/development/requirements.txt
1015
RUN pip3 install --user -r requirements.txt
@@ -25,6 +30,7 @@ LABEL com.example.version.is-production="False"
2530
ARG TERM=xterm
2631

2732
ENV DEBIAN_FRONTEND noninteractive
33+
ENV PROJECT_DIR /projects/
2834

2935
# Install dependencies.
3036
RUN apt-get update \
@@ -43,20 +49,33 @@ RUN apt-get update \
4349
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man \
4450
&& apt-get clean
4551

46-
COPY --from=BUILDER /root/.local/ /root/.local
47-
COPY entrypoint.sh /bin/entrypoint.sh
48-
RUN chmod +x /bin/entrypoint.sh
52+
RUN curl -fsSL https://get.docker.com | sh
53+
RUN useradd -md /home/avd -s /bin/zsh -u 1000 avd
54+
RUN usermod -aG docker avd\
55+
&& usermod -aG sudo avd \
56+
&& echo "avd ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
4957

50-
# Create the /project directory and add it as a mountpoint
51-
WORKDIR /projects
52-
VOLUME ["/projects"]
58+
USER avd
59+
60+
# Copy python collection
61+
COPY --from=BUILDER /home/avd/.local/ /home/avd/.local
62+
ENV PATH=$PATH:/home/avd/.local/bin
5363

5464
# Install Oh My ZSH to provide improved shell
5565
RUN wget --quiet https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh || true \
5666
&& echo 'plugins=(ansible common-aliases safe-paste git jsontools history git-extras)' >> $HOME/.zshrc \
5767
&& echo 'eval `ssh-agent -s`' >> $HOME/.zshrc \
58-
&& echo 'export TERM=xterm' >> $HOME/.zshrc
68+
&& echo 'export TERM=xterm' >> $HOME/.zshrc \
69+
&& echo "export LC_ALL=C.UTF-8" >> $HOME/.zshrc \
70+
&& echo "export LANG=C.UTF-8" >> $HOME/.zshrc \
71+
&& echo 'export PATH=$PATH:/home/avd/.local/bin' >> $HOME/.zshrc
72+
73+
# Set default folder
74+
WORKDIR /projects
75+
VOLUME ["/projects"]
5976

6077
# Use ZSH as default shell with default oh-my-zsh theme
61-
ENV PATH=$PATH:/root/.local/bin
78+
USER root
79+
COPY entrypoint.sh /bin/entrypoint.sh
80+
RUN chmod +x /bin/entrypoint.sh
6281
CMD [ "/bin/entrypoint.sh" ]

3.8/entrypoint.sh

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/bin/bash
22

3+
DOCKER_SOCKET=/var/run/docker.sock
4+
DOCKER_GROUP=docker
5+
USER=avd
6+
37
# Install specific requirement file
48
if [ ! -z "${AVD_REQUIREMENTS}" ]; then
59
if [ -f ${AVD_REQUIREMENTS} ]; then
610
echo "Install new requirements from ${AVD_REQUIREMENTS}"
7-
pip3 install --user -r ${AVD_REQUIREMENTS}
11+
sudo -H -u ${USER} pip3 install --upgrade --user -r ${AVD_REQUIREMENTS}
812
else
913
echo "Requirement file not found, skipping..."
1014
fi
@@ -13,7 +17,28 @@ fi
1317
# Install specific ANSIBLE version
1418
if [ ! -z "${AVD_ANSIBLE}" ]; then
1519
echo "Install ansible with version ${AVD_ANSIBLE}"
16-
pip3 install --user ansible==${AVD_ANSIBLE}
20+
# Required for migration from 2.9 to 2.10
21+
sudo -H -u ${USER} pip3 uninstall -y ansible
22+
sudo -H -u ${USER} pip3 install --upgrade --user ansible==${AVD_ANSIBLE}
23+
fi
24+
25+
# Reconfigure AVD User id if set by user
26+
if [ ! -z "${AVD_UID}" ]; then
27+
echo "Update uid for user avd with ${AVD_UID}"
28+
usermod -u ${AVD_UID} avd
29+
fi
30+
31+
if [ ! -z "${AVD_GID}" ]; then
32+
echo "Update gid for group avd with ${AVD_GID}"
33+
groupmod -g ${AVD_GID} avd
34+
fi
35+
36+
if [ -S ${DOCKER_SOCKET} ]; then
37+
sudo chmod 666 /var/run/docker.sock &>/dev/null
1738
fi
1839

19-
exec /bin/zsh
40+
export PATH=$PATH:/home/avd/.local/bin
41+
export LC_ALL=C.UTF-8
42+
43+
cd /projects/
44+
su - avd -c "cd /projects && /bin/zsh"

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ ANSIBLE_VERSION ?=
77
PIP_REQ ?= NONE
88
# New Flavor creation
99
TEMPLATE ?= _template
10-
10+
UID ?= 1000
11+
GID ?= 1000
1112

1213
.PHONY: help
1314
help: ## Display help message
@@ -27,16 +28,20 @@ run: ## run docker image
2728
docker run --rm -it -v $(CURRENT_DIR)/:/projects \
2829
-e AVD_REQUIREMENTS=$(PIP_REQ) \
2930
-e AVD_ANSIBLE=$(ANSIBLE_VERSION) \
31+
-e AVD_UID=$(UID) \
32+
-e AVD_GID=$(GID) \
3033
-v /etc/hosts:/etc/hosts $(DOCKER_NAME):$(FLAVOR) ;\
3134
else \
3235
docker run --rm -it -v $(CURRENT_DIR)/:/projects \
3336
-e AVD_REQUIREMENTS=$(PIP_REQ) \
3437
-e AVD_ANSIBLE=$(ANSIBLE_VERSION) \
38+
-e AVD_UID=$(UID) \
39+
-e AVD_GID=$(GID) \
3540
-v /etc/hosts:/etc/hosts $(DOCKER_NAME):$(FLAVOR)-$(BRANCH) ;\
3641
fi
3742

3843

3944
.PHONY: new-flavor
4045
new-flavor: ## Create a new python flavor
4146
cp -r $(TEMPLATE) $(FLAVOR)
42-
sed -i '' 's/FLAVOR/$(FLAVOR)/' $(FLAVOR)/Dockerfile
47+
sed -i '' 's/FLAVOR/$(FLAVOR)/' $(FLAVOR)/Dockerfile

0 commit comments

Comments
 (0)