Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into overview-change-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Oct 1, 2024
2 parents af6432a + 7afbde2 commit a89e851
Show file tree
Hide file tree
Showing 94 changed files with 1,122 additions and 1,669 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
build
dist
node_modules
server.env
www
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:react-hooks/recommended',
'plugin:react/jsx-runtime',
],
rules: {
'react/prop-types': 'off', // disable prop-types since we're using TypeScript
Expand All @@ -38,6 +39,7 @@ module.exports = {
},
],
semi: ['error', 'always'],
'react/react-in-jsx-scope': 'off',
},
settings: {
react: {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v4

- name: Run Bento build action
uses: bento-platform/bento_build_action@v0.11.1
uses: bento-platform/bento_build_action@v1.0.0
with:
registry: ghcr.io
registry-username: ${{ github.actor }}
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
client.env
server.env

build/*
node_modules/*
dist/*
.DS_Store
.prettierrc
.idea/
.vscode/
www/
Expand Down
75 changes: 42 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
FROM --platform=$BUILDPLATFORM node:20-bookworm-slim as nodebuilder
FROM --platform=$BUILDPLATFORM node:20-bookworm-slim AS build

WORKDIR /node
# Build bento_public with NodeJS + Webpack
# - Use BUILDPLATFORM for running webpack, since it should perform a lot better.
# - Then, the resulting built files will be copied to a TARGETPLATFORM-based final image.

WORKDIR /bento-public

# Install using just package-lock.json with npm ci
COPY package.json .
COPY package-lock.json .

RUN npm ci

# Build the web application
COPY tsconfig.json .
# Explicitly choose what to copy to speed up builds
# - Copy in build requirements
COPY create_service_info.js .
COPY webpack.config.js .
COPY tsconfig.json .
# - Copy in source code
COPY src src
RUN mkdir -p build/www
RUN npm run build


FROM golang:1.21-bookworm as gobuilder

RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y git

WORKDIR /build

# Only copy the files that are needed!
COPY go.mod .
COPY go.sum .
COPY main.go .
RUN npm run build

RUN go build -o ./reactapp
FROM nginx:1.26

# Install node so that we can run the create_config_prod.js & create_service_info.js scripts
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get update -y && \
apt-get install -y ca-certificates curl gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | \
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | \
tee /etc/apt/sources.list.d/nodesource.list && \
apt-get install -y nodejs && \
rm -rf /var/lib/apt/lists/*

FROM ghcr.io/bento-platform/bento_base_image:node-debian-2024.07.09
# Serve bento_public with NGINX; copy in configuration
COPY nginx.conf /etc/nginx/nginx.conf

ENV BENTO_PUBLIC_PACKAGE_JSON_PATH=/bento-public/package.json
WORKDIR /bento-public

COPY entrypoint.bash .
COPY package.json .
# In general, we want to copy files in order of least -> most changed for layer caching reasons.

# - Copy in LICENSE so that people can see it if they explore the image contents
COPY LICENSE .
# - Copy in the production config generation script
COPY create_config_prod.js .
# - Copy in the service info generator
COPY create_service_info.js .
# - Copy in the entrypoint, which writes the config file and starts NGINX
COPY run.bash .
# - Copy in package.json to provide version to scripts
COPY package.json .
# - Copy webpack-built source code from the build stage to the final image
# - copy this last, since it changes more often than everything above it
# - this way we can cache layers
COPY --from=build /bento-public/dist ./dist

# Copy web app
COPY --from=nodebuilder /node/build/www /bento-public/www

# Copy server
COPY --from=gobuilder /build/reactapp /bento-public/reactapp

ENTRYPOINT [ "/bin/bash", "./entrypoint.bash" ]
CMD [ "/bin/bash", "./run.bash" ]
CMD ["bash", "./run.bash"]
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,10 @@
A publicly accessible portal for clinical datasets, where users are able to see high-level statistics of the data
available through predefined variables of interest and search the data using limited variables at a time. This portal
allows users to gain a generic understanding of the data available (secure and firewalled) without the need to access
it directly. Initially, this portal facilitates the search in English language only, but the French language will be
added at a later time.
it directly.

## Prerequisites:
- Node Package Manager
- Go version >= 1.19

## Getting started:

First, run
```bash
cp etc/example.server.env server.env
```
and modify the contents according to your needs.

If needed, install the relevant Go dependencies:

```bash
go mod download
```

Finally, install the NPM dependencies and run the build process:
```bash
npm install
npm run gobuild
```

## Translations in dev mode
Add your English to French translations in `www/public/locales/fr/translation_fr.json` for them to appear on the website.
17 changes: 0 additions & 17 deletions buildandrun.sh

This file was deleted.

2 changes: 1 addition & 1 deletion create_config_prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const parseBoolean = (value) => ['true', '1', 'yes'].includes((value || '').toLocaleLowerCase());
const parseBoolean = (value) => ['true', 't', '1', 'yes'].includes((value || '').toLocaleLowerCase());

const siteConfig = {
CLIENT_NAME: process.env.BENTO_PUBLIC_CLIENT_NAME || null,
Expand Down
59 changes: 59 additions & 0 deletions create_service_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const childProcess = require('child_process');
const packageData = require('./package.json');

const nodeEnv = process.env.NODE_ENV || 'production';

const serviceType = {
group: 'ca.c3g.bento',
artifact: 'public',
version: packageData.version,
};

const serviceID = process.env.SERVICE_ID || `${serviceType.group}:${serviceType.artifact}`;

const serviceInfo = {
id: serviceID,
name: 'Bento Public',
description: 'Public web interface for the Bento platform.',
type: serviceType,
version: packageData.version,
environment: nodeEnv === 'production' ? 'prod' : 'dev',
organization: {
name: 'C3G',
url: 'https://www.computationalgenomics.ca',
},
contactUrl: 'mailto:[email protected]',
bento: {
serviceKind: 'public',
},
};

const hasGit = (() => {
try {
return childProcess.execSync('which git').toString().trim() === '';
} catch (_e) {
// Exit code 1 (git not found)
return false;
}
})();
const git = (cmd) => childProcess.execSync(`git ${cmd}`).toString().trim();
if (nodeEnv === 'development' && hasGit) {
try {
serviceInfo.bento.gitTag = git('describe --tags --abbrev=0');
serviceInfo.bento.gitBranch = git('branch --show-current');
serviceInfo.bento.gitCommit = git('rev-parse HEAD');
} catch (e) {
console.warn(`Could not get git information (${e})`);
}
} else if (!hasGit) {
console.warn('Could not get git information (missing git)');
}

if (typeof require !== 'undefined' && require.main === module) {
console.log(JSON.stringify(serviceInfo, null, 2));
}

module.exports = {
serviceInfo,
};
28 changes: 10 additions & 18 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
FROM ghcr.io/bento-platform/bento_base_image:node-debian-2024.07.09

RUN apt-get update -y && \
apt-get install -y ca-certificates

# Use bookworm-backports to get go 1.21 instead of 1.19
# Install lsof to help killing the PID binding the port if needed
RUN echo "deb https://deb.debian.org/debian bookworm-backports main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src https://deb.debian.org/debian bookworm-backports main contrib non-free" >> /etc/apt/sources.list && \
apt-get update -y && \
apt-get upgrade -y && \
apt-get -t bookworm-backports install -y golang-go lsof && \
rm -rf /var/lib/apt/lists/*
FROM --platform=$BUILDPLATFORM node:20-bookworm-slim AS install

WORKDIR /bento-public

COPY package.json .
COPY package-lock.json .

# Install NPM dev/prod dependencies to get Nodemon - we will need to fix the permissions of node_modules after
RUN npm ci

# Don't copy code in, since we expect it to be mounted via volume
FROM ghcr.io/bento-platform/bento_base_image:node-debian-2024.10.01

LABEL org.opencontainers.image.description="Local development image for Bento Public."

WORKDIR /bento-public

COPY entrypoint.bash .
COPY run.dev.bash .
COPY nodemon.json .
COPY package.json .
COPY package-lock.json .

COPY --from=install /bento-public/node_modules ./node_modules

ENTRYPOINT [ "bash", "./entrypoint.bash" ]
CMD [ "bash", "./run.dev.bash" ]
13 changes: 0 additions & 13 deletions etc/example.server.env

This file was deleted.

23 changes: 0 additions & 23 deletions go.mod

This file was deleted.

48 changes: 0 additions & 48 deletions go.sum

This file was deleted.

Loading

0 comments on commit a89e851

Please sign in to comment.