diff --git a/Docker/Dockerfile b/Docker/Dockerfile index 6843d83..8d4cf77 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -1,6 +1,8 @@ # 1. A: Define a base image FROM itdominator-base +ARG USERNAME=itdominator + # 1. B: Set ENV Variables ENV NVM_VERSION=0.40.3 ENV NODE_VERSION=24.9.0 @@ -27,7 +29,7 @@ ENV PATH="${JAVA_HOME}/bin:${PATH}" ENV PATH="/opt:${PATH}" # 2. Set the working directory inside the container -WORKDIR /app +WORKDIR /home/${USERNAME}/app # 3. Copy the requirements and src files COPY requirements.txt . @@ -37,10 +39,7 @@ COPY Docker/scripts/run.sh . COPY Docker/opt/ /opt/ # 4. A: Install system level dependencies -# RUN apt update -# RUN apt install -RUN apt-get update -RUN apt-get install -y \ +RUN apt-get update && apt-get install -y \ --no-install-recommends \ --no-install-suggests \ clang \ @@ -51,7 +50,7 @@ RUN apt-get install -y \ gopls # 4. B: Install SDKMAN -USER abaddon +USER ${USERNAME} RUN curl -fsSL https://get.sdkman.io | bash USER root @@ -72,6 +71,8 @@ RUN node --version RUN npm --version RUN java --version +RUN chown ${USERNAME}:${USERNAME} -R /home/${USERNAME} + # 5. Cleanup RUN apt-get autoremove --purge RUN apt-get autoclean @@ -79,8 +80,8 @@ RUN apt-get autoclean RUN rm -rf /var/lib/apt/lists/* RUN rm -rf /tmp/* RUN rm -rf "${NVM_DIR}/.cache" -RUN rm /app/requirements.txt +RUN rm /home/${USERNAME}/app/requirements.txt # 6. Expose Port and define the command used to run the app EXPOSE 9999 -CMD ["/app/run.sh"] +CMD ["/home/itdominator/app/run.sh"] diff --git a/Docker/build.sh b/Docker/build.sh index 8db7861..1681b9a 100755 --- a/Docker/build.sh +++ b/Docker/build.sh @@ -12,6 +12,9 @@ function main() { cd "${SCRIPTPATH}/.." echo "Working Dir: " $(pwd) - podman build -t "${CONTAINER}" -f Docker/Dockerfile . + podman build \ + --build-arg USERNAME="${USER}" \ + -t "${CONTAINER}" \ + -f Docker/Dockerfile . } main $@; diff --git a/Docker/scripts/CONFIG.sh b/Docker/scripts/CONFIG.sh index 9ccc18c..de50de5 100644 --- a/Docker/scripts/CONFIG.sh +++ b/Docker/scripts/CONFIG.sh @@ -5,4 +5,6 @@ # set -o errunset ## To exit if a variable is referenced but not set -CONTAINER="newton-lsp" \ No newline at end of file +_HOME="${HOME}" +CONTAINER="newton-lsp" +CONTAINER_HOME="${_HOME}" \ No newline at end of file diff --git a/Docker/scripts/start.sh b/Docker/scripts/start.sh index c980ca0..9d5ac4e 100755 --- a/Docker/scripts/start.sh +++ b/Docker/scripts/start.sh @@ -19,16 +19,19 @@ function main() { fi CODE_HOST="${HOME}/Coding" - CODE_CONTAINER="${HOME}/Coding" + CODE_CONTAINER="${CONTAINER_HOME}/Coding" CONFIG_HOST="${HOME}/.config/lsps" - CONFIG_CONTAINER="${HOME}/.config/lsps" + CONFIG_CONTAINER="${CONTAINER_HOME}/.config/lsps" + _UID=$(id -u) + _GID=$(id -g) + # --user "${_UID}:${_GID}" \ # podman run -d -m 4G \ podman run -m 4G \ -p 9999:9999 \ - -e HOME="${HOME}" \ - -e MAVEN_OPTS="-Duser.home=${HOME}" \ - -e JAVA_TOOL_OPTIONS="-Duser.home=${HOME}" \ + -e HOME="${CONTAINER_HOME}" \ + -e MAVEN_OPTS="-Duser.home=${CONTAINER_HOME}" \ + -e JAVA_TOOL_OPTIONS="-Duser.home=${CONTAINER_HOME}" \ -e JDTLS_CONFIG_PATH="${CONFIG_CONTAINER}/jdtls" \ -e JDTLS_DATA_PATH="${JDTLS_CONFIG_PATH}/data" \ -v "${CODE_HOST}":"${CODE_CONTAINER}" \