From 689b6b571fc59747b3ed127e9cf5e8ca62c95fb2 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Wed, 2 Sep 2020 14:18:46 -0600 Subject: [PATCH] updated deploy files (#1387) --- .circleci/config.yml | 2 +- deploy/README.md | 4 +- deploy/docs-website.yml | 147 ++------------------------------------- deploy/edge.js | 2 +- deploy/remove-lambda.yml | 23 ------ 5 files changed, 8 insertions(+), 170 deletions(-) delete mode 100644 deploy/remove-lambda.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index a6e89ba70..41d12b9e2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ jobs: - image: circleci/node:erbium environment: HUGO_VERSION: "0.59.1" - S3DEPLOY_VERSION: "2.3.2" + S3DEPLOY_VERSION: "2.3.5" steps: - checkout - restore_cache: diff --git a/deploy/README.md b/deploy/README.md index 66b32c8ca..d232f275c 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -7,10 +7,10 @@ aws cloudformation deploy \ --template-file deploy/docs-website.yml \ --stack-name="${STACK_NAME}" \ --capabilities CAPABILITY_IAM \ - --no-execute-changeset \ --parameter-overrides \ AcmCertificateArn="${ACM_ARN}" \ DomainName="${DOMAIN_NAME}" ``` -The `--no-execute-changeset` option will display the actions that will be taken. Remove the `--no-execute-changeset` option to actually deploy a change. +To only display actions that will be taken, in the `--no-execute-changeset` option. +Without this option, the command executes and deploys the changeset. diff --git a/deploy/docs-website.yml b/deploy/docs-website.yml index 5b1bd94e5..7ce71edf7 100644 --- a/deploy/docs-website.yml +++ b/deploy/docs-website.yml @@ -126,152 +126,13 @@ Resources: ZipFile: | 'use strict'; - const path = require('path'); + // This is a a placeholder lambda function. Use the AWS Lambda console + // to add/update the contents of deploy/edge.js to the actual Lambda + // function and deploy it to Lambda@Edge - const latestVersions = { - 'influxdb': 'v1.8', - 'influxdbv2': 'v2.0', - 'telegraf': 'v1.15', - 'chronograf': 'v1.8', - 'kapacitor': 'v1.5', - 'enterprise': 'v1.8', - }; - - const archiveDomain = 'http://archive.docs.influxdata.com'; + const { request } = event.Records[0].cf; exports.handler = (event, context, callback) => { - - function temporaryRedirect(condition, newUri) { - if (condition) { - return callback(null, { - status: '302', - statusDescription: 'Found', - headers: { - location: [{ - key: 'Location', - value: newUri, - }], - } - }); - } - } - - function permanantRedirect(condition, newUri) { - if (condition) { - return callback(null, { - status: '301', - statusDescription: 'Moved Permanently', - headers: { - 'location': [{ - key: 'Location', - value: newUri, - }], - 'cache-control': [{ - key: 'Cache-Control', - value: "max-age=3600" - }], - }, - }); - } - } - - const { request } = event.Records[0].cf; - const parsedPath = path.parse(request.uri); - const indexPath = 'index.html'; - const validExtensions = { - '.html': true, - '.css': true, - '.js': true, - '.xml': true, - '.png': true, - '.gif': true, - '.jpg': true, - '.ico': true, - '.svg': true, - '.csv': true, - '.txt': true, - '.lp': true, - '.json': true, - '.rb': true, - '.eot': true, - '.ttf': true, - '.woff': true, - '.otf': true, - }; - - // Remove index.html from path - permanantRedirect(request.uri.endsWith('index.html'), request.uri.substr(0, request.uri.length - indexPath.length)); - - // If file has a valid extension, return the request unchanged - if (validExtensions[parsedPath.ext]) { - callback(null, request); - } - - ////////////////////// START PRODUCT-SPECIFIC REDIRECTS ////////////////////// - - //////////////////////////// v2 subdomain redirect /////////////////////////// - permanantRedirect(request.headers.host[0].value === 'v2.docs.influxdata.com', `https://docs.influxdata.com${request.uri}`); - - ////////////////////////// Latest version redirects ////////////////////////// - temporaryRedirect(/\/influxdb\/latest/.test(request.uri), request.uri.replace(/\/latest/, `/${latestVersions['influxdb']}`)); - temporaryRedirect(/\/telegraf\/latest/.test(request.uri), request.uri.replace(/\/latest/, `/${latestVersions['telegraf']}`)); - temporaryRedirect(/\/chronograf\/latest/.test(request.uri), request.uri.replace(/\/latest/, `/${latestVersions['chronograf']}`)); - temporaryRedirect(/\/kapacitor\/latest/.test(request.uri), request.uri.replace(/\/latest/, `/${latestVersions['kapacitor']}`)); - temporaryRedirect(/\/enterprise_influxdb\/latest/.test(request.uri), request.uri.replace(/\/latest/, `/${latestVersions['enterprise']}`)); - - ////////////////////////// Versionless URL redirects ///////////////////////// - temporaryRedirect(request.uri === '/influxdb/', `/influxdb/${latestVersions['influxdb']}/`); - temporaryRedirect(request.uri === '/telegraf/', `/telegraf/${latestVersions['telegraf']}/`); - temporaryRedirect(request.uri === '/chronograf/', `/chronograf/${latestVersions['chronograf']}/`); - temporaryRedirect(request.uri === '/kapacitor/', `/kapacitor/${latestVersions['kapacitor']}/`); - temporaryRedirect(request.uri === '/enterprise_influxdb/', `/enterprise_influxdb/${latestVersions['enterprise']}/`); - - /////////////////////////////// Flux redirects /////////////////////////////// - // Redirect flux guides and introduction based on latest InfluxDB version - if (/v2/.test(latestVersions['influxdb'])) { - temporaryRedirect(/\/flux\/v0\.[0-9]{1,2}\/guides\//.test(request.uri), request.uri.replace(/\/flux\/v0\.[0-9]{1,2}\/guides\//, `/influxdb/${latestVersions['influxdb']}/query-data/flux/`)); - temporaryRedirect(/\/flux\/v0\.[0-9]{1,2}\/guides\//.test(request.uri), request.uri.replace(/\/flux\/v0\.[0-9]{1,2}\/introduction\//, `/influxdb/${latestVersions['influxdb']}/query-data/get-started/`)); - } else { - temporaryRedirect(/\/flux\/v0\.[0-9]{1,2}\/guides\//.test(request.uri), request.uri.replace(/\/flux\/v0\.[0-9]{1,2}\/guides\//, `/influxdb/${latestVersions['influxdb']}/flux/guides/`)); - temporaryRedirect(/\/flux\/v0\.[0-9]{1,2}\/guides\//.test(request.uri), request.uri.replace(/\/flux\/v0\.[0-9]{1,2}\/introduction\//, `/influxdb/${latestVersions['influxdb']}/flux/introduction/`)); - } - // Redirect Flux stdlib and language sections to v2 Flux docs - temporaryRedirect(/\/flux\/v0\.[0-9]{1,2}\/(?:functions|stdlib|language)\//.test(request.uri), request.uri.replace(/\/flux\/v0\.[0-9]{1,2}\//, `/influxdb/${latestVersions['influxdbv2']}/reference/flux/`)); - - // Redirect versionless and base version to v2 Flux docs - temporaryRedirect(/^\/flux\/(?:v0\.[0-9]{1,2}\/|)$/.test(request.uri), `/influxdb/${latestVersions['influxdbv2']}/reference/flux/`); - - ////////////////////////////// v2 path redirect ////////////////////////////// - permanantRedirect(/^\/v2\.0\//.test(request.uri), request.uri.replace(/^\/v2\.0\//, `/influxdb/v2.0/`)); - - ////////////////////////// Archive version redirects ///////////////////////// - permanantRedirect(/\/influxdb\/(?:v0\.[0-9]{1,2}|v1\.[0-2])\//.test(request.uri), `${archiveDomain}${request.uri}`); - permanantRedirect(/\/telegraf\/(?:v0\.[0-9]{1,2}|v1\.[0-8])\//.test(request.uri), `${archiveDomain}${request.uri}`); - permanantRedirect(/\/chronograf\/(?:v0\.[0-9]{1,2}|v1\.[0-5])\//.test(request.uri), `${archiveDomain}${request.uri}`); - permanantRedirect(/\/kapacitor\/(?:v0\.[0-9]{1,2}|v1\.[0-3])\//.test(request.uri), `${archiveDomain}${request.uri}`); - permanantRedirect(/\/enterprise_influxdb\/v1\.[0-3]\//.test(request.uri), `${archiveDomain}${request.uri}`); - permanantRedirect(/\/enterprise_kapacitor\//.test(request.uri), `${archiveDomain}${request.uri}`); - - /////////////////////// END PRODUCT-SPECIFIC REDIRECTS /////////////////////// - - // Redirect to the a trailing slash - permanantRedirect(!request.uri.endsWith('/'), request.uri + '/'); - - // Use index.html if the path doesn't have an extension - // or if the version number is parsed as an extension. - let newUri; - - if (parsedPath.ext === '' || /\.\d*/.test(parsedPath.ext)) { - newUri = path.join(parsedPath.dir, parsedPath.base, indexPath); - } else { - newUri = request.uri; - } - - // Replace the received URI with the URI that includes the index page - request.uri = newUri; - - // Return to CloudFront - // request.uri = request.uri + indexPath; callback(null, request); }; diff --git a/deploy/edge.js b/deploy/edge.js index eff75890e..767b86778 100644 --- a/deploy/edge.js +++ b/deploy/edge.js @@ -147,4 +147,4 @@ exports.handler = (event, context, callback) => { // Return to CloudFront // request.uri = request.uri + indexPath; callback(null, request); -}; \ No newline at end of file +}; diff --git a/deploy/remove-lambda.yml b/deploy/remove-lambda.yml deleted file mode 100644 index 7e0be9c5b..000000000 --- a/deploy/remove-lambda.yml +++ /dev/null @@ -1,23 +0,0 @@ -############################################################################### -### AWS Cloudformation Template -### InfluxData Documentation Website Hosting and Deployment -############################################################################### -AWSTemplateFormatVersion: 2010-09-09 -############################################################################### -Resources: -############################################################################### - DocsOriginRequestRewriteLambdaRole: - Type: AWS::IAM::Role - Properties: - RoleName: test1-DocsOriginRequestRewriteLambdaRole-10RT8O6PQO2ZE - AssumeRolePolicyDocument: - Version: 2012-10-17 - Statement: - - Effect: Allow - Action: sts:AssumeRole - Principal: - Service: - - edgelambda.amazonaws.com - - lambda.amazonaws.com - ManagedPolicyArns: - - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole