Skip to content
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

fix: Use lookup instead of resolve to ensure consider /etc/hosts #3720

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions aztec-up/bin/.aztec-run
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ if [[ -z "${SKIP_NET:-}" && "$UNAME" == "Linux" ]]; then
# We're in rootless docker. Probe for the host ip and use that.
ip=$(hostname -I | head | tr -d ' ')
warn "WARNING: Running within rootless docker. Using $ip as host ip. Ensure listening services are listening on this interface."
DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:$ip"
DOCKER_HOST_BINDS="--add-host host.docker.internal:$ip"
else
DOCKER_HOST_BINDS="$DOCKER_HOST_BINDS --add-host host.docker.internal:host-gateway"
DOCKER_HOST_BINDS="--add-host host.docker.internal:host-gateway"
fi
fi

Expand All @@ -70,10 +70,12 @@ done

DOCKER_ENV="-e HOME=$HOME"
for env in ${ENV_VARS_TO_INJECT:-}; do
# First substitute any reference to localhost with our host gateway.
env=${env//localhost/host.docker.internal}
# Inject into container.
DOCKER_ENV+="-e $env:${!env:-} "
if [ -n "${!env:-}" ]; then
# First substitute any reference to localhost with our host gateway.
env=${env//localhost/host.docker.internal}
# Inject into container.
DOCKER_ENV+=" -e $env=${!env:-}"
fi
done

# Volumes to pass to the container.
Expand Down
2 changes: 0 additions & 2 deletions aztec-up/bin/aztec-cli
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env bash
# TODO: Make compile command always be wasm. Or put nargo in container. Or probe.
# TODO: Make unbox fail if trying to unbox outside of the cwd.
set -euo pipefail

export ENV_VARS_TO_INJECT="PXE_URL PRIVATE_KEY DEBUG"
Expand Down
4 changes: 2 additions & 2 deletions aztec-up/bin/aztec-sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
CMD="docker compose"
$CMD &>/dev/null || CMD="docker-compose"

ARGS="-f $HOME/.aztec/bin/docker-compose.yml -p sandbox"
ARGS="-f ./bin/docker-compose.yml -p sandbox"

# Function to be executed when SIGINT is received.
cleanup() {
Expand All @@ -16,6 +16,6 @@ cleanup() {
trap cleanup SIGINT

# Change working dir, so relative volume mounts are in the right place.
cd ~/.aztec
cd $(dirname $0)/..

$CMD $ARGS up --force-recreate --remove-orphans
15 changes: 9 additions & 6 deletions aztec-up/bin/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,33 @@ services:
'
[ -n "$$FORK_URL" ] && ARGS="$$ARGS --fork-url $$FORK_URL";
[ -n "$$FORK_BLOCK_NUMBER" ] && ARGS="$$ARGS --fork-block-number $$FORK_BLOCK_NUMBER";
echo anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent $$ARGS;
anvil -p 8545 --host 0.0.0.0 --chain-id 31337 --silent $$ARGS
echo anvil -p $$ANVIL_PORT --host 0.0.0.0 --chain-id 31337 --silent $$ARGS;
anvil -p $$ANVIL_PORT --host 0.0.0.0 --chain-id 31337 --silent $$ARGS
'
ports:
- "${SANDBOX_ANVIL_PORT:-8545}:8545"
- "${ANVIL_PORT:-8545}:${ANVIL_PORT:-8545}"
environment:
FORK_URL:
FORK_BLOCK_NUMBER:
ANVIL_PORT: ${ANVIL_PORT:-8545}

aztec:
image: "aztecprotocol/aztec-sandbox"
ports:
- "${SANDBOX_AZTEC_NODE_PORT:-8079}:8079"
- "${SANDBOX_PXE_PORT:-8080}:8080"
- "${AZTEC_NODE_PORT:-8079}:${AZTEC_NODE_PORT:-8079}"
- "${PXE_PORT:-8080}:${PXE_PORT:-8080}"
environment:
DEBUG: # Loaded from the user shell if explicitly set
HOST_WORKDIR: "${PWD}" # Loaded from the user shell to show log files absolute path in host
ETHEREUM_HOST: http://ethereum:8545
ETHEREUM_HOST: http://ethereum:${ANVIL_PORT:-8545}
CHAIN_ID: 31337
ARCHIVER_POLLING_INTERVAL_MS: 50
P2P_BLOCK_CHECK_INTERVAL_MS: 50
SEQ_TX_POLLING_INTERVAL_MS: 50
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
AZTEC_NODE_PORT: ${AZTEC_NODE_PORT:-8079}
PXE_PORT: ${PXE_PORT:-8080}
volumes:
- ./log:/usr/src/yarn-project/aztec-sandbox/log:rw
11 changes: 5 additions & 6 deletions yarn-project/aztec-sandbox/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NoirCommit } from '@aztec/noir-compiler/versions';
import { BootstrapNode, getP2PConfigEnvVars } from '@aztec/p2p';
import { GrumpkinScalar, PXEService, createPXERpcServer } from '@aztec/pxe';

import { resolve as dnsResolve } from 'dns';
import { lookup } from 'dns/promises';
import { readFileSync } from 'fs';
import http from 'http';
import { dirname, resolve } from 'path';
Expand All @@ -35,11 +35,10 @@ enum SandboxMode {
* If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat
* localhost as being host.docker.internal.
*/
function getLocalhost() {
return new Promise(resolve =>
dnsResolve('host.docker.internal', err => (err ? resolve('localhost') : resolve('host.docker.internal'))),
);
}
const getLocalhost = () =>
lookup('host.docker.internal')
.then(() => 'host.docker.internal')
.catch(() => 'localhost');

const LOCALHOST = await getLocalhost();
const {
Expand Down
11 changes: 5 additions & 6 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from '@aztec/foundation/url';
import { addNoirCompilerCommanderActions } from '@aztec/noir-compiler/cli';

import { Command, Option } from 'commander';
import { resolve as dnsResolve } from 'dns';
import { lookup } from 'dns/promises';
import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';

Expand All @@ -27,11 +27,10 @@ import {
* If we can successfully resolve 'host.docker.internal', then we are running in a container, and we should treat
* localhost as being host.docker.internal.
*/
function getLocalhost() {
return new Promise(resolve =>
dnsResolve('host.docker.internal', err => (err ? resolve('localhost') : resolve('host.docker.internal'))),
);
}
const getLocalhost = () =>
lookup('host.docker.internal')
.then(() => 'host.docker.internal')
.catch(() => 'localhost');

const LOCALHOST = await getLocalhost();
const { ETHEREUM_HOST = `http://${LOCALHOST}:8545`, PRIVATE_KEY, API_KEY } = process.env;
Expand Down