-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
47 lines (38 loc) · 1.3 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Use the official Kubespray image as the base
ARG DOCKER_IMAGE
FROM ${DOCKER_IMAGE}
# Set environment variables
ENV HOME=/home/kubespray \
DEBIAN_FRONTEND=noninteractive
# Switch to root to install additional packages and set up the environment
USER root
# Install additional packages if needed
RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN groupadd -g ${GROUP_ID} kubespray && \
useradd -m -u ${USER_ID} -g ${GROUP_ID} -G sudo -s /bin/bash kubespray && \
echo "kubespray ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
chmod 0440 /etc/sudoers && \
mkdir -p /home/kubespray/inventory && \
mkdir -p /home/kubespray/.ssh && \
chown -R kubespray:kubespray /home/kubespray && \
chmod 755 /home/kubespray/inventory && \
chmod 700 /home/kubespray/.ssh
# Copy SSH directory
COPY --chown=kubespray:kubespray ssh /home/kubespray/.ssh
# Set correct permissions for SSH files
RUN chmod 600 /home/kubespray/.ssh/id_ed25519 && \
chmod 644 /home/kubespray/.ssh/config
# Switch back to the non-root user
USER kubespray
# Set the working directory
WORKDIR /kubespray
# Set the entrypoint
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["bash"]