Browse Source

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.
master
James E. Blair 3 months ago
parent
commit
9b9951dff5
3 changed files with 39 additions and 25 deletions
  1. 7
    3
      Dockerfile
  2. 11
    0
      vhost.conf
  3. 21
    22
      zuul-preview/main.cc

+ 7
- 3
Dockerfile View File

@@ -31,9 +31,13 @@ FROM debian:testing
31 31
 
32 32
 COPY --from=builder /output/bindep/run.txt /run.txt
33 33
 RUN 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 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
38
+COPY ./vhost.conf /etc/apache2/sites-available/000-default.conf
37 39
 COPY --from=builder /usr/local /usr/local
40
+
41
+EXPOSE 80
38 42
 ENTRYPOINT ["/usr/bin/dumb-init", "--"]
39
-CMD ["/usr/local/bin/zuul-preview"]
43
+CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]

+ 11
- 0
vhost.conf View File

@@ -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>

+ 21
- 22
zuul-preview/main.cc View File

@@ -47,19 +47,15 @@ class Cache {
47 47
   // The maximum size of the cache.
48 48
   const uint32_t size;
49 49
 
50
-  // Mutex protecting the map and list.
51
-  mutex cache_mutex;
52
-
53 50
 public:
54 51
   Cache(uint s)
55
-    : queue {}, map {}, size{s}, cache_mutex{}
52
+    : queue {}, map {}, size{s}
56 53
   { }
57 54
 
58 55
   // Lookup the hostname in the cache and return the URL if present.
59 56
   // If the entry is present, it is moved to the head of the queue.
60 57
   optional<const string> get(const string &key)
61 58
   {
62
-    lock_guard<mutex> guard{cache_mutex};
63 59
     auto location = map.find(key);
64 60
     if (location == map.end())
65 61
       return {};
@@ -67,7 +63,7 @@ public:
67 63
     auto val = *(location->second);
68 64
     queue.erase(location->second);
69 65
     queue.push_front(val);
70
-    cout << "get push " << val.second << endl;
66
+    //cout << "get push " << val.second << endl;
71 67
     return val.second;
72 68
   }
73 69
 
@@ -75,19 +71,18 @@ public:
75 71
   // recently used entry.
76 72
   void put(const string &key, const string &value)
77 73
   {
78
-    lock_guard<mutex> guard{cache_mutex};
79 74
     auto location = map.find(key);
80 75
     if (location != map.end())
81 76
       return;
82 77
 
83 78
     if (queue.size() == size) {
84 79
       auto last = queue.back();
85
-      cout << "put pop " << last.second << endl;
80
+      //cout << "put pop " << last.second << endl;
86 81
       queue.pop_back();
87 82
       map.erase(last.first);
88 83
     }
89 84
 
90
-    cout << "put push " << value << endl;
85
+    //cout << "put push " << value << endl;
91 86
     queue.push_front(make_pair(key, value));
92 87
     map[key] = queue.begin();
93 88
   }
@@ -130,19 +125,23 @@ int main(int, char**)
130 125
     */
131 126
 
132 127
      // 75031cad206c4014ad7a3387091d15ab
133
-    auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
134
-    uri.append_path(buildid);
135
-    auto response = client.request(
128
+    try {
129
+      auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
130
+      uri.append_path(buildid);
131
+      auto response = client.request(
136 132
         web::http::methods::GET, uri.to_string()).get();
137
-    // body is a web::json::value
138
-    auto body = response.extract_json().get();
139
-    //cout << response.status_code() << endl;
140
-    //cout << body.serialize() << endl;
141
-
142
-    // TODO: use artifact
143
-    // body["log_url"].as_string() returns a const std::string&
144
-    cout << body["log_url"].as_string() << endl;
145
-
146
-    cache.put(hostname, body["log_url"].as_string());
133
+      // body is a web::json::value
134
+      // cout << response.status_code() << endl;
135
+      auto body = response.extract_json().get();
136
+      //cout << body.serialize() << endl;
137
+
138
+      // TODO: use artifact
139
+      // body["log_url"].as_string() returns a const std::string&
140
+      cout << body["log_url"].as_string() << endl;
141
+
142
+      cache.put(hostname, body["log_url"].as_string());
143
+    } catch (...) {
144
+      cout << "error" << endl;
145
+    }
147 146
   }
148 147
 }

Loading…
Cancel
Save