summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-02-11 08:39:01 -0800
committerJames E. Blair <jeblair@redhat.com>2019-02-11 08:39:01 -0800
commit7b680c18ec3a14aec6e0e879e7075a97f9baefcb (patch)
treefd30b79e6c0927c220e2bf5a98e13c2655f99c3a
parent12e829169865c17fd24c21a188339a9943ad8bdc (diff)
Use an env var for the API url
-rw-r--r--Dockerfile1
-rw-r--r--vhost.conf2
-rw-r--r--zuul-preview/main.cc26
3 files changed, 19 insertions, 10 deletions
diff --git a/Dockerfile b/Dockerfile
index e8b60e6..42fb583 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -40,4 +40,5 @@ COPY --from=builder /usr/local /usr/local
40 40
41EXPOSE 80 41EXPOSE 80
42ENTRYPOINT ["/usr/bin/dumb-init", "--"] 42ENTRYPOINT ["/usr/bin/dumb-init", "--"]
43ENV ZUUL_API_URL=
43CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"] 44CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]
diff --git a/vhost.conf b/vhost.conf
index 10fa6ff..0bdc5c7 100644
--- a/vhost.conf
+++ b/vhost.conf
@@ -7,5 +7,5 @@
7 # LogLevel alert rewrite:trace6 7 # LogLevel alert rewrite:trace6
8 RewriteEngine On 8 RewriteEngine On
9 RewriteMap preview "prg://usr/local/bin/zuul-preview" 9 RewriteMap preview "prg://usr/local/bin/zuul-preview"
10 RewriteRule "^/?(.*)$" "${preview:%{HTTP_HOST}}/$1" [P] 10 RewriteRule "^/?(.*)$" "${preview:%{ENV:ZUUL_API_URL} %{HTTP_HOST}}/$1" [P]
11</VirtualHost> 11</VirtualHost>
diff --git a/zuul-preview/main.cc b/zuul-preview/main.cc
index 22ce31b..7b57f08 100644
--- a/zuul-preview/main.cc
+++ b/zuul-preview/main.cc
@@ -31,12 +31,12 @@
31 31
32using namespace std; 32using namespace std;
33 33
34vector<string> split(const string &in) 34vector<string> split(const string &in, char delim)
35{ 35{
36 istringstream stream(in); 36 istringstream stream(in);
37 vector<string> parts; 37 vector<string> parts;
38 string part; 38 string part;
39 while (getline(stream, part, '.')) { 39 while (getline(stream, part, delim)) {
40 parts.push_back(part); 40 parts.push_back(part);
41 } 41 }
42 return parts; 42 return parts;
@@ -96,9 +96,7 @@ public:
96 96
97int main(int, char**) 97int main(int, char**)
98{ 98{
99 web::http::client::http_client client("https://zuul.opendev.org"); 99 string input;
100
101 string hostname;
102 Cache cache{1024}; 100 Cache cache{1024};
103 101
104 // For each request apache receieves, it sends us the HTTP host name 102 // For each request apache receieves, it sends us the HTTP host name
@@ -107,8 +105,17 @@ int main(int, char**)
107 // (protected by an internal mutex) and expect exactly one line of 105 // (protected by an internal mutex) and expect exactly one line of
108 // output for each. 106 // output for each.
109 // Expected input: 107 // Expected input:
110 // site.926bb0aaddad4bc3853269451e115dcb.openstack.preview.opendev.org 108 // https://zuul.opendev.org site.926bb0aaddad4bc3853269451e115dcb.openstack.preview.opendev.org
111 while (getline(cin, hostname)) { 109 while (getline(cin, input)) {
110
111 // Split the input into api_url, hostname
112 auto parts = split(input, ' ');
113 if (parts.size() != 2) {
114 cout << "Wrong number of args" << endl;
115 continue;
116 }
117 auto api_url = parts[0];
118 auto hostname = parts[1];
112 119
113 // If we have the value in the cache, return it. 120 // If we have the value in the cache, return it.
114 if (auto val = cache.get(hostname)) { 121 if (auto val = cache.get(hostname)) {
@@ -118,9 +125,9 @@ int main(int, char**)
118 125
119 // We use the first three parts of the hostname to look up the 126 // We use the first three parts of the hostname to look up the
120 // build url. 127 // build url.
121 auto parts = split(hostname); 128 parts = split(hostname, '.');
122 if (parts.size() < 3) { 129 if (parts.size() < 3) {
123 cout << "Not enough args" << endl; 130 cout << "Not enough hostname parts" << endl;
124 continue; 131 continue;
125 } 132 }
126 auto artifact = parts[0]; 133 auto artifact = parts[0];
@@ -129,6 +136,7 @@ int main(int, char**)
129 136
130 try { 137 try {
131 // Use the Zuul API to look up the artifact URL. 138 // Use the Zuul API to look up the artifact URL.
139 web::http::client::http_client client(api_url);
132 auto uri = web::uri_builder("/api/tenant/" + tenant + "/build"); 140 auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
133 uri.append_path(buildid); 141 uri.append_path(buildid);
134 auto response = client.request( 142 auto response = client.request(