-
Notifications
You must be signed in to change notification settings - Fork 6
Make devcontainer work in WSL and proxy environments #52
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
base: main
Are you sure you want to change the base?
Changes from all commits
82c1af3
c287345
63979a7
2938614
c81e8ed
cbbc584
7e50710
8aae837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,82 @@ | ||
| #!/usr/bin/env bash | ||
| set -euxo pipefail | ||
|
|
||
| if ! docker buildx inspect multiarch &>/dev/null; then | ||
| docker buildx create --name multiarch --driver docker-container --use | ||
| else | ||
| docker buildx use multiarch | ||
| # Function to check if builder has correct proxy configuration | ||
| check_proxy_config() { | ||
| local builder_info | ||
| builder_info=$(docker buildx inspect multiarch 2>/dev/null || echo "") | ||
|
|
||
| # Check if HTTP_PROXY is set in environment but not in builder | ||
| if [ -n "${HTTP_PROXY:-}" ]; then | ||
| if ! echo "$builder_info" | grep -q "HTTP_PROXY=${HTTP_PROXY}"; then | ||
| return 1 | ||
| fi | ||
| fi | ||
|
|
||
| # Check if HTTPS_PROXY is set in environment but not in builder | ||
| if [ -n "${HTTPS_PROXY:-}" ]; then | ||
| if ! echo "$builder_info" | grep -q "HTTPS_PROXY=${HTTPS_PROXY}"; then | ||
| return 1 | ||
| fi | ||
| fi | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| # Check if builder exists and has correct proxy configuration | ||
| if docker buildx inspect multiarch &>/dev/null; then | ||
| if ! check_proxy_config; then | ||
| echo "Builder 'multiarch' exists but has incorrect proxy configuration. Recreating..." | ||
| docker buildx rm multiarch | ||
| else | ||
| echo "Builder 'multiarch' already exists with correct configuration." | ||
| docker buildx use multiarch | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| # Create BuildKit configuration file with proxy settings | ||
| BUILDKIT_CONFIG="" | ||
| if [ -n "${HTTP_PROXY:-}" ] || [ -n "${HTTPS_PROXY:-}" ]; then | ||
| BUILDKIT_CONFIG="${HOME}/.config/buildkit/buildkitd.toml" | ||
| mkdir -p "$(dirname "${BUILDKIT_CONFIG}")" | ||
| cat > "${BUILDKIT_CONFIG}" <<EOF | ||
| [worker.oci] | ||
| enabled = true | ||
|
|
||
| [worker.containerd] | ||
| enabled = false | ||
|
|
||
| # Default build arg values for all builds (includes proxy settings) | ||
| [worker.oci.proxy] | ||
| http = "${HTTP_PROXY:-}" | ||
| https = "${HTTPS_PROXY:-}" | ||
| noProxy = "${NO_PROXY:-}" | ||
| EOF | ||
| fi | ||
|
|
||
| # Build driver options for proxy configuration | ||
| DRIVER_OPTS=() | ||
|
|
||
| if [ -n "${HTTP_PROXY:-}" ]; then | ||
| DRIVER_OPTS+=("--driver-opt" "env.HTTP_PROXY=${HTTP_PROXY}") | ||
| fi | ||
|
|
||
| if [ -n "${HTTPS_PROXY:-}" ]; then | ||
| DRIVER_OPTS+=("--driver-opt" "env.HTTPS_PROXY=${HTTPS_PROXY}") | ||
| fi | ||
|
|
||
| if [ -n "${NO_PROXY:-}" ]; then | ||
| DRIVER_OPTS+=("--driver-opt" "env.NO_PROXY=${NO_PROXY}") | ||
| fi | ||
|
|
||
| # Add network mode to use host DNS resolution | ||
| DRIVER_OPTS+=("--driver-opt" "network=host") | ||
|
|
||
| # Add BuildKit config file if proxy is configured | ||
| if [ -n "${BUILDKIT_CONFIG}" ]; then | ||
| DRIVER_OPTS+=("--config" "${BUILDKIT_CONFIG}") | ||
| fi | ||
|
|
||
| # Create builder with driver options | ||
| docker buildx create --name multiarch --driver docker-container "${DRIVER_OPTS[@]}" --use |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,10 @@ apt-get install -y python${python_version} python3-pip python3-venv | |
| # devcontainer feature "python" (cf. https://github.com/devcontainers/features/tree/main/src/python ) | ||
| apt-get install -y flake8 python3-autopep8 black python3-yapf mypy pydocstyle pycodestyle bandit pipenv virtualenv python3-pytest pylint | ||
|
|
||
| # OpenJDK JRE and CA certificates, via APT | ||
| # Required for Bazel to work with corporate proxy/CA certificates | ||
| apt-get install -y --no-install-recommends ca-certificates-java openjdk-${openjdk_version}-jre-headless | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifying the Java version here is IMHO ok, because there are different versions as apt packages available for the same Ubuntu release. |
||
|
|
||
| # Bazelisk, directly from GitHub | ||
| # Using the existing devcontainer feature is not optimal: | ||
| # - it does not check the SHA256 checksum of the downloaded file | ||
|
|
@@ -63,6 +67,10 @@ mkdir -p /etc/bash_completion.d | |
| mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash | ||
| sh -c "echo 'export USE_BAZEL_VERSION=${bazel_version}' >> /etc/profile.d/bazel.sh" | ||
|
|
||
| # Configure Bazel to use system trust store for SSL/TLS connections | ||
| # This is required for corporate environments with custom CA certificates | ||
| echo 'startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit' >> /etc/bazel.bazelrc | ||
|
|
||
| # Buildifier, directly from GitHub (apparently no APT repository available) | ||
| # The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file. | ||
| BUILDIFIER_VARIANT="amd64" | ||
|
|
@@ -105,6 +113,9 @@ apt-get install -y --no-install-recommends --fix-broken qemu-system-arm="${qemu_ | |
| # sshpass | ||
| apt-get install -y sshpass="${sshpass_version}*" | ||
|
|
||
| # gdb (GNU Debugger) | ||
| apt-get install -y gdb="${gdb_version}*" | ||
|
Comment on lines
+116
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @opajonk Do we really have to specify the tool version, if it just installed via We already have a Ubuntu release set, which defines the versions of these tools. And thus defining the versions for each tool feels redundant. |
||
|
|
||
| # Cleanup | ||
| # REMOVE CONTAINER BUILD DEPENDENCIES | ||
| apt-get remove --purge -y apt-transport-https | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still does not work. Execution is now successful, but variables are still present in a new shell:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The
postStartCommandruns in its own shell und unsets the environment variables only there.The only solution I would have at the moment, would be to append unset commands to
.bashrcin thepostStartCommand. The.bashrcis then sourced by every new bash shell and every time unsets the environment variables. But it's not a nice solution imho. Would appreciate better proposals.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can use
/etc/profile.d/for this. Here is an example where I removed using it: https://github.com/eclipse-score/devcontainer/pull/51/files#diff-e418ce180663a5c3fc806f1c352a9d737097e60cecaa9cd1724c8236a955a335R64