|
| 1 | +# Image metadata and config |
| 2 | +FROM debian:jessie |
| 3 | + |
| 4 | +LABEL name="angular.io PR preview" \ |
| 5 | + description="This image implements the PR preview functionality for angular.io." \ |
| 6 | + vendor="Angular" \ |
| 7 | + version="1.0" |
| 8 | + |
| 9 | +VOLUME /aio-secrets |
| 10 | +VOLUME /var/www/aio-builds |
| 11 | +VOLUME /dockerbuild |
| 12 | + |
| 13 | +EXPOSE 80 443 |
| 14 | + |
| 15 | + |
| 16 | +# Build-time args and env vars |
| 17 | +# The AIO_ARTIFACT_PATH path needs to be kept in synch with the value of |
| 18 | +# `aio_preview->steps->store_artifacts->destination` property in `.circleci/config.yml` |
| 19 | +ARG AIO_ARTIFACT_PATH=aio/dist/aio-snapshot.tgz |
| 20 | +ARG TEST_AIO_ARTIFACT_PATH=$AIO_ARTIFACT_PATH |
| 21 | +ARG AIO_BUILDS_DIR=/var/www/aio-builds |
| 22 | +ARG TEST_AIO_BUILDS_DIR=/tmp/aio-builds |
| 23 | +ARG AIO_DOMAIN_NAME=ngbuilds.io |
| 24 | +ARG TEST_AIO_DOMAIN_NAME=$AIO_DOMAIN_NAME.localhost |
| 25 | +ARG AIO_GITHUB_ORGANIZATION=angular |
| 26 | +ARG TEST_AIO_GITHUB_ORGANIZATION=test-org |
| 27 | +ARG AIO_GITHUB_REPO=angular |
| 28 | +ARG TEST_AIO_GITHUB_REPO=test-repo |
| 29 | +ARG AIO_GITHUB_TEAM_SLUGS=team,aio-contributors |
| 30 | +ARG TEST_AIO_GITHUB_TEAM_SLUGS=team,aio-contributors |
| 31 | +ARG AIO_NGINX_HOSTNAME=$AIO_DOMAIN_NAME |
| 32 | +ARG TEST_AIO_NGINX_HOSTNAME=$TEST_AIO_DOMAIN_NAME |
| 33 | +ARG AIO_NGINX_PORT_HTTP=80 |
| 34 | +ARG TEST_AIO_NGINX_PORT_HTTP=8080 |
| 35 | +ARG AIO_NGINX_PORT_HTTPS=443 |
| 36 | +ARG TEST_AIO_NGINX_PORT_HTTPS=4433 |
| 37 | +ARG AIO_SIGNIFICANT_FILES_PATTERN='^(?:aio|packages)/(?!.*[._]spec\\.[jt]s$)' |
| 38 | +ARG TEST_AIO_SIGNIFICANT_FILES_PATTERN=$AIO_SIGNIFICANT_FILES_PATTERN |
| 39 | +ARG AIO_TRUSTED_PR_LABEL="aio: preview" |
| 40 | +ARG TEST_AIO_TRUSTED_PR_LABEL="aio: preview" |
| 41 | +ARG AIO_PREVIEW_SERVER_HOSTNAME=preview.localhost |
| 42 | +ARG TEST_AIO_PREVIEW_SERVER_HOSTNAME=preview.localhost |
| 43 | +ARG AIO_ARTIFACT_MAX_SIZE=20971520 |
| 44 | +ARG TEST_AIO_ARTIFACT_MAX_SIZE=200 |
| 45 | +ARG AIO_PREVIEW_SERVER_PORT=3000 |
| 46 | +ARG TEST_AIO_PREVIEW_SERVER_PORT=3001 |
| 47 | + |
| 48 | +ENV AIO_ARTIFACT_PATH=$AIO_ARTIFACT_PATH TEST_AIO_ARTIFACT_PATH=$TEST_AIO_ARTIFACT_PATH \ |
| 49 | + AIO_BUILDS_DIR=$AIO_BUILDS_DIR TEST_AIO_BUILDS_DIR=$TEST_AIO_BUILDS_DIR \ |
| 50 | + AIO_DOMAIN_NAME=$AIO_DOMAIN_NAME TEST_AIO_DOMAIN_NAME=$TEST_AIO_DOMAIN_NAME \ |
| 51 | + AIO_GITHUB_ORGANIZATION=$AIO_GITHUB_ORGANIZATION TEST_AIO_GITHUB_ORGANIZATION=$TEST_AIO_GITHUB_ORGANIZATION \ |
| 52 | + AIO_GITHUB_REPO=$AIO_GITHUB_REPO TEST_AIO_GITHUB_REPO=$TEST_AIO_GITHUB_REPO \ |
| 53 | + AIO_GITHUB_TEAM_SLUGS=$AIO_GITHUB_TEAM_SLUGS TEST_AIO_GITHUB_TEAM_SLUGS=$TEST_AIO_GITHUB_TEAM_SLUGS \ |
| 54 | + AIO_LOCALCERTS_DIR=/etc/ssl/localcerts TEST_AIO_LOCALCERTS_DIR=/etc/ssl/localcerts-test \ |
| 55 | + AIO_NGINX_HOSTNAME=$AIO_NGINX_HOSTNAME TEST_AIO_NGINX_HOSTNAME=$TEST_AIO_NGINX_HOSTNAME \ |
| 56 | + AIO_NGINX_LOGS_DIR=/var/log/aio/nginx TEST_AIO_NGINX_LOGS_DIR=/var/log/aio/nginx-test \ |
| 57 | + AIO_NGINX_PORT_HTTP=$AIO_NGINX_PORT_HTTP TEST_AIO_NGINX_PORT_HTTP=$TEST_AIO_NGINX_PORT_HTTP \ |
| 58 | + AIO_NGINX_PORT_HTTPS=$AIO_NGINX_PORT_HTTPS TEST_AIO_NGINX_PORT_HTTPS=$TEST_AIO_NGINX_PORT_HTTPS \ |
| 59 | + AIO_SCRIPTS_JS_DIR=/usr/share/aio-scripts-js \ |
| 60 | + AIO_SCRIPTS_SH_DIR=/usr/share/aio-scripts-sh \ |
| 61 | + AIO_SIGNIFICANT_FILES_PATTERN=$AIO_SIGNIFICANT_FILES_PATTERN TEST_AIO_SIGNIFICANT_FILES_PATTERN=$TEST_AIO_SIGNIFICANT_FILES_PATTERN \ |
| 62 | + AIO_TRUSTED_PR_LABEL=$AIO_TRUSTED_PR_LABEL TEST_AIO_TRUSTED_PR_LABEL=$TEST_AIO_TRUSTED_PR_LABEL \ |
| 63 | + AIO_PREVIEW_SERVER_HOSTNAME=$AIO_PREVIEW_SERVER_HOSTNAME TEST_AIO_PREVIEW_SERVER_HOSTNAME=$TEST_AIO_PREVIEW_SERVER_HOSTNAME \ |
| 64 | + AIO_ARTIFACT_MAX_SIZE=$AIO_ARTIFACT_MAX_SIZE TEST_AIO_ARTIFACT_MAX_SIZE=$TEST_AIO_ARTIFACT_MAX_SIZE \ |
| 65 | + AIO_PREVIEW_SERVER_PORT=$AIO_PREVIEW_SERVER_PORT TEST_AIO_PREVIEW_SERVER_PORT=$TEST_AIO_PREVIEW_SERVER_PORT \ |
| 66 | + AIO_WWW_USER=www-data \ |
| 67 | + NODE_ENV=production |
| 68 | + |
| 69 | + |
| 70 | +# Create directory for logs |
| 71 | +RUN mkdir /var/log/aio |
| 72 | + |
| 73 | + |
| 74 | +# Add extra package sources |
| 75 | +RUN apt-get update -y && apt-get install -y curl |
| 76 | +RUN curl --silent --show-error --location https://deb.nodesource.com/setup_10.x | bash - |
| 77 | +RUN curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - |
| 78 | +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list |
| 79 | +RUN echo "deb http://ftp.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/backports.list |
| 80 | + |
| 81 | + |
| 82 | +# Install packages |
| 83 | +RUN apt-get update -y && apt-get install -y \ |
| 84 | + chkconfig \ |
| 85 | + cron \ |
| 86 | + dnsmasq \ |
| 87 | + nano \ |
| 88 | + nodejs \ |
| 89 | + openssl \ |
| 90 | + rsyslog \ |
| 91 | + yarn |
| 92 | +RUN apt-get install -t jessie-backports -y nginx |
| 93 | +RUN yarn global add pm2@2 |
| 94 | + |
| 95 | + |
| 96 | +# Set up log rotation |
| 97 | +COPY logrotate/* /etc/logrotate.d/ |
| 98 | +RUN chmod 0644 /etc/logrotate.d/* |
| 99 | + |
| 100 | + |
| 101 | +# Set up cronjobs |
| 102 | +COPY cronjobs/aio-builds-cleanup /etc/cron.d/ |
| 103 | +RUN chmod 0744 /etc/cron.d/aio-builds-cleanup |
| 104 | +RUN crontab /etc/cron.d/aio-builds-cleanup |
| 105 | +RUN printenv | grep AIO_ >> /etc/environment |
| 106 | + |
| 107 | + |
| 108 | +# Set up dnsmasq |
| 109 | +COPY dnsmasq/dnsmasq.conf /etc/ |
| 110 | +RUN sed -i "s|{{\$AIO_NGINX_HOSTNAME}}|$AIO_NGINX_HOSTNAME|g" /etc/dnsmasq.conf |
| 111 | +RUN sed -i "s|{{\$AIO_PREVIEW_SERVER_HOSTNAME}}|$AIO_PREVIEW_SERVER_HOSTNAME|g" /etc/dnsmasq.conf |
| 112 | +RUN sed -i "s|{{\$TEST_AIO_NGINX_HOSTNAME}}|$TEST_AIO_NGINX_HOSTNAME|g" /etc/dnsmasq.conf |
| 113 | +RUN sed -i "s|{{\$TEST_AIO_PREVIEW_SERVER_HOSTNAME}}|$TEST_AIO_PREVIEW_SERVER_HOSTNAME|g" /etc/dnsmasq.conf |
| 114 | + |
| 115 | + |
| 116 | +# Set up SSL/TLS certificates |
| 117 | +COPY nginx/create-selfsigned-cert.sh /tmp/ |
| 118 | +RUN chmod a+x /tmp/create-selfsigned-cert.sh |
| 119 | +RUN /tmp/create-selfsigned-cert.sh "selfcert-prod" "$AIO_NGINX_HOSTNAME" "$AIO_LOCALCERTS_DIR" |
| 120 | +RUN /tmp/create-selfsigned-cert.sh "selfcert-test" "$TEST_AIO_NGINX_HOSTNAME" "$TEST_AIO_LOCALCERTS_DIR" |
| 121 | +RUN rm /tmp/create-selfsigned-cert.sh |
| 122 | +RUN update-ca-certificates |
| 123 | + |
| 124 | + |
| 125 | +# Set up nginx (for production and testing) |
| 126 | +RUN sed -i -E "s|^user\s+\S+;|user $AIO_WWW_USER;|" /etc/nginx/nginx.conf |
| 127 | +RUN rm -f /etc/nginx/conf.d/* |
| 128 | +RUN rm -f /etc/nginx/sites-enabled/* |
| 129 | + |
| 130 | +COPY nginx/aio-builds.conf /etc/nginx/conf.d/aio-builds-prod.conf |
| 131 | +RUN sed -i "s|{{\$AIO_BUILDS_DIR}}|$AIO_BUILDS_DIR|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 132 | +RUN sed -i "s|{{\$AIO_DOMAIN_NAME}}|$AIO_DOMAIN_NAME|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 133 | +RUN sed -i "s|{{\$AIO_LOCALCERTS_DIR}}|$AIO_LOCALCERTS_DIR|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 134 | +RUN sed -i "s|{{\$AIO_NGINX_LOGS_DIR}}|$AIO_NGINX_LOGS_DIR|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 135 | +RUN sed -i "s|{{\$AIO_NGINX_PORT_HTTP}}|$AIO_NGINX_PORT_HTTP|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 136 | +RUN sed -i "s|{{\$AIO_NGINX_PORT_HTTPS}}|$AIO_NGINX_PORT_HTTPS|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 137 | +RUN sed -i "s|{{\$AIO_PREVIEW_SERVER_HOSTNAME}}|$AIO_PREVIEW_SERVER_HOSTNAME|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 138 | +RUN sed -i "s|{{\$AIO_ARTIFACT_MAX_SIZE}}|$AIO_ARTIFACT_MAX_SIZE|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 139 | +RUN sed -i "s|{{\$AIO_PREVIEW_SERVER_PORT}}|$AIO_PREVIEW_SERVER_PORT|g" /etc/nginx/conf.d/aio-builds-prod.conf |
| 140 | + |
| 141 | +COPY nginx/aio-builds.conf /etc/nginx/conf.d/aio-builds-test.conf |
| 142 | +RUN sed -i "s|{{\$AIO_BUILDS_DIR}}|$TEST_AIO_BUILDS_DIR|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 143 | +RUN sed -i "s|{{\$AIO_DOMAIN_NAME}}|$TEST_AIO_DOMAIN_NAME|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 144 | +RUN sed -i "s|{{\$AIO_LOCALCERTS_DIR}}|$TEST_AIO_LOCALCERTS_DIR|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 145 | +RUN sed -i "s|{{\$AIO_NGINX_LOGS_DIR}}|$TEST_AIO_NGINX_LOGS_DIR|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 146 | +RUN sed -i "s|{{\$AIO_NGINX_PORT_HTTP}}|$TEST_AIO_NGINX_PORT_HTTP|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 147 | +RUN sed -i "s|{{\$AIO_NGINX_PORT_HTTPS}}|$TEST_AIO_NGINX_PORT_HTTPS|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 148 | +RUN sed -i "s|{{\$AIO_PREVIEW_SERVER_HOSTNAME}}|$TEST_AIO_PREVIEW_SERVER_HOSTNAME|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 149 | +RUN sed -i "s|{{\$AIO_ARTIFACT_MAX_SIZE}}|$TEST_AIO_ARTIFACT_MAX_SIZE|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 150 | +RUN sed -i "s|{{\$AIO_PREVIEW_SERVER_PORT}}|$TEST_AIO_PREVIEW_SERVER_PORT|g" /etc/nginx/conf.d/aio-builds-test.conf |
| 151 | + |
| 152 | + |
| 153 | +# Set up pm2 |
| 154 | +RUN pm2 startup systemv -u root > /dev/null |
| 155 | +RUN chkconfig pm2-root on |
| 156 | + |
| 157 | + |
| 158 | +# Set up the shell scripts |
| 159 | +COPY scripts-sh/ $AIO_SCRIPTS_SH_DIR/ |
| 160 | +RUN chmod a+x $AIO_SCRIPTS_SH_DIR/* |
| 161 | +RUN find $AIO_SCRIPTS_SH_DIR -maxdepth 1 -type f -printf "%P\n" \ |
| 162 | + | while read file; do ln -s $AIO_SCRIPTS_SH_DIR/$file /usr/local/bin/aio-${file%.*}; done |
| 163 | + |
| 164 | + |
| 165 | +# Set up the Node.js scripts |
| 166 | +COPY scripts-js/ $AIO_SCRIPTS_JS_DIR/ |
| 167 | +WORKDIR $AIO_SCRIPTS_JS_DIR/ |
| 168 | +RUN yarn install --production --frozen-lockfile |
| 169 | + |
| 170 | + |
| 171 | +# Set up health check |
| 172 | +HEALTHCHECK --interval=5m CMD /usr/local/bin/aio-health-check |
| 173 | + |
| 174 | + |
| 175 | +# Go! |
| 176 | +WORKDIR / |
| 177 | +CMD aio-init && tail -f /dev/null |
0 commit comments