diff --git a/Dockerfile b/Dockerfile index dfe4c5b..e8b60e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,9 +31,13 @@ FROM debian:testing COPY --from=builder /output/bindep/run.txt /run.txt 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 \ - && 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 + +EXPOSE 80 ENTRYPOINT ["/usr/bin/dumb-init", "--"] -CMD ["/usr/local/bin/zuul-preview"] +CMD ["/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 @@ + + 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] + 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 { // The maximum size of the cache. const uint32_t size; - // Mutex protecting the map and list. - mutex cache_mutex; - public: 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. // If the entry is present, it is moved to the head of the queue. optional get(const string &key) { - lock_guard guard{cache_mutex}; auto location = map.find(key); if (location == map.end()) return {}; @@ -67,7 +63,7 @@ public: auto val = *(location->second); queue.erase(location->second); queue.push_front(val); - cout << "get push " << val.second << endl; + //cout << "get push " << val.second << endl; return val.second; } @@ -75,19 +71,18 @@ public: // recently used entry. void put(const string &key, const string &value) { - lock_guard guard{cache_mutex}; auto location = map.find(key); if (location != map.end()) return; if (queue.size() == size) { auto last = queue.back(); - cout << "put pop " << last.second << endl; + //cout << "put pop " << last.second << endl; queue.pop_back(); map.erase(last.first); } - cout << "put push " << value << endl; + //cout << "put push " << value << endl; queue.push_front(make_pair(key, value)); map[key] = queue.begin(); } @@ -130,19 +125,23 @@ int main(int, char**) */ // 75031cad206c4014ad7a3387091d15ab - auto uri = web::uri_builder("/api/tenant/" + tenant + "/build"); - uri.append_path(buildid); - auto response = client.request( + try { + auto uri = web::uri_builder("/api/tenant/" + tenant + "/build"); + uri.append_path(buildid); + auto response = client.request( web::http::methods::GET, uri.to_string()).get(); - // body is a web::json::value - auto body = response.extract_json().get(); - //cout << response.status_code() << endl; - //cout << body.serialize() << endl; + // body is a web::json::value + // cout << response.status_code() << endl; + auto body = response.extract_json().get(); + //cout << body.serialize() << endl; - // TODO: use artifact - // body["log_url"].as_string() returns a const std::string& - cout << body["log_url"].as_string() << endl; + // TODO: use artifact + // body["log_url"].as_string() returns a const std::string& + 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; + } } }