-
Notifications
You must be signed in to change notification settings - Fork 12
build: proxy settings for build and devcontainer #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nbmaiti
wants to merge
1
commit into
main
Choose a base branch
from
proxy_setting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−18
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| FROM mcr.microsoft.com/devcontainers/go:1.25-bookworm | ||
|
|
||
| # 1. Define the arguments to accept them from devcontainer.json | ||
| ARG HTTP_PROXY | ||
| ARG HTTPS_PROXY | ||
| ARG NO_PROXY | ||
| ARG http_proxy | ||
| ARG https_proxy | ||
| ARG no_proxy | ||
|
|
||
| # 2. Export them as environment variables | ||
| ENV HTTP_PROXY=$HTTP_PROXY | ||
| ENV HTTPS_PROXY=$HTTPS_PROXY | ||
| ENV NO_PROXY=$NO_PROXY | ||
| ENV http_proxy=$http_proxy | ||
| ENV https_proxy=$https_proxy | ||
| ENV no_proxy=$no_proxy | ||
|
|
||
| # 3. Ensure sudo keeps these variables (crucial for features that use sudo) | ||
| RUN echo 'Defaults env_keep += "HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy"' >> /etc/sudoers | ||
|
|
||
| # 4. Prime the apt cache with proxy settings active | ||
| RUN apt-get update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,55 @@ | ||
| // For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
| // README at: https://github.com/devcontainers/templates/tree/main/src/go | ||
| { | ||
| "name": "Go", | ||
| // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
| "image": "mcr.microsoft.com/devcontainers/go:dev-1-bullseye", | ||
| // Features to add to the dev container. More info: https://containers.dev/features. | ||
| // "features": {}, | ||
| // Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
| "forwardPorts": [ | ||
| 8181 | ||
| ], | ||
| // Use 'postCreateCommand' to run commands after the container is created. | ||
| "postCreateCommand": "go install github.com/air-verse/air@v1.62.0" | ||
| // Configure tool-specific properties. | ||
| // "customizations": {}, | ||
| // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
| // "remoteUser": "root" | ||
| "name": "Console Go", | ||
| // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
| "build": { | ||
| "dockerfile": "Dockerfile", | ||
| "context": "..", | ||
| "args": { | ||
| "HTTP_PROXY": "${localEnv:HTTP_PROXY:}", | ||
| "HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}", | ||
| "NO_PROXY": "${localEnv:NO_PROXY:}", | ||
| "http_proxy": "${localEnv:http_proxy:}", | ||
| "https_proxy": "${localEnv:https_proxy:}", | ||
| "no_proxy": "${localEnv:no_proxy:}" | ||
| } | ||
| }, | ||
| // Features to add to the dev container. More info: https://containers.dev/features. | ||
| // "features": {}, | ||
| // Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
| "forwardPorts": [ | ||
| 8181 | ||
| ], | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/docker-in-docker:2": { | ||
| "version": "latest", | ||
| "moby": true | ||
| }, | ||
| "ghcr.io/devcontainers/features/node:1": { | ||
| "version": "lts" | ||
| }, | ||
| "ghcr.io/devcontainers/features/common-utils:2": { | ||
| "installZsh": true, | ||
| "configureZshAsDefaultShell": true, | ||
| "installOhMyZsh": true, | ||
| "upgradePackages": true | ||
| } | ||
| }, | ||
| "containerEnv": { | ||
| "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}", | ||
| "HTTP_PROXY": "${localEnv:HTTP_PROXY:}", | ||
| "HTTPS_PROXY": "${localEnv:HTTPS_PROXY:}", | ||
| "NO_PROXY": "${localEnv:NO_PROXY:}", | ||
| "http_proxy": "${localEnv:http_proxy:}", | ||
| "https_proxy": "${localEnv:https_proxy:}", | ||
| "no_proxy": "${localEnv:no_proxy:}" | ||
| }, | ||
| // Use 'postCreateCommand' to run commands after the container is created. | ||
| "postCreateCommand": "sed -i 's/\\r$//' .devcontainer/post-create.sh && /bin/bash .devcontainer/post-create.sh" | ||
|
|
||
| // Configure tool-specific properties. | ||
| // "customizations": {}, | ||
| // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. | ||
| // "remoteUser": "root" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Unset empty proxy variables | ||
| for var in HTTP_PROXY HTTPS_PROXY NO_PROXY http_proxy https_proxy no_proxy; do | ||
| eval v="\${$var}" | ||
| if [ -z "$v" ]; then unset $var; fi | ||
| done | ||
|
|
||
| # Strip all trailing '/' or '\\' from proxy URLs for apt config | ||
| strip_trailing_slash() { | ||
| local url="$1" | ||
| # Remove all trailing / or \ | ||
| url="${url%%*(/|\\)}" | ||
| # Fallback for Bash < 4.0 (no extglob): use sed | ||
| echo "$url" | sed 's%[\\/]*$%%' | ||
| } | ||
|
|
||
| if [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ] || [ -n "$HTTPS_PROXY" ] || [ -n "$https_proxy" ]; then | ||
| echo "Configuring apt to use proxy..." | ||
| sudo mkdir -p /etc/apt/apt.conf.d | ||
| # Remove all trailing / or \\ from proxy URLs | ||
| apt_http_proxy="$(strip_trailing_slash "${HTTP_PROXY:-${http_proxy:-}}")" | ||
| apt_https_proxy="$(strip_trailing_slash "${HTTPS_PROXY:-${https_proxy:-}}")" | ||
| sudo tee /etc/apt/apt.conf.d/99proxy > /dev/null <<EOF | ||
| Acquire::http::Proxy "$apt_http_proxy"; | ||
| Acquire::https::Proxy "$apt_https_proxy"; | ||
| EOF | ||
| fi | ||
|
|
||
| if [ -n "$HTTP_PROXY" ] || [ -n "$http_proxy" ] || [ -n "$HTTPS_PROXY" ] || [ -n "$https_proxy" ]; then | ||
| echo "Configuring Docker daemon proxy..." | ||
| docker_http_proxy="${HTTP_PROXY:-${http_proxy:-}}" | ||
| docker_https_proxy="${HTTPS_PROXY:-${https_proxy:-}}" | ||
| docker_no_proxy="${NO_PROXY:-${no_proxy:-}}" | ||
| sudo mkdir -p /etc/docker | ||
| sudo tee /etc/docker/daemon.json > /dev/null <<EOF | ||
| { | ||
| "proxies": { | ||
| "httpProxy": "${docker_http_proxy}", | ||
| "httpsProxy": "${docker_https_proxy}", | ||
| "noProxy": "${docker_no_proxy}" | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| if command -v systemctl >/dev/null 2>&1 && systemctl is-active --quiet docker; then | ||
| sudo systemctl restart docker | ||
| elif command -v service >/dev/null 2>&1 && service docker status >/dev/null 2>&1; then | ||
| sudo service docker restart | ||
| elif [ -x /usr/local/share/docker-init.sh ]; then | ||
| sudo pkill dockerd || true | ||
| sudo /usr/local/share/docker-init.sh >/tmp/docker-init.log 2>&1 || sudo /usr/local/share/docker-init.sh | ||
| fi | ||
| fi | ||
|
|
||
| echo "Installing runtime dependencies..." | ||
| sudo apt-get update | ||
| sudo apt-get install -y dbus dbus-x11 xdg-utils libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb | ||
|
|
||
| go install github.com/air-verse/air@latest | ||
| go install github.com/go-delve/delve/cmd/dlv@latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.