Skip to content

Commit

Permalink
Merge pull request #1593 from tidepool-org/in-browser-merged
Browse files Browse the repository at this point in the history
[UPLOAD-1068] Uploader in browser
  • Loading branch information
gniezen committed Jul 29, 2024
2 parents 3a12702 + eeedc4f commit fe45a7a
Show file tree
Hide file tree
Showing 94 changed files with 2,864 additions and 1,675 deletions.
46 changes: 45 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
version: 2
version: 2.1
orbs:
node: circleci/node@5.2.0
jobs:
build-macos:
resource_class: macos.m1.medium.gen1
Expand Down Expand Up @@ -95,6 +97,44 @@ jobs:
# Remove the temporary certificate file
rm -f certificate.p12
build-web:
working_directory: ~/tidepool-org/chrome-uploader
parallelism: 1
# CircleCI 2.0 does not support environment variables that refer to each other the same way as 1.0 did.
# If any of these refer to each other, rewrite them so that they don't or see https://circleci.com/docs/2.0/env-vars/#interpolating-environment-variables-to-set-other-environment-variables .
environment:
HOMEBREW_NO_AUTO_UPDATE: 1
BASH_ENV: ".circleci/bash_env.sh"
DISPLAY: ":99"
docker:
- image: cimg/node:18.17.1-browsers
steps:
- setup_remote_docker:
version: docker23
- run: sudo apt-get update && sudo apt-get install -y build-essential git curl libusb-1.0 libavutil-dev libxss1 libsecret-1-dev libudev-dev libgtk-3-0 libcanberra-gtk3-module packagekit-gtk3-module chromium-browser fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatspi2.0-0 libcairo2 libcups2 libgbm1 libgdk-pixbuf2.0-0 libgtk-3-0 libpango-1.0-0 libpangocairo-1.0-0 libxcursor1 libxss1 xdg-utils xvfb libdbus-glib-1-2 libgtk-3-dev libxt6
- checkout
# - run: mv .nvmrc .nvmrc.tmp
# - node/install:
# install-yarn: true
# node-version: '18.17.1'
# - run: mv .nvmrc.tmp .nvmrc
- run: git submodule sync
- run: git submodule update --init
- run: echo 'export PATH=${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin' >> $BASH_ENV
- restore_cache:
key: dependency-cache-web-{{ checksum "package.json" }}
- run: yarn config set cache-folder ~/.cache/yarn
- run: yarn --frozen-lockfile
- save_cache:
key: dependency-cache-web-{{ checksum "package.json" }}
paths:
- ~/.cache/yarn
- ./node_modules
# Test
- run: yarn lint
- run: Xvfb :99 -screen 0 1280x1024x24 & > /dev/null && yarn test
# Build docker image
- run: if [ -z "$CIRCLE_PR_NUMBER" ]; then ./artifact.sh; else echo "Forked repo; no docker image built."; fi
build-windows:
machine:
image: windows-server-2022-gui:current
Expand Down Expand Up @@ -138,6 +178,10 @@ workflows:
filters:
tags:
only: /^v.*/
- build-web:
filters:
tags:
only: /^v.*/
- build-windows:
filters:
tags:
Expand Down
90 changes: 86 additions & 4 deletions .config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,85 @@
* == BSD2 LICENSE ==
*/

import env from "./app/utils/env";

const serverEnvironments = {
local: {
hosts: ['localhost:3001'],
API_URL: 'http://localhost:8009',
UPLOAD_URL: 'http://localhost:8009',
DATA_URL: 'http://localhost:9220',
BLIP_URL: 'http://localhost:3000'
},
development: {
hosts: ['localhost:31500'],
API_URL: 'http://localhost:31500',
UPLOAD_URL: 'http://localhost:31500',
DATA_URL: 'http://localhost:31500/dataservices',
BLIP_URL: 'http://localhost:31500'
},
dev1: {
hosts: ['dev1.dev.tidepool.org'],
API_URL: 'https://dev1.dev.tidepool.org',
UPLOAD_URL: 'https://dev1.dev.tidepool.org',
DATA_URL: 'https://dev1.dev.tidepool.org/dataservices',
BLIP_URL: 'https://dev1.dev.tidepool.org'
},
qa1: {
hosts: ['qa1.development.tidepool.org', 'dev-app.tidepool.org', 'dev-api.tidepool.org'],
API_URL: 'https://qa1.development.tidepool.org',
UPLOAD_URL: 'https://qa1.development.tidepool.org',
DATA_URL: 'https://qa1.development.tidepool.org/dataservices',
BLIP_URL: 'https://qa1.development.tidepool.org'
},
qa2: {
hosts: ['qa2.development.tidepool.org', 'stg-app.tidepool.org', 'stg-api.tidepool.org'],
API_URL: 'https://qa2.development.tidepool.org',
UPLOAD_URL: 'https://qa2.development.tidepool.org',
DATA_URL: 'https://qa2.development.tidepool.org/dataservices',
BLIP_URL: 'https://qa2.development.tidepool.org'
},
qa3: {
hosts: ['qa3.development.tidepool.org'],
API_URL: 'https://qa3.development.tidepool.org',
UPLOAD_URL: 'https://qa3.development.tidepool.org',
DATA_URL: 'https://qa3.development.tidepool.org/dataservices',
BLIP_URL: 'https://qa3.development.tidepool.org'
},
int: {
hosts: ['external.integration.tidepool.org', 'int-app.tidepool.org', 'int-api.tidepool.org'],
API_URL: 'https://external.integration.tidepool.org',
UPLOAD_URL: 'https://external.integration.tidepool.org',
DATA_URL: 'https://external.integration.tidepool.org/dataservices',
BLIP_URL: 'https://external.integration.tidepool.org'
},
prd: {
hosts: ['app.tidepool.org', 'api.tidepool.org', 'prd-app.tidepool.org', 'prd-api.tidepool.org'],
API_URL: 'https://api.tidepool.org',
UPLOAD_URL: 'https://api.tidepool.org',
DATA_URL: 'https://api.tidepool.org/dataservices',
BLIP_URL: 'https://app.tidepool.org'
},
};

function serverEnvFromLocation() {
const url = new URL(window.location.href);
let host = url.hostname;
if (host === 'localhost') {
host += ':' + url.port;
}
return serverEnvFromHost(host)
}

function serverEnvFromHost(host) {
for (const [server, environment] of Object.entries(serverEnvironments)) {
if (_.includes(environment.hosts, host)) {
return server
}
}
return 'prd';
}

function stringToBoolean(str, defaultValue) {
if (str === 'true') {
return true;
Expand All @@ -32,14 +111,17 @@ function stringToArray(str, defaultValue) {
return str.split(',');
}

const selectedServerEnv = env.browser ? serverEnvFromLocation() : 'prd';

module.exports = {
// this is to always have the Bows logger turned on!
// NB: it is distinct from our own "debug mode"
DEBUG: stringToBoolean(process.env.DEBUG, true),
// the defaults for these need to be pointing to prod
API_URL: process.env.API_URL || 'https://api.tidepool.org',
UPLOAD_URL: process.env.UPLOAD_URL || 'https://uploads.tidepool.org',
DATA_URL: process.env.DATA_URL || 'https://api.tidepool.org/dataservices',
BLIP_URL: process.env.BLIP_URL || 'https://app.tidepool.org',
API_URL: process.env.API_URL || serverEnvironments[selectedServerEnv].API_URL,
UPLOAD_URL: process.env.UPLOAD_URL || serverEnvironments[selectedServerEnv].UPLOAD_URL,
DATA_URL: process.env.DATA_URL || serverEnvironments[selectedServerEnv].DATA_URL,
BLIP_URL: process.env.BLIP_URL || serverEnvironments[selectedServerEnv].BLIP_URL,
DEFAULT_TIMEZONE: process.env.DEFAULT_TIMEZONE || 'America/Los_Angeles',
I18N_ENABLED: stringToBoolean(process.env.I18N_ENABLED, false),
};
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Dockerfile

Dockerfile.dev

docker-compose.yaml

.env
.env
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ lib-cov
pids
logs
results
config/
config/*
!config/local.sh
!config/local.example.js
build
build/Release
.eslintcache
Expand Down
124 changes: 87 additions & 37 deletions Dockerfile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,41 +1,91 @@
FROM ubuntu:18.04
FROM node:18.17.1-alpine as base
WORKDIR /app
RUN mkdir -p dist node_modules .yarn-cache && chown -R node:node .

ENV DEBIAN_FRONTEND noninteractive
ENV NODE_VERSION "v16.14.2"

# Lots of packages. Some dependencies and stuff for GUI.
RUN apt-get -qq -y update && \
apt-get -qq -y install build-essential git curl libusb-1.0 libavutil-dev libxss1 \
libsecret-1-dev libudev-dev libgtk-3-0 libcanberra-gtk3-module packagekit-gtk3-module \
chromium-browser

RUN useradd -s /bin/bash node && mkdir -p /home/node/.config \
&& chown -R node:node /home/node

# Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get -qq -y update && apt-get -qq -y install yarn

# Node
RUN curl -O https://nodejs.org/download/release/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.gz \
&& tar -xzf node-$NODE_VERSION-linux-x64.tar.gz -C /usr/local/bin

ENV PATH=/usr/local/bin/node-$NODE_VERSION-linux-x64/bin:${PATH}

RUN chown -R node:$(id -gn node) /home/node/.config

WORKDIR /home/node

RUN mkdir uploader

ENV NODE_ENV "development"

WORKDIR /home/node/uploader/

COPY entrypoint.sh entrypoint.sh
FROM base as build
ARG API_URL
ARG UPLOAD_URL
ARG DATA_URL
ARG BLIP_URL
ARG REALM_HOST
ARG PORT=3001
ARG SERVICE_NAME=uploader
ARG ROLLBAR_POST_SERVER_TOKEN
ARG I18N_ENABLED=false
ARG RX_ENABLED=false
ARG PENDO_ENABLED=true
ARG TRAVIS_COMMIT
# Set ENV from ARGs
ENV \
API_URL=$API_URL \
UPLOAD_URL=$UPLOAD_URL \
DATA_URL=$DATA_URL \
BLIP_URL=$BLIP_URL \
REALM_HOST=$REALM_HOST \
PORT=$PORT \
SERVICE_NAME=$SERVICE_NAME \
ROLLBAR_POST_TOKEN=$ROLLBAR_POST_SERVER_TOKEN \
I18N_ENABLED=$I18N_ENABLED \
RX_ENABLED=$RX_ENABLED \
PENDO_ENABLED=$PENDO_ENABLED \
TRAVIS_COMMIT=$TRAVIS_COMMIT \
NODE_ENV=development

# Install dependancies
RUN \
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk --no-cache update \
&& apk --no-cache upgrade \
&& apk add --no-cache --virtual .build-deps alpine-sdk python3 linux-headers eudev-dev ffmpeg-dev \
&& rm -rf /var/cache/apk/* /tmp/*
USER node
RUN mkdir -p /home/node/.yarn-cache /home/node/.cache/yarn
COPY --chown=node:node package.json yarn.lock ./
RUN --mount=type=cache,target=/home/node/.yarn-cache,id=yarn,uid=1000,gid=1000 yarn install --ignore-scripts --cache-folder /home/node/.yarn-cache
# Copy source files, and possibily invalidate so we have to rebuild
COPY --chown=node:node . .
RUN npm run build-web
USER root
RUN apk del .build-deps

ENTRYPOINT ["/bin/bash", "entrypoint.sh"]
FROM base as production
ARG API_URL
ARG UPLOAD_URL
ARG DATA_URL
ARG BLIP_URL
ARG REALM_HOST
ARG PORT=3001
ARG SERVICE_NAME=uploader
ARG ROLLBAR_POST_SERVER_TOKEN
ARG I18N_ENABLED=false
ARG RX_ENABLED=false
ARG PENDO_ENABLED=true
ARG TRAVIS_COMMIT
# Set ENV from ARGs
ENV \
API_URL=$API_URL \
UPLOAD_URL=$UPLOAD_URL \
DATA_URL=$DATA_URL \
BLIP_URL=$BLIP_URL \
REALM_HOST=$REALM_HOST \
PORT=$PORT \
SERVICE_NAME=$SERVICE_NAME \
ROLLBAR_POST_TOKEN=$ROLLBAR_POST_SERVER_TOKEN \
I18N_ENABLED=$I18N_ENABLED \
RX_ENABLED=$RX_ENABLED \
PENDO_ENABLED=$PENDO_ENABLED \
TRAVIS_COMMIT=$TRAVIS_COMMIT \
NODE_ENV=production
# Only install dependancies needed for the production server
USER node
RUN yarn add express@4.16.3 helmet@7.0.0 body-parser@1.18.3
# Copy only files needed to run the server
COPY --from=build /app/dist dist
COPY --from=build \
/app/config.server.js \
/app/package.json \
/app/server.js \
./
CMD ["node", "server.js"]
41 changes: 41 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM ubuntu:18.04

ENV DEBIAN_FRONTEND noninteractive
ENV NODE_VERSION "v12.13.0"

# Lots of packages. Some dependencies and stuff for GUI.
RUN apt-get -qq -y update && \
apt-get -qq -y install build-essential git curl libusb-1.0 libavutil-dev libxss1 \
libsecret-1-dev libudev-dev libgtk-3-0 libcanberra-gtk3-module packagekit-gtk3-module \
chromium-browser

RUN useradd -s /bin/bash node && mkdir -p /home/node/.config \
&& chown -R node:node /home/node

# Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -

RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get -qq -y update && apt-get -qq -y install yarn

# Node
RUN curl -O https://nodejs.org/download/release/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.gz \
&& tar -xzf node-$NODE_VERSION-linux-x64.tar.gz -C /usr/local/bin

ENV PATH=/usr/local/bin/node-$NODE_VERSION-linux-x64/bin:${PATH}

RUN chown -R node:$(id -gn node) /home/node/.config

WORKDIR /home/node

RUN mkdir uploader

ENV NODE_ENV "development"

WORKDIR /home/node/uploader/

COPY entrypoint.sh entrypoint.sh

USER node

ENTRYPOINT ["/bin/bash", "entrypoint.sh"]
Loading

0 comments on commit fe45a7a

Please sign in to comment.