Use an env var for the API url
This commit is contained in:
parent
12e8291698
commit
7b680c18ec
@ -40,4 +40,5 @@ COPY --from=builder /usr/local /usr/local
|
|||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
||||||
|
ENV ZUUL_API_URL=
|
||||||
CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]
|
CMD ["/usr/sbin/apachectl", "-DFOREGROUND", "-e", "info"]
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
# LogLevel alert rewrite:trace6
|
# LogLevel alert rewrite:trace6
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
RewriteMap preview "prg://usr/local/bin/zuul-preview"
|
RewriteMap preview "prg://usr/local/bin/zuul-preview"
|
||||||
RewriteRule "^/?(.*)$" "${preview:%{HTTP_HOST}}/$1" [P]
|
RewriteRule "^/?(.*)$" "${preview:%{ENV:ZUUL_API_URL} %{HTTP_HOST}}/$1" [P]
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
|
@ -31,12 +31,12 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
vector<string> split(const string &in)
|
vector<string> split(const string &in, char delim)
|
||||||
{
|
{
|
||||||
istringstream stream(in);
|
istringstream stream(in);
|
||||||
vector<string> parts;
|
vector<string> parts;
|
||||||
string part;
|
string part;
|
||||||
while (getline(stream, part, '.')) {
|
while (getline(stream, part, delim)) {
|
||||||
parts.push_back(part);
|
parts.push_back(part);
|
||||||
}
|
}
|
||||||
return parts;
|
return parts;
|
||||||
@ -96,9 +96,7 @@ public:
|
|||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
web::http::client::http_client client("https://zuul.opendev.org");
|
string input;
|
||||||
|
|
||||||
string hostname;
|
|
||||||
Cache cache{1024};
|
Cache cache{1024};
|
||||||
|
|
||||||
// For each request apache receieves, it sends us the HTTP host name
|
// For each request apache receieves, it sends us the HTTP host name
|
||||||
@ -107,8 +105,17 @@ int main(int, char**)
|
|||||||
// (protected by an internal mutex) and expect exactly one line of
|
// (protected by an internal mutex) and expect exactly one line of
|
||||||
// output for each.
|
// output for each.
|
||||||
// Expected input:
|
// Expected input:
|
||||||
// site.926bb0aaddad4bc3853269451e115dcb.openstack.preview.opendev.org
|
// https://zuul.opendev.org site.926bb0aaddad4bc3853269451e115dcb.openstack.preview.opendev.org
|
||||||
while (getline(cin, hostname)) {
|
while (getline(cin, input)) {
|
||||||
|
|
||||||
|
// Split the input into api_url, hostname
|
||||||
|
auto parts = split(input, ' ');
|
||||||
|
if (parts.size() != 2) {
|
||||||
|
cout << "Wrong number of args" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto api_url = parts[0];
|
||||||
|
auto hostname = parts[1];
|
||||||
|
|
||||||
// If we have the value in the cache, return it.
|
// If we have the value in the cache, return it.
|
||||||
if (auto val = cache.get(hostname)) {
|
if (auto val = cache.get(hostname)) {
|
||||||
@ -118,9 +125,9 @@ int main(int, char**)
|
|||||||
|
|
||||||
// We use the first three parts of the hostname to look up the
|
// We use the first three parts of the hostname to look up the
|
||||||
// build url.
|
// build url.
|
||||||
auto parts = split(hostname);
|
parts = split(hostname, '.');
|
||||||
if (parts.size() < 3) {
|
if (parts.size() < 3) {
|
||||||
cout << "Not enough args" << endl;
|
cout << "Not enough hostname parts" << endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto artifact = parts[0];
|
auto artifact = parts[0];
|
||||||
@ -129,6 +136,7 @@ int main(int, char**)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Use the Zuul API to look up the artifact URL.
|
// Use the Zuul API to look up the artifact URL.
|
||||||
|
web::http::client::http_client client(api_url);
|
||||||
auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
|
auto uri = web::uri_builder("/api/tenant/" + tenant + "/build");
|
||||||
uri.append_path(buildid);
|
uri.append_path(buildid);
|
||||||
auto response = client.request(
|
auto response = client.request(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user