From 623e1f1ce1c64e906ca1ec96b1bb9aed59df1c56 Mon Sep 17 00:00:00 2001 From: Huabing Zhao Date: Wed, 4 Dec 2024 07:04:41 +0000 Subject: [PATCH] patch example Signed-off-by: Huabing Zhao --- bazel/envoy_examples.patch | 295 +++++++++++++++++++++++++++++++++++++ bazel/repositories.bzl | 5 +- 2 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 bazel/envoy_examples.patch diff --git a/bazel/envoy_examples.patch b/bazel/envoy_examples.patch new file mode 100644 index 0000000000000..f610fa37f5e52 --- /dev/null +++ b/bazel/envoy_examples.patch @@ -0,0 +1,295 @@ +diff --git a/single-page-app/verify.sh b/single-page-app/verify.sh +index 6b1547f..582917d 100755 +--- a/single-page-app/verify.sh ++++ b/single-page-app/verify.sh +@@ -10,11 +10,13 @@ export PORT_PROXY="${SPA_PORT_PROXY:-11900}" + export PORT_MYHUB="${SPA_PORT_MYHUB:-11902}" + export MANUAL=true + ++ + BACKUP_FILES=( +- "envoy.yml" ++ "envoy.yml" + ) + +-finally() { ++ ++finally () { + rm -rf .local.ci + for file in "${BACKUP_FILES[@]}"; do + move_if_exists "${file}.bak" "${file}" +@@ -30,8 +32,9 @@ export -f finally + # eg selenium or similar. + # Everything else should be tested. + ++ + EXPECTED_USER_JQ=$( +- cat <<'EOF' ++cat << 'EOF' + {"avatar_url": "http://localhost:\($port)/images/users/envoy.svg", + "followers": 3, + "following": 2, +@@ -44,11 +47,10 @@ EXPECTED_USER="$( + yq -c \ + --arg port "$PORT_MYHUB" \ + "$EXPECTED_USER_JQ" \ +- ' | +- grep -oP '/assets/[^"]+' | +- sed 's/\/assets\///;s/".*//' ++get_js () { ++ _curl -k "https://localhost:${PORT_PROXY}" \ ++ | grep "assets/index" \ ++ | grep -oP '' \ ++ | grep -oP '/assets/[^"]+' \ ++ | sed 's/\/assets\///;s/".*//' + } + + run_log "Adjust environment for CI" +@@ -238,8 +234,8 @@ export UI_PATH=./.local.ci/ui + for file in "${BACKUP_FILES[@]}"; do + cp -a "${file}" "${file}.bak" + done +-echo "VITE_APP_API_URL=https://localhost:${PORT_PROXY}" >ui/.env.production.local +-echo "VITE_APP_API_URL=http://localhost:${PORT_DEV_PROXY}" >ui/.env.development.local ++echo "VITE_APP_API_URL=https://localhost:${PORT_PROXY}" > ui/.env.production.local ++echo "VITE_APP_API_URL=http://localhost:${PORT_DEV_PROXY}" > ui/.env.development.local + sed -i "s/localhost:7000/localhost:${PORT_MYHUB}/g" envoy.yml + export UID + +@@ -248,7 +244,7 @@ cp -a secrets/ .local.ci/ + export SECRETS_PATH=./.local.ci/secrets/ + HMAC_SECRET=$(echo "MY_HMAC_SECRET" | mkpasswd -s) + export HMAC_SECRET +-envsubst .local.ci/secrets/hmac-secret.yml ++envsubst < hmac-secret.tmpl.yml > .local.ci/secrets/hmac-secret.yml + + run_log "Start servers" + bring_up_example +@@ -273,7 +269,7 @@ docker compose up --build -d envoy + docker compose run --rm ui build.sh + + run_log "Check the created routes" +-jq '.resources[0].filter_chains[0].filters[0].typed_config.route_config.virtual_hosts[0].routes' <.local.ci/production/xds/lds.yml ++jq '.resources[0].filter_chains[0].filters[0].typed_config.route_config.virtual_hosts[0].routes' < .local.ci/production/xds/lds.yml + + test_auth https "${PORT_PROXY}" + +@@ -301,7 +297,7 @@ responds_with \ + + run_log "Update Envoy's configuration to use Github" + export TOKEN_SECRET=ZZZ +-envsubst .local.ci/secrets/github-token-secret.yml ++envsubst < token-secret.tmpl.yml > .local.ci/secrets/github-token-secret.yml + GITHUB_PROVIDED_CLIENT_ID=XXX + cp -a envoy.yml .local.ci/ + sed -i "s@cluster:\ hub@cluster:\ github@g" .local.ci/envoy.yml +@@ -310,10 +306,10 @@ sed -i "s@authorization_endpoint:\ http://localhost:${PORT_MYHUB}/authorize@auth + sed -i "s@uri:\ http://myhub:${PORT_MYHUB}/authenticate@uri:\ https://github.com/login/oauth/access_token@g" .local.ci/envoy.yml + sed -i "s@path:\ /etc/envoy/secrets/myhub-token-secret.yml@path:\ /etc/envoy/secrets/github-token-secret.yml@g" .local.ci/envoy.yml + sed -i "s@host_rewrite_literal:\ api.myhub@host_rewrite_literal:\ api.github.com@g" .local.ci/envoy.yml +-cat _github-clusters.yml >>.local.ci/envoy.yml ++cat _github-clusters.yml >> .local.ci/envoy.yml + + run_log "Update the app configuration to use Github" +-echo "VITE_APP_AUTH_PROVIDER=github" >.local.ci/ui/.env.local ++echo "VITE_APP_AUTH_PROVIDER=github" > .local.ci/ui/.env.local + + run_log "Rebuild the app and restart Envoy (Github)" + export ENVOY_CONFIG=.local.ci/envoy.yml +@@ -330,16 +326,16 @@ run_log "Inititiate dev login (Github)" + responds_with_header \ + "HTTP/1.1 302 Found" \ + "http://localhost:${PORT_DEV_PROXY}/login" +-if [[ "$STATE_BASE64URL_ENCODE" == "true" ]]; then ++if [[ "$SUPPORT_NONCE" == "true" ]]; then + responds_with_header \ +- "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=${BASE64URL_PREFIX}" \ ++ "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttp%253A%252F%252Flocalhost%253A${PORT_DEV_PROXY}%252Flogin%26nonce%3D" \ + "http://localhost:${PORT_DEV_PROXY}/login" + responds_with_header \ + "set-cookie: OauthNonce=" \ + "http://localhost:${PORT_DEV_PROXY}/login" + else + responds_with_header \ +- "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttp%253A%252F%252Flocalhost%253A${PORT_DEV_PROXY}%252Flogin%26nonce%3D" \ ++ "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=http%3A%2F%2Flocalhost%3A${PORT_DEV_PROXY}%2Flogin" \ + "http://localhost:${PORT_DEV_PROXY}/login" + fi + +@@ -348,9 +344,9 @@ responds_with \ + "Envoy single page app example" \ + "https://localhost:${PORT_PROXY}" \ + -k +-if [[ "$STATE_BASE64URL_ENCODE" == "true" ]]; then ++if [[ "$SUPPORT_NONCE" == "true" ]]; then + responds_with_header \ +- "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=${BASE64URL_PREFIX}" \ ++ "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttps%253A%252F%252Flocalhost%253A${PORT_PROXY}%252Flogin%26nonce%3D" \ + "https://localhost:${PORT_PROXY}/login" \ + -k + responds_with_header \ +@@ -359,7 +355,7 @@ if [[ "$STATE_BASE64URL_ENCODE" == "true" ]]; then + -k + else + responds_with_header \ +- "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=url%3Dhttps%253A%252F%252Flocalhost%253A${PORT_PROXY}%252Flogin%26nonce%3D" \ ++ "location: https://github.com/login/oauth/authorize?client_id=XXX&redirect_uri=https%3A%2F%2Flocalhost%3A${PORT_PROXY}%2Fauthorize&response_type=code&scope=user%3Aemail&state=https%3A%2F%2Flocalhost%3A${PORT_PROXY}%2Flogin" \ + "https://localhost:${PORT_PROXY}/login" \ + -k + fi +diff --git a/single-page-app/xds/lds.yml b/single-page-app/xds/lds.yml +deleted file mode 100644 +index e69de29..0000000 diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index a7ad9f1c4edad..a8a9b639444a4 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -215,7 +215,10 @@ def envoy_dependencies(skip_targets = []): external_http_archive( "com_github_google_flatbuffers", patch_args = ["-p1"], - patches = ["@envoy//bazel:flatbuffers.patch"], + patches = [ + "@envoy//bazel:flatbuffers.patch", + "@envoy//bazel:envoy_examples.patch", + ], ) external_http_archive("bazel_features") external_http_archive("bazel_toolchains")