Skip to content

Commit

Permalink
Include remaining static resources in preview (elastic#1227)
Browse files Browse the repository at this point in the history
Includes the last static resources used by the air_gapped_template. Now
air gapped docs shouldn't redirect to production at all.
  • Loading branch information
nik9000 authored Sep 30, 2019
1 parent 73157ea commit 522a6b3
Show file tree
Hide file tree
Showing 31 changed files with 148 additions and 21 deletions.
2 changes: 1 addition & 1 deletion air_gapped/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.elastic.co/docs/preview:8
FROM docker.elastic.co/docs/preview:9

COPY air_gapped/work/target_repo.git /docs_build/.repos/target_repo.git

Expand Down
2 changes: 1 addition & 1 deletion air_gapped/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ GIT_DIR=air_gapped/work/target_repo.git git fetch

# Build the images
./build_docs --just-build-image
docker build -t docker.elastic.co/docs/preview:8 -f preview/Dockerfile .
docker build -t docker.elastic.co/docs/preview:9 -f preview/Dockerfile .
# Use buildkit here to pick up the customized dockerignore file
DOCKER_BUILDKIT=1 docker build -t docker.elastic.co/docs-private/air_gapped:latest -f air_gapped/Dockerfile .
2 changes: 2 additions & 0 deletions integtest/spec/all_books_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ def self.setup_example(repo, lang, hash)
Net::HTTP.get_response(URI("#{book_root}/resources/readme/example.svg"))
end

include_examples 'the favicon'

it 'serves the root index' do
expect(root_index).to serve(doc_body(include(<<~HTML.strip)))
<a class="ulink" href="test/current/index.html" target="_top">Test
Expand Down
15 changes: 15 additions & 0 deletions integtest/spec/helper/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'net/http'

require_relative 'dsl/convert_all'
require_relative 'dsl/convert_single'
require_relative 'dsl/file_contexts'
Expand Down Expand Up @@ -41,6 +43,19 @@ def dest_file(file)
end
end

RSpec.shared_examples 'the favicon' do
context 'the favicon' do
let(:favicon) do
Net::HTTP.get_response(URI('http://localhost:8000/favicon.ico'))
end
let(:path) { '/docs_build/resources/web/static/favicon.ico' }
let(:expected_bits) { File.open dest_file(path), 'rb', &:read }
it 'serves the favicon' do
expect(favicon).to serve(eq(expected_bits))
end
end
end

include ConvertAll
include ConvertSingle
include FileContexts
Expand Down
1 change: 1 addition & 0 deletions integtest/spec/preview_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def get(watermark, branch, path)
it 'logs that the built docs are ready' do
wait_for_logs(/Built docs are ready/)
end
include_examples 'the favicon'

shared_examples 'serves some docs' do |supports_gapped: true|
context 'the docs root' do
Expand Down
2 changes: 2 additions & 0 deletions integtest/spec/single_book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ def self.convert_with_source_branch_before_context(branch)
Net::HTTP.get_response(URI("#{static}/styles.css"))
end

include_examples 'the favicon'

context 'the index' do
context 'when not air gapped' do
it 'contains the gtag js' do
Expand Down
30 changes: 17 additions & 13 deletions lib/ES/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -742,15 +742,6 @@ CONF
add_header 'Access-Control-Allow-Headers' 'kbn-xsrf-token';
}
}
types {
application/javascript js;
image/gif gif;
image/jpeg jpg;
image/jpeg jpeg;
image/svg+xml svg;
text/css css;
text/html html;
}
CONF
}

Expand All @@ -772,9 +763,20 @@ http {
listen 8000;
$web_conf
$guide_conf
rewrite ^/android-chrome-(.+)\$ https://www.elastic.co/android-chrome-\$1 permanent;
location / {
alias /docs_build/resources/web/static/;
autoindex off;
}
types {
application/javascript js;
image/gif gif;
image/jpeg jpg;
image/jpeg jpeg;
image/svg+xml svg;
text/css css;
text/html html;
}
rewrite ^/assets/(.+)\$ https://www.elastic.co/assets/\$1 permanent;
rewrite ^/favicon(.+)\$ https://www.elastic.co/favicon\$1 permanent;
rewrite ^/gdpr-data\$ https://www.elastic.co/gdpr-data permanent;
rewrite ^/static/(.+)\$ https://www.elastic.co/static/\$1 permanent;
$redirects_line
Expand Down Expand Up @@ -833,9 +835,11 @@ http {
add_header 'Access-Control-Allow-Headers' 'kbn-xsrf-token';
}
}
rewrite ^/android-chrome-(.+)\$ https://www.elastic.co/android-chrome-\$1 permanent;
location / {
alias /docs_build/resources/web/static/;
autoindex off;
}
rewrite ^/assets/(.+)\$ https://www.elastic.co/assets/\$1 permanent;
rewrite ^/favicon(.+)\$ https://www.elastic.co/favicon\$1 permanent;
rewrite ^/gdpr-data\$ https://www.elastic.co/gdpr-data permanent;
rewrite ^/static/(.+)\$ https://www.elastic.co/static/\$1 permanent;
}
Expand Down
4 changes: 2 additions & 2 deletions preview/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ set -e

cd $(git rev-parse --show-toplevel)
../infra/ansible/roles/git_fetch_reference/files/git-fetch-reference.sh built-docs.git
docker build -t docker.elastic.co/docs/preview:8 -f preview/Dockerfile .
docker build -t docker.elastic.co/docs/preview:9 -f preview/Dockerfile .
id=$(docker run --rm \
--publish 8000:8000/tcp \
-v $HOME/.git-references:/root/.git-references \
-d \
docker.elastic.co/docs/preview:8 \
docker.elastic.co/docs/preview:9 \
/docs_build/build_docs.pl --in_standard_docker \
--preview --reference /root/.git-references \
--target_repo https://github.com/elastic/built-docs.git)
Expand Down
2 changes: 1 addition & 1 deletion publish_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

export BUILD=docker.elastic.co/docs/build:1
export PREVIEW=docker.elastic.co/docs/preview:8
export PREVIEW=docker.elastic.co/docs/preview:9

cd $(git rev-parse --show-toplevel)
./build_docs --just-build-image
Expand Down
2 changes: 1 addition & 1 deletion resources/web/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_watch: tests

.PHONY: jest
jest: tests
/node_modules/jest/bin/jest.js ./tests/**
/node_modules/jest/bin/jest.js ./tests/** ./__test__/**

.PHONY: tests
tests:
Expand Down
64 changes: 64 additions & 0 deletions resources/web/__test__/air_gapped_template.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @license
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

'use strict';

const fs = require('fs');
const { promisify } = require('util');

const readdir = promisify(fs.readdir);
const readFile = promisify(fs.readFile);

describe("air_gapped_template.html", () => {
let template;
beforeAll(async () => {
template = await readFile("air_gapped_template.html", {encoding: "utf8"});
});
describe("links", () => {
/**
* Outgoing links from the template.
*/
let links;
beforeAll(() => {
links = Array.from(new Set([...template.matchAll(/(?:href|src)="([^"]+)"/g)].map(m => m[1]))).sort();
});
/**
* Resources that we compile or otherwise manipulate on the way into
* the built-docs repo.
*/
const compiledWebResources = [
"/guide/static/styles.css",
"/guide/static/docs.js",
"/guide/static/jquery.js"
];
/**
* Resources that are statically served from the preview app.
*/
let staticResources;
beforeAll(async () => {
staticResources = (await readdir("static")).map(e => `/${e}`);
});

it("to expected resources", () => {
const allResources = ["/guide/", ...compiledWebResources, ...staticResources].sort();
expect(links).toEqual(allResources);
});
});
});
1 change: 0 additions & 1 deletion resources/web/air_gapped_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#ffffff">
<meta name="apple-mobile-web-app-title" content="Elastic">
<meta name="application-name" content="Elastic">
<meta name="msapplication-TileColor" content="#ffffff">
Expand Down
Binary file added resources/web/static/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-114x114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-57x57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/apple-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/favicon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/favicon.ico
Binary file not shown.
Binary file added resources/web/static/favicon_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/favicon_32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/web/static/favicon_64x64_16bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions resources/web/static/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "App",
"icons": [
{
"src": "\/android-icon-36x36.png",
"sizes": "36x36",
"type": "image\/png",
"density": "0.75"
},
{
"src": "\/android-icon-48x48.png",
"sizes": "48x48",
"type": "image\/png",
"density": "1.0"
},
{
"src": "\/android-icon-72x72.png",
"sizes": "72x72",
"type": "image\/png",
"density": "1.5"
},
{
"src": "\/android-icon-96x96.png",
"sizes": "96x96",
"type": "image\/png",
"density": "2.0"
},
{
"src": "\/android-icon-144x144.png",
"sizes": "144x144",
"type": "image\/png",
"density": "3.0"
},
{
"src": "\/android-icon-192x192.png",
"sizes": "192x192",
"type": "image\/png",
"density": "4.0"
}
]
}
1 change: 0 additions & 1 deletion resources/web/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#ffffff">
<meta name="apple-mobile-web-app-title" content="Elastic">
<meta name="application-name" content="Elastic">
<meta name="msapplication-TileColor" content="#ffffff">
Expand Down

0 comments on commit 522a6b3

Please sign in to comment.