Skip to content

Commit

Permalink
Added proxy into docker-in-docker config (#56)
Browse files Browse the repository at this point in the history
* Added proxy into docker-in-docker config

* Fixed review findings

* Remove unnecessary echo
  • Loading branch information
kse3hi authored Nov 2, 2023
1 parent fde5c80 commit 1fb7a33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .devcontainer/scripts/configure-proxies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if [ "${USE_PROXIES}" = "true" ]; then
git config --global https.proxy ${HTTPS_PROXY}
fi

# Apply wget proxy
echo "# Proxy settings" >> /etc/wgetrc
echo "http_proxy=${HTTP_PROXY}" >> /etc/wgetrc
echo "https_proxy=${HTTPS_PROXY}" >> /etc/wgetrc
Expand All @@ -95,6 +96,20 @@ if [ "${USE_PROXIES}" = "true" ]; then
# enable root user to "apt-get" via proxy
echo "Acquire::http::proxy \"${HTTP_PROXY}\";" >> /etc/apt/apt.conf
echo "Acquire::https::proxy \"${HTTPS_PROXY}\";" >> /etc/apt/apt.conf

# apply proxy for docker config
DOCKER_CONFIG_INITIAL_CONTENT="{}"
DOCKER_CONFIG_FOLDER=/home/${USERNAME}/.docker
mkdir -p $DOCKER_CONFIG_FOLDER
DOCKER_CONFIG_FILE=${DOCKER_CONFIG_FOLDER}/config.json
if [ -s "${DOCKER_CONFIG_FILE}" ]; then
echo "Existing docker config file found!"
DOCKER_CONFIG_INITIAL_CONTENT=$(cat "${DOCKER_CONFIG_FILE}")
fi

DOCKER_PROXY_JSON="{\"default\": {\"httpProxy\": \"$HTTP_PROXY\", \"httpsProxy\": \"$HTTP_PROXY\", \"noProxy\": \"$NO_PROXY\"}}"

echo $DOCKER_CONFIG_INITIAL_CONTENT | jq --argjson proxy "$DOCKER_PROXY_JSON" '. + {proxies: $proxy}' >| $DOCKER_CONFIG_FILE
fi

exit 0
3 changes: 2 additions & 1 deletion Dockerfiles/base/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ RUN groupadd --gid $USER_GID $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

WORKDIR /home/vscode
WORKDIR /home/${USERNAME}
# Will be available in container under home directory
COPY .devcontainer/scripts/configure-proxies.sh .
WORKDIR /tmp/setup
COPY ./common .
Expand Down

0 comments on commit 1fb7a33

Please sign in to comment.