Skip to content

Commit

Permalink
Merge pull request #1 from traefikturkey/main
Browse files Browse the repository at this point in the history
merging main
  • Loading branch information
ilude authored Mar 22, 2024
2 parents 3228b7d + f0ebf24 commit c4f4636
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
dest: "{{ dotfiles_path }}"
recursive: yes # Recursively clone submodules
update: yes
force: yes
accept_hostkey: yes

- name: Execute {{ dotfiles_path }}/install
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"build": {
"context": "..",
"dockerfile": "../Dockerfile",
"target": "devcontainer",
"args": {
"PROJECT_NAME": "${localWorkspaceFolderBasename}",
"PROJECT_PATH": "${containerWorkspaceFolder}",
// "TZ": "${localEnv:TZ:America/New_York}",
// "TERM_SHELL": "${localEnv:TERM_SHELL:zsh}"
}
},
"postAttachCommand": "ansible-playbook --inventory 127.0.0.1 --connection=local /workspaces/${localWorkspaceFolderBasename}/.devcontainer/ansible/setup-container.yml",
"updateContentCommand": "LC_ALL=C.UTF-8 ansible-playbook --inventory 127.0.0.1 --connection=local ${containerWorkspaceFolder}/.devcontainer/ansible/setup-container.yml",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"runArgs": ["--name", "${localWorkspaceFolderBasename}_devcontainer", "--hostname", "${localWorkspaceFolderBasename}","--env-file",".devcontainer/.env" ],
"mounts": [
Expand Down
7 changes: 7 additions & 0 deletions .devcontainer/entrypoint.d/docker-socket-perms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Check if /var/run/docker.sock exists
if [ -S "/var/run/docker.sock" ]; then
echo "Docker socket detected. changing ownership to ${USER}:${USER}..."
sudo chown ${USER}:${USER} /var/run/docker.sock
fi
182 changes: 122 additions & 60 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# syntax=docker/dockerfile:1.4
FROM python:3.12-slim-bookworm
ARG PYTHON_VERSION=3.12

FROM python:${PYTHON_VERSION}-slim-bookworm as base
LABEL maintainer="Mike Glenn <[email protected]>"

ARG PUID=${PUID:-1000}
Expand All @@ -10,77 +12,52 @@ ARG TZ=America/New_York
ENV USER=${USER}
ENV TZ=${TZ}

ARG PROJECT_NAME
ENV PROJECT_NAME=${PROJECT_NAME}

ARG PROJECT_PATH
ARG PROJECT_PATH=/app
ENV PROJECT_PATH=${PROJECT_PATH}

ARG TERM_SHELL=zsh
ENV TERM_SHELL=${TERM_SHELL}
ENV PYTHON_DEPS_PATH=/dependencies
ENV PYTHONPATH="${PYTHONPATH}:${PYTHON_DEPS_PATH}"

ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN=true

ENV HOME=/home/${USER}
ARG TERM_SHELL=zsh
ENV TERM_SHELL=${TERM_SHELL}

RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
bash-completion \
ansible \
binutils \
build-essential \
ca-certificates \
cmake \
coreutils \
curl \
exa \
extra-cmake-modules \
findutils \
git \
iproute2 \
jq \
less \
locales \
make \
openssl \
openssh-client \
ripgrep \
rsync \
sshpass \
sudo \
tar \
tree \
tzdata \
util-linux \
yq \
zsh \
zsh-autosuggestions \
zsh-syntax-highlighting && \
apt-get autoremove -fy && \
apt-get clean && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/* && \
# https://www.jeffgeerling.com/blog/2023/how-solve-error-externally-managed-environment-when-installing-pip3
sudo rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED
bash \
bash-completion \
ca-certificates \
curl \
less \
locales \
make \
tzdata \
zsh && \
# install google chrome for webdriver
curl -o google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt install -fy ./google-chrome-stable_current_amd64.deb && \
rm -rf google-chrome-stable_current_amd64.deb && \
# cleanup
apt-get autoremove -fy && \
apt-get clean && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

RUN sed -i 's/UID_MAX .*/UID_MAX 100000/' /etc/login.defs && \
groupadd --gid ${PGID} ${USER} && \
useradd --uid ${PUID} --gid ${PGID} -s /bin/${TERM_SHELL} -m ${USER} && \
echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} && \
chmod 0440 /etc/sudoers.d/${USER} && \
mkdir -p ${PROJECT_PATH}
echo "alias l='ls -lhA --color=auto --group-directories-first'" >> /etc/zshenv && \
echo "alias es='env | sort'" >> /etc/zshenv && \
echo "PS1='\h:\$(pwd) \$ '" >> /etc/zshenv && \
mkdir -p ${PROJECT_PATH} && \
chown -R ${USER}:${USER} ${PROJECT_PATH} && \
# https://www.jeffgeerling.com/blog/2023/how-solve-error-externally-managed-environment-when-installing-pip3
rm -rf /usr/lib/python${PYTHON_VERSION}/EXTERNALLY-MANAGED

ENV HOME=/home/${USER}

COPY requirements.txt /tmp/requirements.txt
RUN pip3 install --upgrade pip && \
pip3 install --upgrade setuptools && \
pip3 install --upgrade wheel && \
pip3 install --no-cache-dir -r /tmp/requirements.txt && \
rm -rf /tmp/requirements.txt

COPY --chmod=755 <<-"EOF" /usr/local/bin/docker-entrypoint.sh
#!/bin/bash
set -e
Expand All @@ -89,14 +66,99 @@ if [ -v DOCKER_ENTRYPOINT_DEBUG ] && [ "$DOCKER_ENTRYPOINT_DEBUG" == 1 ]; then
set -o xtrace
fi

sudo chown ${USER}:${USER} /var/run/docker.sock
# Check if the directory exists
if [ -d "${PROJECT_PATH}/.devcontainer/entrypoint.d" ]; then
# Loop through all *.sh files in the directory and execute them
for script in "${PROJECT_PATH}/.devcontainer/entrypoint.d"/*.sh; do
chmod +x "$script"
echo "Executing entrypoint script: $script"
"$script"
done
fi

echo "Running: $@"
exec $@
EOF

WORKDIR $PROJECT_PATH
ENTRYPOINT [ "docker-entrypoint.sh" ]


##############################
# Begin build
##############################
FROM base as build

RUN apt-get update && apt-get install -y --no-install-recommends \
binutils \
build-essential \
cmake \
coreutils \
extra-cmake-modules \
findutils \
git \
openssl \
openssh-client \
wget && \
apt-get autoremove -fy && \
apt-get clean && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements.txt
RUN pip3 install --upgrade pip && \
pip3 install --upgrade setuptools && \
pip3 install --upgrade wheel && \
mkdir -p ${PYTHON_DEPS_PATH} && \
chown -R ${USER}:${USER} ${PROJECT_PATH} ${PYTHON_DEPS_PATH} && \
pip3 install --no-cache-dir --target=${PYTHON_DEPS_PATH} -r requirements.txt && \
rm -rf requirements.txt

##############################
# Begin production
##############################
FROM base as production

COPY --from=build --chown=${USER}:${USER} ${PYTHON_DEPS_PATH} ${PYTHON_DEPS_PATH}
COPY --chown=${USER}:${USER} app ${PROJECT_PATH}
USER ${USER}

CMD [ "python3", "app/app.py" ]


##############################
# Begin devcontainer
##############################
FROM build as devcontainer

RUN apt-get update && apt-get install -y --no-install-recommends \
ansible \
exa \
iproute2 \
jq \
openssh-client \
ripgrep \
rsync \
sshpass \
sudo \
tar \
tree \
util-linux \
yq \
zsh-autosuggestions \
zsh-syntax-highlighting && \
apt-get autoremove -fy && \
apt-get clean && \
apt-get autoclean -y && \
rm -rf /var/lib/apt/lists/*

RUN echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} && \
chmod 0440 /etc/sudoers.d/${USER}

ARG PROJECT_NAME
ENV PROJECT_NAME=${PROJECT_NAME}

USER ${USER}

# https://code.visualstudio.com/remote/advancedcontainers/start-processes#_adding-startup-commands-to-the-docker-image-instead
ENTRYPOINT [ "docker-entrypoint.sh" ]
CMD [ "sleep", "infinity" ]
File renamed without changes.

0 comments on commit c4f4636

Please sign in to comment.