18f-pages-server 中文文档教程

发布于 3年前 浏览 22 项目主页 更新于 3年前

18f-pages-server

此服务器为 18F 页面 发布静态网站。 它的工作方式与 GitHub 页面 非常相似。 它 自动发布基于 Jekyll 的网站 每当对发布分支进行更新时(如 gh-pages,但在哪里 分支的名称由服务器的配置定义)。 它也是 如果发布,则支持通过 rsync 发布 分支不包含基于 Jekyll 的站点。

Reusability

服务器可能由其他组织运行,因为它是完全可配置的 通过 pages-config.json 文件。 你可以想象更换 您自己的说明中的所有“18F”实例 组织的句柄。

Publishing

一旦服务器已经按照 服务器安装说明,提交到存储库的 发布分支(例如 18f-pages)将在 https://PAGES_HOST/REPO_NAME,其中 PAGES_HOST 是主机名 运行 18f-pages-server 并且 REPO_NAME 是存储库的名称 没有组织前缀。

例如,18F/guides-template 将发布到 https://pages.18f.gov/guides-template/。

最近构建尝试的状态将显示在 <代码>https://PAGES_HOST/REPO_NAME/build.log。

Prefixing Jekyll links with {{ site.baseurl }}

Jekyll 站点中以以下开头的指向另一个页面或资源的每个链接 / 或使用 {{ post.url }} 等指令定义的必须{{ site.baseurl }} 为前缀。 18f-pages-server 依赖于此 财产以确保您的网站可以在主机上正确发布为 https://PAGES_HOST/REPO_NAME/,如 额外的服务器生成的 Jekyll 配置部分。 这完全类似于 GitHub 项目页面 URL 结构

例如:

[This link will be broken when published.](/another/page)
[This link will continue to work.]({{ site.baseurl }}/another/page)

{{ site.baseurl }} 应用于每个需要它的链接,您的网站将 在本地服务时正确呈现并表现相同 http://localhost:4000/ 通过 jekyll serve and 发布到 <代码>https://PAGES_HOST/REPO_NAME/。

Repository configuration

在以下说明中,18f-pages 是发布的名称 分支。 此名称对于每个 builders 条目都是可配置的 pages-config.json 文件。

  • Create the 18f-pages publishing branch. If you already have a gh-pages branch, you can do this on the command line via:
$ git checkout -b 18f-pages gh-pages
$ git push origin 18f-pages
  • If your repo is primarily an 18F Pages site (as opposed to a project site with an 18f-pages branch for documentation), you may optionally set the default branch on GitHub to 18f-pages.
  • Configure a webhook for the repository if there isn't already a webhook configured for the entire GitHub organization.
  • Push a change to the 18f-pages branch to publish your site.

New sites are not published before the first push to the publishing branch

服务器当前未检测到发布分支的创建(例如 18f-pages),或创建带有发布分支的存储库。 因此,必须先将更改推送到发布分支,然后站点才会 出现在服务主机上。 目前还不清楚我们是否会实施检测 将来的新存储库或发布分支。

Multiple publishing branches

一个版本库可以包含多个发布分支,每个分支 对应于 pages-config.json 中的一个 builders 项目 文件

几个 18F 存储库同时具有 18f-pages18f-pages-staging 分支,想法是大多数更改将首先应用于 18f-pages-staging 并发布在 https://pages-staging.18f.gov/。 当。。。的时候 站点已准备好公开发布,18f-pages-staging 分支将 合并到 18f-pages,将站点发布在 https://pages.18f.gov/。

Publishing to internal and external sites from the same branch

可以将您的网站配置为同时发布到内部网站 和来自同一分支的外部站点。

  • _config_internal.yml 文件添加到您的 Jekyll 站点,其中包含 过滤掉仅限内部的内容所需的配置。 例如,您的 仅供内部使用的内容可以使用以下内容进行包装 Liquid conditional

  {% if site.internal %}REDACTED TO PROTECT THE INNOCENT AND THEIR VICTIMS{% endif %}
  

然后,您的 _config_internal.yml 应该包含属性:

  internal: true
  

但是,您可以自由实施任何过滤和配置方案 这对您的网站有意义。

您还可以添加一个 _config_external.yml 文件以进行额外配置, 但是 _config_internal.yml 文件必须仍然存在。

如果您需要一个网站只供内部使用,请设置一个单独的 builders 配置中的条目 用于仅限内部的分支。

Webhook configuration

您将需要配置一个或多个 GitHub webhooks 发送push 事件到 https://PAGES_HOST/deploy,其中 PAGES_HOST 是主机名 您组织的页面服务器实例,例如 pages.18f.gov。 这 webhook 必须是内容类型application/json。 Webhooks 可以是 为单个存储库配置,或者可以配置单个 webhook 对于整个 GitHub 组织。 请参阅 18F 指南模板 webhook 设置 说明 举个例子。

Stale sites and repositories require manual deletion

目前没有自动删除陈旧存储库的工具 或当存储库或其发布分支被创建时由它们生成的站点 重命名或删除,或者当站点通过自己的更新自己的 baseurlpagesYaml 文件。 目前,此类存储库 并且生成的站点目录必须从主机中手动删除。 我们可能 将来实施自动站点和存储库删除。

Additional server-generated Jekyll configuration

对于 Jekyll 站点,服务器将生成一个临时的 Jekyll 配置文件,其中包含 由 pagesConfig 配置属性 定义的名称。 对于 18F 页面,此文件称为 _config_18f_pages.yml。 它将定义 以下值将覆盖站点的任何现有值 _config.yml 文件:

  • baseurl: - set to the name of the repository without the organization prefix, e.g. /guides-template for the 18F/guides-template repo
  • asset_root: - set to the assetRoot configuration property

在大多数情况下,已发布的站点不应具有这些属性中的任何一个 在他们的 _config.yml 文件中定义,也不应该发布他们自己的 _config_18f_pages.yml 文件。 但是,如果站点确实包含自己的 _config_18f_pages.yml 文件,服务器将使用该文件中的设置 而不是自己生成。

如果一个网站使用这个文件来定义它自己的 baseurl 属性,那 property不是/或者空字符串,那么生成的输出目录 将匹配定义的 baseurl。 在这种情况下,baseurl 必须以 <代码>/。

如果 baseurl/ 或空字符串,或未在文件中定义,则 生成的输出目录将匹配任何其他站点的默认值,即 没有组织前缀的存储库名称。 请参阅以下部分 为生成的主页创建符号链接了解详情 关于这个用例。

Installing the 18f-pages server

如果您的系统上尚不存在以下内容,请安装:

  • Node.js version 0.12.7 or higher; check with node -v
  • Ruby version 2.2.3 or higher; check with ruby -v
  • Git version 1.9.1 or higher; check with git --version

对于 Ruby,我们强烈建议使用版本管理器,例如 rbenvrvm, 虽然这不是必需的。

rsync 应该已经安装在大多数类 UNIX 系统上,但是 rsyncOpts 配置选项可能需要调整, 特别是在 OS X 上。您可能希望手动尝试使用 rsync 来 确定最适合您的选项。

使用正确的 Node.js、Ruby 和 Git 版本,运行以下命令:

$ gem install jekyll bundler
$ npm install -g 18f-pages-server forever

最后,作为将运行服务器的主机上的用户, 生成 SSH 密钥以添加到您的 GitHub 帐号。 新钥匙可以 如果您离开组织,则由另一名团队成员生成。

Generate and configure pages-config.json

运行 18f-pages print-template > path/to/pages-config.json 生成一个 pages-config.json 文件。 编辑此文件以支持您的安装。

该模板是 pages-config.json 的副本 这个存储库,它基于 18F 页面的实际配置,以及 说明了以下每个设置:

  • port: the port on which the server will listen for GitHub webhooks
  • home: the parent directory for all of the generated site content
  • git: path to git on the host machine
  • bundler: path to bundle on the host machine
  • bundlerCacheDir: path to bundle cache relative to home
  • jekyll: path to jekyll on the host machine
  • rsync: path to rsync on the host machine
  • rsyncOpts: options to pass to rsync that control Jekyll-less builds; OS X installations in particular may need to adjust these
  • s3 (optional): if present, will back up each generated site to Amazon S3; attributes are:
  • awscli: path to the aws command on the host machine
  • bucket: address of the S3 bucket to which to sync generated sites
  • payloadLimit: maximum allowable size (in bytes) for incoming webhooks
  • githubOrg: GitHub organization to which all published repositories belong
  • pagesConfig: name of the server-generated Jekyll config file that sets the baseurl: and asset_root: Jekyll properties
  • pagesYaml: name of the file from which properties such as baseurl: will be read
  • fileLockWaitTime: max time for an incoming build request to wait for the lock file, in milliseconds
  • fileLockPollTime: max interval for an incoming build request to poll for the lock file, in milliseconds
  • secretKeyFile (optional): if you defined a Secret for your webhook, you must enter the path to a file containing the secret value; otherwise ignore this
  • assetRoot: the value that the generated pagesConfig file will contain for the asset_root: Jekyll configuration variable; see the guides_style_18f gem's source code for how 18F Pages share common style sheets and JavaScript files across 18F Pages sites, so that updates to the theme are shared across all 18F Pages once they are pushed to the 18F Guides Template
  • builders: a list of individual webhook listeners/document publishers; each item contains the following fields, each of which must contain a unique value relative to all other builders entries:
  • branch: the publishing branch from which to generate sites
  • repositoryDir: the directory within home into which all repositories will be cloned
  • generatedSiteDir: the directory within home into which all sites will be generated
  • internalSiteDir: the directory within home into which internal views of sites will be generated

此外,每个 builders 条目都可以覆盖以下一个或多个 顶级值:

  • githubOrg
  • pagesConfig
  • pagesYaml
  • secretKeyFile
  • assetRoot

builders 列表允许我们运行一个服务器来发布两个 https://pages.18f.gov/ 和经过身份验证的 https://pages-staging.18f.gov/。

Branch-specific secret keys

顶级 secretKeyFile 中的值将用于验证所有 默认情况下跨所有分支传入的有效负载。 但是,可以 配置分支特定的 secretKeyFile 值,如果有效负载 对应于特定分支的信息由额外的 webhook 生成。

例如,如果你想为多个 GitHub 运行一个页面服务器 组织,而不是跨组织共享密钥,每个 组织将有自己的分支,有自己的 secretKeyFile

Run the 18f-pages server

之后,运行以下命令启动服务器 Forever,其中 /path/to//usr/local/bin/ 替换为适当的绝对路径:

$ forever start -l /path/to/pages.log -a /usr/local/bin/18f-pages /path/to/pages-config.json

您可以通过运行 which 18f-pages18f-pages 的绝对路径代码>。

Create a symlink to the index.html of the generated homepage

如果您希望发布您的主页,请遵循此示例 18f-pages-server 主机也使用 18f-pages-server

18F Pages 主页本身是从 18F/pages 存储库。 它定义了自己的 _config_18f_pages.yml 文件,以便 baseurl: 覆盖 额外的服务器生成的 Jekyll 配置部分 不会发生:

baseurl:
asset_root: /guides-template

主页字面上是一个单页网站,但它仍然发布到 名为 pages 的目录。 让它出现在的根部的技巧 https://pages.18f.gov/ 是手动 符号链接 pages/index.html 到 它的父目录:

$ ln -s /home/ubuntu/pages-generated/pages/index.html /home/ubuntu/pages-generated/index.html

这个基于符号链接的解决方案导致主页也保持可用 在 https://pages.18f.gov/pages/,但这似乎不值得修复。 如果 避免这是您组织的优先事项,主页可以是 使用自己专用的 builder 生成并通过自己专用的服务 网络服务器规则。 尝试自动生成符号链接或复制 生成的主页文件可能是另一种选择,但似乎风险更大且 可能深奥。

Webserver configuration

最后的必需步骤是设置您的网络服务器以公开18f-pages webhook 端点并提供由 18f-pages 生成的静态内容 服务器。 最后的可选步骤是在组织范围内设置一个 webhook 配置并运行网络服务器后。

以下摘录自完整 18F页面nginx配置 对于 https://pages.18f.gov/ 和 https://pages-staging.18f.gov/。 注意如何 值与 pages-config.json 文件 中的值匹配, 在配置部分中解释。

https://pages.18f.gov/ server 块的第一个摘录定义了 https://pages.18f.gov/deploy webhook 端点。 这个端点代理 向运行在端口 5000 上的 18f-pages 服务器发出请求。请注意,只有一个 webhook 端点是必需的,因为单个服务器实例同时发布 https://pages.18f.gov/ 和 https://pages-staging.18f.gov/。

server {
  listen 443 ssl spdy;
  server_name  pages.18f.gov;
  include ssl/star.18f.gov.conf;

  ...

  location /deploy {
    proxy_pass http://localhost:5000/;
    proxy_http_version 1.1;
    proxy_redirect off;

    proxy_set_header Host   $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_max_temp_file_size 0;

    proxy_connect_timeout 10;
    proxy_send_timeout    30;
    proxy_read_timeout    30;
  }

  ...
}

https://pages.18f.gov/ server 块的第二个摘录对应 到 pages-config.json 的第一个 builders 条目:

server {
  listen 443 ssl spdy;
  server_name  pages.18f.gov;
  include ssl/star.18f.gov.conf;

  ...

  location / {
    root   /home/ubuntu/pages-generated;
    index  index.html;
    default_type text/html;
  }

  ...
}

这些最终的server 块定义经过身份验证的 https://pages-staging.18f.gov/ 主机。 127.0.0.1:8080 块对应于 pages-config.json 中的第二个 builders 条目。 请注意,该网站使用 bitly/oauth2_proxy 用于身份验证, 您可以在 18F Hub 的 OAuth2 代理部分了解更多信息 部署自述文件

server {
  listen 443 ssl spdy;
  server_name  pages-staging.18f.gov;
  include ssl/star.18f.gov.conf;

  include vhosts/auth-locations.conf;
}

server {
  listen 127.0.0.1:8080;
  server_name  pages-staging.18f.gov;
  port_in_redirect off;

  location / {
    root  /home/ubuntu/pages-staging;
    index  index.html;
    default_type text/html;
  }
}

Contributing

  1. Fork the repo (or just clone it if you're an 18F team member)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes and test them via npm test or gulp test
  4. Lint your changes with gulp lint
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

欢迎提交问题或 ping @ertzeid、@jbarnicle 或@mtorres253 询问您可能有的任何问题, 特别是如果当前文档应该已经解决了您的需求,但是 没有。

Public domain

该项目属于全球公共领域。 如中所述 CONTRIBUTING

该项目在美国属于公共领域,版权所有 和世界范围内的工作相关权利通过放弃 CC0 1.0 通用公共领域贡献

所有对该项目的贡献都将在 CC0 奉献精神下发布。 通过提交拉取请求,您同意遵守此放弃 版权权益。

18f-pages-server

This server publishes static websites for 18F Pages. It works very similarly to GitHub pages. It automatically publishes Jekyll-based web sites whenever updates are made to a publishing branch (like gh-pages, but where the name of the branch is defined by the server's configuration). It also supports publishing via rsync if the publishing branch does not contain a Jekyll-based site.

Reusability

The server may be run by other organizations, as it is completely configurable via the pages-config.json file. You may imagine replacing all instances of "18F" in the instructions that follow with your own organization's handle.

Publishing

Once the server has been set up per the server installation instructions, commits to a repository's publishing branch (e.g. 18f-pages) will publish the site at https://PAGES_HOST/REPO_NAME, where PAGES_HOST is the name of the host running 18f-pages-server and REPO_NAME is the name of the repository without the organization prefix.

For example, 18F/guides-template will publish to https://pages.18f.gov/guides-template/.

The status of the most recent build attempt will be visible at https://PAGES_HOST/REPO_NAME/build.log.

Prefixing Jekyll links with {{ site.baseurl }}

Every link to another page or resource within a Jekyll site that starts with / or that is defined using directives such as {{ post.url }} must be prefixed with {{ site.baseurl }}. The 18f-pages-server depends on this property to ensure that your site may be published correctly on the host as https://PAGES_HOST/REPO_NAME/, as explained in the additional server-generated Jekyll configuration section. This is exactly analogous to the GitHub Project Pages URL structure.

For example:

[This link will be broken when published.](/another/page)
[This link will continue to work.]({{ site.baseurl }}/another/page)

With {{ site.baseurl }} applied to every link that needs it, your site will render properly and behave identically when served locally at http://localhost:4000/ via jekyll serve and when published to https://PAGES_HOST/REPO_NAME/.

Repository configuration

In the following instructions, 18f-pages is the name of the publishing branch. This name is configurable for each builders entry in the pages-config.json file.

  • Create the 18f-pages publishing branch. If you already have a gh-pages branch, you can do this on the command line via:
$ git checkout -b 18f-pages gh-pages
$ git push origin 18f-pages
  • If your repo is primarily an 18F Pages site (as opposed to a project site with an 18f-pages branch for documentation), you may optionally set the default branch on GitHub to 18f-pages.
  • Configure a webhook for the repository if there isn't already a webhook configured for the entire GitHub organization.
  • Push a change to the 18f-pages branch to publish your site.

New sites are not published before the first push to the publishing branch

The server currently does not detect the creation of a publishing branch (e.g. 18f-pages), or the creation of a repository with a publishing branch. Therefore, one must push a change to a publishing branch before the site will appear on the serving host. It is unclear whether we will implement detection of new repositories or publishing branches in the future.

Multiple publishing branches

A repository can contain more than one publishing branch, with each branch corresponding to a builders item in the pages-config.json file.

Several 18F repositories have both an 18f-pages and an 18f-pages-staging branch, with the idea that most changes will be applied first to 18f-pages-staging and published at https://pages-staging.18f.gov/. When the site is ready for public release, the 18f-pages-staging branch will be merged into 18f-pages, publishing the site at https://pages.18f.gov/.

Publishing to internal and external sites from the same branch

It is possible to configure your site to publish to both an internal site and an external site from the same branch.

  • Add a _config_internal.yml file to your Jekyll site containing the configuration needed to filter out internal-only content. For example, your internal-only content may be wrapped using the following Liquid conditional:

  {% if site.internal %}REDACTED TO PROTECT THE INNOCENT AND THEIR VICTIMS{% endif %}
  

Then, your _config_internal.yml should contain the property:

  internal: true
  

However, you're free to implement any filtering and configuration scheme that makes sense for your site.

You may also add a _config_external.yml file for additional configuration, but a _config_internal.yml file must still be present.

If you need a site to remain internal-only, set up a separate builders entry in the configuration for an internal-only branch.

Webhook configuration

You will need to configure one or more GitHub webhooks to send push events to https://PAGES_HOST/deploy, where PAGES_HOST is the hostname for your organization's instance of the pages server, e.g. pages.18f.gov. The webhooks must be of Content type application/json. Webhooks can be configured for individual repositories, or a single webhook can be configured for an entire GitHub organization. See the 18F Guides Template webhook setup instructions for an example.

Stale sites and repositories require manual deletion

There is currently no facility for automatically deleting stale repositories or the sites generated by them when a repository or its publishing branch is renamed or deleted, or when a site updates its own baseurl via its own pagesYaml file. For the time being, such repositories and generated site directories must be removed from the host manually. We may implement automated site and repository removal in the future.

Additional server-generated Jekyll configuration

For Jekyll sites, the server will generate a temporary Jekyll config file with a name defined by the pagesConfig configuration property. For 18F Pages, this file is called _config_18f_pages.yml. It will define the following values that will override any existing values from the site's _config.yml file:

  • baseurl: - set to the name of the repository without the organization prefix, e.g. /guides-template for the 18F/guides-template repo
  • asset_root: - set to the assetRoot configuration property

In most cases, published sites should not have either of these properties defined in their _config.yml files, nor should they publish their own _config_18f_pages.yml file. However, if a site does contain its own _config_18f_pages.yml file, the server will use settings from that file rather than generating its own.

If a site uses this file to define its own baseurl property, and that property is not / or the empty string, then the generated output directory will match the defined baseurl. In this case, baseurl must begin with /.

If baseurl is / or the empty string, or is not defined in the file, the generated output directory will match the default for any other site, which is the repository name without the organization prefix. See the section on creating a symlink to the generated homepage for details about this use case.

Installing the 18f-pages server

Install the following if they are not yet present on your system:

  • Node.js version 0.12.7 or higher; check with node -v
  • Ruby version 2.2.3 or higher; check with ruby -v
  • Git version 1.9.1 or higher; check with git --version

For Ruby, we strongly recommend using a version manager such as rbenv or rvm, though this is not required.

rsync should already be installed on most UNIX-like systems, but the rsyncOpts configuration option may require adjustment, particularly on OS X. You may wish to experiment with rsync manually to determine which options suit you best.

With the correct Node.js, Ruby, and Git versions in place, run the following:

$ gem install jekyll bundler
$ npm install -g 18f-pages-server forever

Finally, as the user on the host that will run the server, generate an SSH key to add to your GitHub account. A new key can be generated by another team member should you leave the organization.

Generate and configure pages-config.json

Run 18f-pages print-template > path/to/pages-config.json to generate a pages-config.json file. Edit this file to support your installation.

The template is a copy of the pages-config.json from this repository, which is based on the actual configuration for 18F Pages, and illustrates each of the following settings:

  • port: the port on which the server will listen for GitHub webhooks
  • home: the parent directory for all of the generated site content
  • git: path to git on the host machine
  • bundler: path to bundle on the host machine
  • bundlerCacheDir: path to bundle cache relative to home
  • jekyll: path to jekyll on the host machine
  • rsync: path to rsync on the host machine
  • rsyncOpts: options to pass to rsync that control Jekyll-less builds; OS X installations in particular may need to adjust these
  • s3 (optional): if present, will back up each generated site to Amazon S3; attributes are:
  • awscli: path to the aws command on the host machine
  • bucket: address of the S3 bucket to which to sync generated sites
  • payloadLimit: maximum allowable size (in bytes) for incoming webhooks
  • githubOrg: GitHub organization to which all published repositories belong
  • pagesConfig: name of the server-generated Jekyll config file that sets the baseurl: and asset_root: Jekyll properties
  • pagesYaml: name of the file from which properties such as baseurl: will be read
  • fileLockWaitTime: max time for an incoming build request to wait for the lock file, in milliseconds
  • fileLockPollTime: max interval for an incoming build request to poll for the lock file, in milliseconds
  • secretKeyFile (optional): if you defined a Secret for your webhook, you must enter the path to a file containing the secret value; otherwise ignore this
  • assetRoot: the value that the generated pagesConfig file will contain for the asset_root: Jekyll configuration variable; see the guides_style_18f gem's source code for how 18F Pages share common style sheets and JavaScript files across 18F Pages sites, so that updates to the theme are shared across all 18F Pages once they are pushed to the 18F Guides Template
  • builders: a list of individual webhook listeners/document publishers; each item contains the following fields, each of which must contain a unique value relative to all other builders entries:
  • branch: the publishing branch from which to generate sites
  • repositoryDir: the directory within home into which all repositories will be cloned
  • generatedSiteDir: the directory within home into which all sites will be generated
  • internalSiteDir: the directory within home into which internal views of sites will be generated

Also, each builders entry may override one or more of the following top-level values:

  • githubOrg
  • pagesConfig
  • pagesYaml
  • secretKeyFile
  • assetRoot

The builders list allows us to run one server to publish both https://pages.18f.gov/ and the authenticated https://pages-staging.18f.gov/.

Branch-specific secret keys

The value within the top-level secretKeyFile will be used to validate all incoming payloads across all branches by default. However, it is possible to configure branch-specific secretKeyFile values, if the payloads corresponding to a particular branch are generated by an additional webhook.

For example, if you want to run one Pages server for more than one GitHub organization, rather than sharing secret keys across organizations, each organization will have its own branch with its own secretKeyFile.

Run the 18f-pages server

After that, run the following to launch the server via Forever, where /path/to/ and /usr/local/bin/ are replaced with the appropriate absolute paths:

$ forever start -l /path/to/pages.log -a /usr/local/bin/18f-pages /path/to/pages-config.json

You can find the absolute path to 18f-pages by running which 18f-pages.

Create a symlink to the index.html of the generated homepage

Follow this example if you wish to publish the homepage of your 18f-pages-server host using 18f-pages-server as well.

The 18F Pages homepage is itself built from the 18F/pages repository. It defines its own _config_18f_pages.yml file so that the baseurl: override described in the additional server-generated Jekyll configuration section does not take place:

baseurl:
asset_root: /guides-template

The homepage is literally a one-page site, but it is still published into a directory called pages. The trick to having it appear at the root of https://pages.18f.gov/ is to manually symlink pages/index.html into its parent directory:

$ ln -s /home/ubuntu/pages-generated/pages/index.html /home/ubuntu/pages-generated/index.html

This symlink-based solution results in the homepage also remaining available at https://pages.18f.gov/pages/, but that hardly seems worth fixing. If avoiding this is a priority for your organization, the homepage can be generated using its own dedicated builder and served via its own dedicated webserver rule. Trying to automate generation of the symlink or to copy the generated homepage file might be another option, but seems riskier and potentially esoteric.

Webserver configuration

The final required step is setting up your webserver to expose the 18f-pages webhook endpoint and to serve the static content generated by the 18f-pages server. The final optional step is setting up an organization-wide webhook once the webserver is configured and running.

The following excerpts are extracted from the complete 18F Pages nginx configuration for https://pages.18f.gov/ and https://pages-staging.18f.gov/. Note how the values match those from the pages-config.json file, explained in the configuration section.

This first excerpt from the https://pages.18f.gov/ server block defines the https://pages.18f.gov/deploy webhook endpoint. This endpoint proxies requests to the 18f-pages server running on port 5000. Note that only one webhook endpoint is required, since the single server instance publishes both https://pages.18f.gov/ and https://pages-staging.18f.gov/.

server {
  listen 443 ssl spdy;
  server_name  pages.18f.gov;
  include ssl/star.18f.gov.conf;

  ...

  location /deploy {
    proxy_pass http://localhost:5000/;
    proxy_http_version 1.1;
    proxy_redirect off;

    proxy_set_header Host   $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_max_temp_file_size 0;

    proxy_connect_timeout 10;
    proxy_send_timeout    30;
    proxy_read_timeout    30;
  }

  ...
}

This second excerpt from the https://pages.18f.gov/ server block corresponds to the first builders entry from pages-config.json:

server {
  listen 443 ssl spdy;
  server_name  pages.18f.gov;
  include ssl/star.18f.gov.conf;

  ...

  location / {
    root   /home/ubuntu/pages-generated;
    index  index.html;
    default_type text/html;
  }

  ...
}

These final server blocks define the authenticated https://pages-staging.18f.gov/ host. The 127.0.0.1:8080 block corresponds to the second builders entry from pages-config.json. Note that this site uses the bitly/oauth2_proxy for authentication, which you can learn more about in the OAuth2 Proxy section of the 18F Hub deployment README.

server {
  listen 443 ssl spdy;
  server_name  pages-staging.18f.gov;
  include ssl/star.18f.gov.conf;

  include vhosts/auth-locations.conf;
}

server {
  listen 127.0.0.1:8080;
  server_name  pages-staging.18f.gov;
  port_in_redirect off;

  location / {
    root  /home/ubuntu/pages-staging;
    index  index.html;
    default_type text/html;
  }
}

Contributing

  1. Fork the repo (or just clone it if you're an 18F team member)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes and test them via npm test or gulp test
  4. Lint your changes with gulp lint
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

Feel free to file an issue or to ping @ertzeid, @jbarnicle, or @mtorres253 with any questions you may have, especially if the current documentation should've addressed your needs, but didn't.

Public domain

This project is in the worldwide public domain. As stated in CONTRIBUTING:

This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.

All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文