From 2f1a862b831f44b9b923dcc52f94af69d3b40aa6 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 18 Apr 2019 12:49:27 +0300 Subject: [PATCH] build(docs-infra): upgrade preview server docker image to Debian 9 (#29976) Previously, the preview server docker image was based on Debian 8 (jessie). Recently, `jessie-updates` and `jessie-backborts` were removed from the Debian mirrors ([more info][1]), thus breaking new builds of the image. Instead of updating `/etc/apt/sources.list` to remove the obsolete sources, this commit upgrades to Debian 9 (stretch). (The GCE VM running the preview server docker container was also upgraded from Debian 8 to 9 this morning.) --- Other changes: - Removed dependency on `chkconfig`, which is not supported on Debian 9. - Installing `nginx` from the regular repositories (instead of `*-backports). - Upgraded to `pm2` v3, which can handle hooking itself up to system startup better (without `chkconfig` - see above). - Updated tests to reflect the fact that `nginx` has dropped the reason phrase in response status lines for HTTP/2 (in compliance with [the spec][2]). (HTTP/1.1: `HTTP/1.1 200 OK` | HTTP/2: `HTTP/2 200`) [1]: https://www.lucas-nussbaum.net/blog/?p=947 [2]: https://http2.github.io/http2-spec/#rfc.section.8.1.2.4 PR Close #29976 --- aio/aio-builds-setup/dockerbuild/Dockerfile | 12 ++++------ .../scripts-js/lib/verify-setup/helper.ts | 16 ++----------- .../scripts-js/lib/verify-setup/nginx.e2e.ts | 24 +++++++++---------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/aio/aio-builds-setup/dockerbuild/Dockerfile b/aio/aio-builds-setup/dockerbuild/Dockerfile index d77d210a5e..78432dfe50 100644 --- a/aio/aio-builds-setup/dockerbuild/Dockerfile +++ b/aio/aio-builds-setup/dockerbuild/Dockerfile @@ -1,5 +1,5 @@ # Image metadata and config -FROM debian:jessie +FROM debian:stretch LABEL name="angular.io PR preview" \ description="This image implements the PR preview functionality for angular.io." \ @@ -76,21 +76,20 @@ RUN apt-get update -y && apt-get install -y curl RUN curl --silent --show-error --location https://deb.nodesource.com/setup_10.x | bash - RUN curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -RUN echo "deb http://ftp.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/backports.list +RUN echo "deb http://ftp.debian.org/debian stretch-backports main" | tee /etc/apt/sources.list.d/backports.list # Install packages RUN apt-get update -y && apt-get install -y \ - chkconfig \ cron \ dnsmasq \ nano \ + nginx \ nodejs \ openssl \ rsyslog \ yarn -RUN apt-get install -t jessie-backports -y nginx -RUN yarn global add pm2@2 +RUN yarn global add pm2@3 # Set up log rotation @@ -151,8 +150,7 @@ RUN sed -i "s|{{\$AIO_PREVIEW_SERVER_PORT}}|$TEST_AIO_PREVIEW_SERVER_PORT|g" /et # Set up pm2 -RUN pm2 startup systemv -u root > /dev/null -RUN chkconfig pm2-root on +RUN pm2 startup --user root > /dev/null # Set up the shell scripts diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/helper.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/helper.ts index f267e608dd..d5c65241ef 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/helper.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/helper.ts @@ -1,7 +1,6 @@ // Imports import * as cp from 'child_process'; import * as fs from 'fs'; -import * as http from 'http'; import * as path from 'path'; import * as shell from 'shelljs'; import {AIO_DOWNLOADS_DIR, HIDDEN_DIR_PREFIX} from '../common/constants'; @@ -105,18 +104,7 @@ class Helper { Object.keys(this.portPerScheme).forEach(scheme => suiteFactory(scheme, this.portPerScheme[scheme])); } - public verifyResponse(status: number | [number, string], regex: string | RegExp = /^/): VerifyCmdResultFn { - let statusCode: number; - let statusText: string; - - if (Array.isArray(status)) { - statusCode = status[0]; - statusText = status[1]; - } else { - statusCode = status; - statusText = http.STATUS_CODES[statusCode] || 'UNKNOWN_STATUS_CODE'; - } - + public verifyResponse(status: number, regex: string | RegExp = /^/): VerifyCmdResultFn { return (result: CmdResult) => { const [headers, body] = result.stdout. split(/(?:\r?\n){2,}/). @@ -131,7 +119,7 @@ class Helper { } expect(result.success).toBe(true); - expect(headers).toContain(`${statusCode} ${statusText}`); + expect(headers).toMatch(new RegExp(`HTTP/(?:1\\.1|2) ${status} `)); expect(body).toMatch(regex); }; } diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/nginx.e2e.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/nginx.e2e.ts index 656973b205..4a58bad9f2 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/nginx.e2e.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/nginx.e2e.ts @@ -259,10 +259,10 @@ describe(`nginx`, () => { it('should disallow non-GET requests', async () => { await Promise.all([ - h.runCmd(`curl -iLX POST ${baseUrl}/42`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX PUT ${baseUrl}/42`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX PATCH ${baseUrl}/42`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX DELETE ${baseUrl}/42`).then(h.verifyResponse([405, 'Not Allowed'])), + h.runCmd(`curl -iLX POST ${baseUrl}/42`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX PUT ${baseUrl}/42`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX PATCH ${baseUrl}/42`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX DELETE ${baseUrl}/42`).then(h.verifyResponse(405)), ]); }); @@ -295,10 +295,10 @@ describe(`nginx`, () => { const url = `${scheme}://${host}/circle-build`; Promise.all([ - h.runCmd(`curl -iLX GET ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX PUT ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX PATCH ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX DELETE ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), + h.runCmd(`curl -iLX GET ${url}`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX PUT ${url}`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX PATCH ${url}`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX DELETE ${url}`).then(h.verifyResponse(405)), ]).then(done); }); @@ -334,10 +334,10 @@ describe(`nginx`, () => { it('should disallow non-POST requests', done => { Promise.all([ - h.runCmd(`curl -iLX GET ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX PUT ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX PATCH ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), - h.runCmd(`curl -iLX DELETE ${url}`).then(h.verifyResponse([405, 'Not Allowed'])), + h.runCmd(`curl -iLX GET ${url}`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX PUT ${url}`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX PATCH ${url}`).then(h.verifyResponse(405)), + h.runCmd(`curl -iLX DELETE ${url}`).then(h.verifyResponse(405)), ]).then(done); });