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.
This commit is contained in:
James E. Blair 2019-02-10 17:33:27 -08:00
parent 8dc7bfcf16
commit 9b9951dff5
3 changed files with 37 additions and 23 deletions

View File

@ -31,9 +31,13 @@ FROM debian:testing
COPY --from=builder /output/bindep/run.txt /run.txt COPY --from=builder /output/bindep/run.txt /run.txt
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y dumb-init $(cat /run.txt) \ && apt-get install -y dumb-init apache2 $(cat /run.txt) \
&& apt-get clean \ && apt-get clean \
&& rm -rf /var/lib/apt/lists/* /run.txt && rm -rf /var/lib/apt/lists/* /run.txt \
&& a2enmod rewrite proxy proxy_http
COPY ./vhost.conf /etc/apache2/sites-available/000-default.conf
COPY --from=builder /usr/local /usr/local COPY --from=builder /usr/local /usr/local
EXPOSE 80
ENTRYPOINT ["/usr/bin/dumb-init", "--"] ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["/usr/local/bin/zuul-preview"] CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]

11
vhost.conf Normal file
View File

@ -0,0 +1,11 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog /dev/stdout
CustomLog /dev/stdout combined
# LogLevel alert rewrite:trace6
RewriteEngine On
RewriteMap preview "prg://usr/local/bin/zuul-preview"
RewriteRule "^(.*)$" "${preview:%{HTTP_HOST}}$1" [P]
</VirtualHost>

View File

@ -47,19 +47,15 @@ class Cache {
// The maximum size of the cache. // The maximum size of the cache.
const uint32_t size; const uint32_t size;
// Mutex protecting the map and list.
mutex cache_mutex;
public: public:
Cache(uint s) Cache(uint s)
: queue {}, map {}, size{s}, cache_mutex{} : queue {}, map {}, size{s}
{ } { }
// Lookup the hostname in the cache and return the URL if present. // Lookup the hostname in the cache and return the URL if present.
// If the entry is present, it is moved to the head of the queue. // If the entry is present, it is moved to the head of the queue.
optional<const string> get(const string &key) optional<const string> get(const string &key)
{ {
lock_guard<mutex> guard{cache_mutex};
auto location = map.find(key); auto location = map.find(key);
if (location == map.end()) if (location == map.end())
return {}; return {};
@ -67,7 +63,7 @@ public:
auto val = *(location->second); auto val = *(location->second);
queue.erase(location->second); queue.erase(location->second);
queue.push_front(val); queue.push_front(val);
cout << "get push " << val.second << endl; //cout << "get push " << val.second << endl;
return val.second; return val.second;
} }
@ -75,19 +71,18 @@ public:
// recently used entry. // recently used entry.
void put(const string &key, const string &value) void put(const string &key, const string &value)
{ {
lock_guard<mutex> guard{cache_mutex};
auto location = map.find(key); auto location = map.find(key);
if (location != map.end()) if (location != map.end())
return; return;
if (queue.size() == size) { if (queue.size() == size) {
auto last = queue.back(); auto last = queue.back();
cout << "put pop " << last.second << endl; //cout << "put pop " << last.second << endl;
queue.pop_back(); queue.pop_back();
map.erase(last.first); map.erase(last.first);
} }
cout << "put push " << value << endl; //cout << "put push " << value << endl;
queue.push_front(make_pair(key, value)); queue.push_front(make_pair(key, value));
map[key] = queue.begin(); map[key] = queue.begin();
} }
@ -130,19 +125,23 @@ int main(int, char**)
*/ */
// 75031cad206c4014ad7a3387091d15ab // 75031cad206c4014ad7a3387091d15ab
auto uri = web::uri_builder("/api/tenant/" + tenant + "/build"); try {
uri.append_path(buildid); auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
auto response = client.request( uri.append_path(buildid);
auto response = client.request(
web::http::methods::GET, uri.to_string()).get(); web::http::methods::GET, uri.to_string()).get();
// body is a web::json::value // body is a web::json::value
auto body = response.extract_json().get(); // cout << response.status_code() << endl;
//cout << response.status_code() << endl; auto body = response.extract_json().get();
//cout << body.serialize() << endl; //cout << body.serialize() << endl;
// TODO: use artifact // TODO: use artifact
// body["log_url"].as_string() returns a const std::string& // body["log_url"].as_string() returns a const std::string&
cout << body["log_url"].as_string() << endl; cout << body["log_url"].as_string() << endl;
cache.put(hostname, body["log_url"].as_string()); cache.put(hostname, body["log_url"].as_string());
} catch (...) {
cout << "error" << endl;
}
} }
} }