Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ To download the Extensible Service Proxy source code, clone the ESP repository:
* [script](/script): Scripts used for build, test, and continuous integration.
* [test](/test): Applications and client code used for end-to-end testing.
* [tools](/tools): Assorted tooling.
* [start_esp](/start_esp): A Python start-up script for the ESP proxy. The script includes a generic nginx configuration template and fetching logic to retrieve service configuration from Google Service Management service.



## ESP Tutorial ##
Expand Down
8 changes: 0 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#
# A Bazel (http://bazel.io) workspace for the Google Cloud Endpoints runtime.

ESP_TOOL = "30fbd45c24a58caec5a1082f8073dcaeb313bd45"

git_repository(
name = "nginx",
commit = "18e870fcf52981cd0804eef269f2bb08182f0e3f", # v1.13.4
Expand Down Expand Up @@ -117,12 +115,6 @@ bind(
actual = "@gflags_git//:gflags",
)

git_repository(
name = "tools",
commit = ESP_TOOL,
remote = "https://github.com/cloudendpoints/endpoints-tools",
)

#
# Python rules
#
Expand Down
52 changes: 5 additions & 47 deletions src/nginx/main/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -218,59 +218,17 @@ pkg_tar(
# The first occurrence of the duplicate file will be picked. In other
# words, /etc/nginx/nginx.conf from ":nginx-conf-override" will
# override that from "@nginx_pkgoss//:debian_overlay".
":start_esp_tar",
"@tools//start_esp:nginx-conf-template",
"@tools//start_esp:server-conf-template",
"@tools//start_esp:nginx-initd-override",
"//start_esp:nginx-conf-template",
"//start_esp:server-conf-template",
"//start_esp:nginx-initd-override",
"@nginx_pkgoss//:debian_overlay",
"@tools//start_esp:esp-bin",
"//start_esp:esp-bin",
":nginx-bin",
":esp-copyright",
"@tools//start_esp:trusted-ca-certificates",
"//start_esp:trusted-ca-certificates",
],
)

# Due to an issue with external repository and PEX rules, we need to move these files here

genrule(
name = "import_start_esp",
srcs = ["@tools//start_esp:start_esp.py"],
outs = ["start_esp.py"],
cmd = "cat $(location @tools//start_esp:start_esp.py) > $@",
)

genrule(
name = "import_fetch_service_config",
srcs = ["@tools//start_esp:fetch_service_config.py"],
outs = ["fetch_service_config.py"],
cmd = "cat $(location @tools//start_esp:fetch_service_config.py) > $@",
)

pex_binary(
name = "start_esp",
srcs = [
":fetch_service_config.py",
":start_esp.py",
],
main = ":start_esp.py",
reqs = [
"certifi",
"mako>=1.0.4",
"oauth2client>=3.0.0",
"pyasn1>=0.1.9",
"pyasn1-modules>=0.0.8",
"urllib3>=1.16",
],
)

pkg_tar(
name = "start_esp_tar",
files = [":start_esp"],
mode = "0755",
package_dir = "/usr/sbin",
strip_prefix = ".",
)

pkg_deb(
name = "endpoints-server-proxy",
architecture = "amd64",
Expand Down
101 changes: 101 additions & 0 deletions start_esp/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright (C) Extensible Service Proxy Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
###############################################################################
#

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar", "pkg_deb")
load("@io_bazel_rules_pex//pex:pex_rules.bzl", "pex_binary")

package(default_visibility = ["//visibility:public"])

pkg_tar(
name = "esp-bin",
files = [
":debug_nginx.sh",
":fetch_service_config.sh",
":nginx-debug",
":start_esp",
],
mode = "0755",
package_dir = "/usr/sbin",
strip_prefix = ".",
)

pex_binary(
name = "start_esp",
srcs = [
"fetch_service_config.py",
"start_esp.py",
],
main = "start_esp.py",
reqs = [
"certifi",
"mako>=1.0.4",
"oauth2client>=3.0.0",
"pyasn1>=0.1.9",
"pyasn1-modules>=0.0.8",
"urllib3>=1.16",
],
)

pkg_tar(
name = "nginx-conf-template",
files = [
":nginx-auto.conf.template",
],
mode = "0644",
package_dir = "/etc/nginx",
strip_prefix = ".",
)

pkg_tar(
name = "server-conf-template",
files = [
":server-auto.conf.template",
":server_config.pb.txt",
],
mode = "0644",
package_dir = "/etc/nginx",
strip_prefix = ".",
)

pkg_tar(
name = "trusted-ca-certificates",
files = [
":trusted-ca-certificates.crt",
],
mode = "0644",
package_dir = "/etc/nginx",
strip_prefix = ".",
)

pkg_tar(
name = "nginx-initd-override",
files = [
":nginx-init.d/nginx",
],
mode = "0755",
package_dir = "/etc/init.d",
)
78 changes: 78 additions & 0 deletions start_esp/debug_nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
#
# Copyright (C) Extensible Service Proxy Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################
#
# This script assumes following file locations:
# /usr/sbin/nginx for nginx binary
# /etc/nginx/nginx.conf for nginx config
#
# Usage: /usr/sbin/debug_nginx.sh [ start | stop ]
#
# start: use debug Nginx binary and turn on debug trace
# stop: use release Nginx binary and turn off debug trace.
#

function start_debug() {
[[ -e /etc/nginx/nginx.conf.original ]] || cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.original
[[ -e /usr/sbin/nginx.original ]] || cp /usr/sbin/nginx /usr/sbin/nginx.original

echo "error_log /var/log/nginx/error.log debug;" > /etc/nginx/nginx.conf-debug
echo "worker_rlimit_core 512m;" >> /etc/nginx/nginx.conf-debug
echo "working_directory /tmp;" >> /etc/nginx/nginx.conf-debug
cat /etc/nginx/nginx.conf.original >> /etc/nginx/nginx.conf-debug

cp /etc/nginx/nginx.conf-debug /etc/nginx/nginx.conf
cp /usr/sbin/nginx-debug /usr/sbin/nginx

ulimit -c unlimited

# Sending USR2 to Nginx to reload the binary
kill -USR2 "$(cat /var/run/nginx.pid)"
}

function stop_debug() {
[[ -e /etc/nginx/nginx.conf.original ]] && cp /etc/nginx/nginx.conf.original /etc/nginx/nginx.conf
[[ -e /usr/sbin/nginx.original ]] && cp /usr/sbin/nginx.original /usr/sbin/nginx

# Sending USR2 to Nginx to reload the binary
kill -USR2 "$(cat /var/run/nginx.pid)"
}

case $1 in
start)
start_debug
;;
stop)
stop_debug
;;
*)
echo "Usage: $0 {start|stop}"
exit 2
;;
esac


Loading