summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2019-02-10 17:33:27 -0800
committerJames E. Blair <jeblair@redhat.com>2019-02-10 17:33:27 -0800
commit9b9951dff51d4b93b3f8b26ab53b06327bd504df (patch)
tree997a6d5d0f82fe9ee5bb7a1c0b1ce5fb29faa0dc
parent8dc7bfcf16407950cff46f727c77d00dcca3961c (diff)
Run apache
Add an apache vhost config file which uses zuul-preview as a rewritemap. Remove extraneous output from zuul-preview. Add an exception handler around the http code. Remove the mutex (as we are single threaded). Run apache as the docker CMD.
-rw-r--r--Dockerfile10
-rw-r--r--vhost.conf11
-rw-r--r--zuul-preview/main.cc43
3 files changed, 39 insertions, 25 deletions
diff --git a/Dockerfile b/Dockerfile
index dfe4c5b..e8b60e6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -31,9 +31,13 @@ FROM debian:testing
31 31
32COPY --from=builder /output/bindep/run.txt /run.txt 32COPY --from=builder /output/bindep/run.txt /run.txt
33RUN apt-get update \ 33RUN apt-get update \
34 && apt-get install -y dumb-init $(cat /run.txt) \ 34 && apt-get install -y dumb-init apache2 $(cat /run.txt) \
35 && apt-get clean \ 35 && apt-get clean \
36 && rm -rf /var/lib/apt/lists/* /run.txt 36 && rm -rf /var/lib/apt/lists/* /run.txt \
37 && a2enmod rewrite proxy proxy_http
38COPY ./vhost.conf /etc/apache2/sites-available/000-default.conf
37COPY --from=builder /usr/local /usr/local 39COPY --from=builder /usr/local /usr/local
40
41EXPOSE 80
38ENTRYPOINT ["/usr/bin/dumb-init", "--"] 42ENTRYPOINT ["/usr/bin/dumb-init", "--"]
39CMD ["/usr/local/bin/zuul-preview"] 43CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]
diff --git a/vhost.conf b/vhost.conf
new file mode 100644
index 0000000..d1fb671
--- /dev/null
+++ b/vhost.conf
@@ -0,0 +1,11 @@
1<VirtualHost *:80>
2 ServerAdmin webmaster@localhost
3 DocumentRoot /var/www/html
4 ErrorLog /dev/stdout
5 CustomLog /dev/stdout combined
6
7 # LogLevel alert rewrite:trace6
8 RewriteEngine On
9 RewriteMap preview "prg://usr/local/bin/zuul-preview"
10 RewriteRule "^(.*)$" "${preview:%{HTTP_HOST}}$1" [P]
11</VirtualHost>
diff --git a/zuul-preview/main.cc b/zuul-preview/main.cc
index c96ed7a..79e655d 100644
--- a/zuul-preview/main.cc
+++ b/zuul-preview/main.cc
@@ -47,19 +47,15 @@ class Cache {
47 // The maximum size of the cache. 47 // The maximum size of the cache.
48 const uint32_t size; 48 const uint32_t size;
49 49
50 // Mutex protecting the map and list.
51 mutex cache_mutex;
52
53public: 50public:
54 Cache(uint s) 51 Cache(uint s)
55 : queue {}, map {}, size{s}, cache_mutex{} 52 : queue {}, map {}, size{s}
56 { } 53 { }
57 54
58 // Lookup the hostname in the cache and return the URL if present. 55 // Lookup the hostname in the cache and return the URL if present.
59 // If the entry is present, it is moved to the head of the queue. 56 // If the entry is present, it is moved to the head of the queue.
60 optional<const string> get(const string &key) 57 optional<const string> get(const string &key)
61 { 58 {
62 lock_guard<mutex> guard{cache_mutex};
63 auto location = map.find(key); 59 auto location = map.find(key);
64 if (location == map.end()) 60 if (location == map.end())
65 return {}; 61 return {};
@@ -67,7 +63,7 @@ public:
67 auto val = *(location->second); 63 auto val = *(location->second);
68 queue.erase(location->second); 64 queue.erase(location->second);
69 queue.push_front(val); 65 queue.push_front(val);
70 cout << "get push " << val.second << endl; 66 //cout << "get push " << val.second << endl;
71 return val.second; 67 return val.second;
72 } 68 }
73 69
@@ -75,19 +71,18 @@ public:
75 // recently used entry. 71 // recently used entry.
76 void put(const string &key, const string &value) 72 void put(const string &key, const string &value)
77 { 73 {
78 lock_guard<mutex> guard{cache_mutex};
79 auto location = map.find(key); 74 auto location = map.find(key);
80 if (location != map.end()) 75 if (location != map.end())
81 return; 76 return;
82 77
83 if (queue.size() == size) { 78 if (queue.size() == size) {
84 auto last = queue.back(); 79 auto last = queue.back();
85 cout << "put pop " << last.second << endl; 80 //cout << "put pop " << last.second << endl;
86 queue.pop_back(); 81 queue.pop_back();
87 map.erase(last.first); 82 map.erase(last.first);
88 } 83 }
89 84
90 cout << "put push " << value << endl; 85 //cout << "put push " << value << endl;
91 queue.push_front(make_pair(key, value)); 86 queue.push_front(make_pair(key, value));
92 map[key] = queue.begin(); 87 map[key] = queue.begin();
93 } 88 }
@@ -130,19 +125,23 @@ int main(int, char**)
130 */ 125 */
131 126
132 // 75031cad206c4014ad7a3387091d15ab 127 // 75031cad206c4014ad7a3387091d15ab
133 auto uri = web::uri_builder("/api/tenant/" + tenant + "/build"); 128 try {
134 uri.append_path(buildid); 129 auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
135 auto response = client.request( 130 uri.append_path(buildid);
131 auto response = client.request(
136 web::http::methods::GET, uri.to_string()).get(); 132 web::http::methods::GET, uri.to_string()).get();
137 // body is a web::json::value 133 // body is a web::json::value
138 auto body = response.extract_json().get(); 134 // cout << response.status_code() << endl;
139 //cout << response.status_code() << endl; 135 auto body = response.extract_json().get();
140 //cout << body.serialize() << endl; 136 //cout << body.serialize() << endl;
141 137
142 // TODO: use artifact 138 // TODO: use artifact
143 // body["log_url"].as_string() returns a const std::string& 139 // body["log_url"].as_string() returns a const std::string&
144 cout << body["log_url"].as_string() << endl; 140 cout << body["log_url"].as_string() << endl;
145 141
146 cache.put(hostname, body["log_url"].as_string()); 142 cache.put(hostname, body["log_url"].as_string());
143 } catch (...) {
144 cout << "error" << endl;
145 }
147 } 146 }
148} 147}