Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hard-coded "sheet" URL to be passed at build time #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
FROM nginx:1.23.0

RUN apt-get update && apt-get upgrade -y

RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs
FROM node:18 AS build

RUN \
apt-get install -y \
libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 \
libxss1 libasound2 libxtst6 xauth xvfb g++ make
ARG SHEET_ID
ARG SHEET_NAME

WORKDIR /src/build-your-own-radar
COPY package.json ./
RUN npm install

COPY . ./

# Override parent node image's entrypoint script (/usr/local/bin/docker-entrypoint.sh),
# which tries to run CMD as a node command
ENTRYPOINT []
CMD ["./build_and_start_nginx.sh"]
RUN npm test && npm run build:prod

FROM nginx:1.23.0

COPY --from=build /src/build-your-own-radar/dist /opt/build-your-own-radar
COPY default.template /etc/nginx/conf.d/default.conf
CMD nginx -g 'daemon off;'
13 changes: 11 additions & 2 deletions src/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ require('./images/logo.png')
require('./images/radar_legend.png')
require('./gtm.js')

const GoogleSheetInput = require('./util/factory')
const RadarInput = require('./util/factory')

GoogleSheetInput().build()
if (process.env.SHEET_ID) {
RadarInput().build(process.env.SHEET_ID, process.env.SHEET_NAME)
} else {
const QueryParams = require('./util/queryParamProcessor')

var queryString = window.location.href.match(/sheetId(.*)/)
var queryParams = queryString ? QueryParams(queryString[0]) : {}

RadarInput().build(queryParams.sheetId, queryParams.sheetName)
}
32 changes: 11 additions & 21 deletions src/util/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const CSVDocument = function (url) {
return self
}

const JSONFile = function (url) {
const JSONFile = function (url, title) {
var self = {}

self.build = function () {
Expand All @@ -180,7 +180,7 @@ const JSONFile = function (url) {
contentValidator.verifyContent()
contentValidator.verifyHeaders()
var blips = _.map(data, new InputSanitizer().sanitize)
plotRadar(FileName(url), blips, 'JSON File', [])
plotRadar(title || FileName(url), blips, 'JSON File', [])
} catch (exception) {
plotErrorMessage(exception, 'json')
}
Expand All @@ -194,12 +194,6 @@ const JSONFile = function (url) {
return self
}

const DomainName = function (url) {
var search = /.+:\/\/([^\\/]+)/
var match = search.exec(decodeURIComponent(url.replace(/\+/g, ' ')))
return match == null ? null : match[1]
}

const FileName = function (url) {
var search = /([^\\/]+)$/
var match = search.exec(decodeURIComponent(url.replace(/\+/g, ' ')))
Expand All @@ -210,23 +204,19 @@ const FileName = function (url) {
return url
}

const GoogleSheetInput = function () {
const RadarInput = function () {
var self = {}
var sheet

self.build = function () {
var domainName = DomainName(window.location.search.substring(1))
var queryString = window.location.href.match(/sheetId(.*)/)
var queryParams = queryString ? QueryParams(queryString[0]) : {}

if (queryParams.sheetId && queryParams.sheetId.endsWith('.csv')) {
sheet = CSVDocument(queryParams.sheetId)
self.build = function (sheetId, sheetName) {
if (sheetId && sheetId.endsWith('.csv')) {
sheet = CSVDocument(sheetId)
sheet.init().build()
} else if (queryParams.sheetId && queryParams.sheetId.endsWith('.json')) {
sheet = JSONFile(queryParams.sheetId)
} else if (sheetId && sheetId.endsWith('.json')) {
sheet = JSONFile(sheetId, sheetName)
sheet.init().build()
} else if (domainName && domainName.endsWith('google.com') && queryParams.sheetId) {
sheet = GoogleSheet(queryParams.sheetId, queryParams.sheetName)
} else if (sheetId && sheetName) {
sheet = GoogleSheet(sheetId, sheetName)

sheet.init().build()
} else {
Expand Down Expand Up @@ -437,4 +427,4 @@ function plotUnauthorizedErrorMessage() {
})
}

module.exports = GoogleSheetInput
module.exports = RadarInput
6 changes: 5 additions & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (env) {
}

const common = ['./src/common.js']
const main = ['./src/site.js']

const ASSET_PATH = process.env.ASSET_PATH || '/'

Expand All @@ -38,13 +39,16 @@ const plugins = [
'process.env.API_KEY': JSON.stringify(process.env.API_KEY),
'process.env.ENABLE_GOOGLE_AUTH': JSON.stringify(process.env.ENABLE_GOOGLE_AUTH),
'process.env.GTM_ID': JSON.stringify(process.env.GTM_ID),
'process.env.SHEET_ID': JSON.stringify(process.env.SHEET_ID),
'process.env.SHEET_NAME': JSON.stringify(process.env.SHEET_NAME),
}),
]

module.exports = {
context: __dirname,
entry: {
common: common,
common,
main,
},

output: {
Expand Down
2 changes: 0 additions & 2 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const path = require('path')
const webpack = require('webpack')
const main = ['./src/site.js']
const fs = require('fs')
const config = require('./src/config')['development']
const featureTogglesList = Object.keys(config.featureToggles)
Expand All @@ -14,7 +13,6 @@ fs.writeFileSync(path.join(__dirname, './src/stylesheets/_featuretoggles.scss'),

module.exports = merge(common, {
mode: 'development',
entry: { main: main },
performance: {
hints: false,
},
Expand Down
2 changes: 0 additions & 2 deletions webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const path = require('path')
const webpack = require('webpack')
const main = ['./src/site.js']
const fs = require('fs')
const config = require('./src/config')['production']
const featureTogglesList = Object.keys(config.featureToggles)
Expand All @@ -12,7 +11,6 @@ fs.writeFileSync(path.join(__dirname, './src/stylesheets/_featuretoggles.scss'),

module.exports = merge(common, {
mode: 'production',
entry: { main },
performance: {
hints: false,
},
Expand Down