Skip to content

Commit 1a111a7

Browse files
committed
OpenConceptLab/ocl_online#31 | attempting private package install
1 parent 6372a42 commit 1a111a7

7 files changed

Lines changed: 78 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,22 @@ jobs:
4949
with:
5050
username: ${{ secrets.DOCKER_USERNAME }}
5151
password: ${{ secrets.DOCKER_PASSWORD }}
52-
#- name: Log in to the Container registry
53-
# uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
54-
# with:
55-
# registry: ghcr.io
56-
# username: ${{ github.actor }}
57-
# password: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Setup SSH for premium repos
53+
run: |
54+
mkdir -p ~/.ssh
55+
echo "${{ secrets.PREMIUM_UI_DEPLOY_KEY }}" > ~/.ssh/id_rsa
56+
chmod 600 ~/.ssh/id_rsa
57+
ssh-keyscan github.com >> ~/.ssh/known_hosts
5858
- name: Build and push Docker image
5959
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
6060
with:
6161
context: .
6262
push: true
63+
ssh: default
6364
tags: openconceptlab/oclweb3:nightly, openconceptlab/oclweb3:${{ steps.package-version.outputs.current-version}}-${{env.GITHUB_SHA_SHORT}}
64-
build-args: SOURCE_COMMIT=${{env.GITHUB_SHA_SHORT}}
65+
build-args: |
66+
SOURCE_COMMIT=${{env.GITHUB_SHA_SHORT}}
67+
PRIVATE_PACKAGES_GIT=${{env.PRIVATE_PACKAGES_GIT}}
6568
6669
release:
6770
needs: [build]

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Stage-1 Build and Development Environment
2+
# syntax=docker/dockerfile:1.4
3+
24
FROM node:14.11 as build
35
ARG NODE_ENV=production
46
ARG NODE_OPTIONS=--max_old_space_size=700
@@ -23,6 +25,17 @@ ADD package-lock.json /app/
2325

2426
RUN npm ci --production=false
2527

28+
# OPTIONAL: install private premium UI package during image build
29+
# Example installs a package from a private repo/subdir
30+
ARG PRIVATE_PACKAGES_GIT
31+
RUN --mount=type=ssh \
32+
mkdir -p /root/.ssh && \
33+
ssh-keyscan github.com >> /root/.ssh/known_hosts && \
34+
if [ -n "$PRIVATE_PACKAGES_GIT" ]; then \
35+
echo "Installing premium UI packages:" $PRIVATE_PACKAGES_GIT && \
36+
npm i $PRIVATE_PACKAGES_GIT; \
37+
fi
38+
2639
ADD webpack.config.js /app/
2740
ADD .babelrc /app/
2841
ADD src /app/src/

docker-compose.override.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
target: build
99
args:
1010
NODE_ENV: development
11+
PRIVATE_PACKAGES_GIT:
1112
ports:
1213
- "4002:4002"
1314
- "4003:35729"

docker-compose.sso.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
target: build
99
args:
1010
NODE_ENV: development
11+
PRIVATE_PACKAGES_GIT:
1112
ports:
1213
- "4002:4002"
1314
- "4003:35729"

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
context: .
88
args:
99
NODE_ENV: production
10+
PRIVATE_PACKAGES_GIT:
1011
ports:
1112
- "4002:4002"
1213
restart: on-failure
@@ -16,7 +17,7 @@ services:
1617
- WEB_PORT=4002
1718
- RECAPTCHA_SITE_KEY=${RECAPTCHA_SITE_KEY-6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI}
1819
- GA_ACCOUNT_ID=${GA_ACCOUNT_ID-UA-000000-01}
19-
- ANALYTICS_API
20+
- ANALYTICS_API=${ANALYTICS_API-}
2021
- ERRBIT_URL
2122
- ERRBIT_KEY
2223
- HOTJAR_ID

src/common/loadRoutes.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export async function loadRoutes() {
2+
try {
3+
// This package exists only in your private deployment
4+
const mod = require("ocl-analytics-web");
5+
6+
// Expect the private package to export PremiumRoutes (recommended)
7+
// return React component that renders <Route .../>
8+
return mod.Routes || null;
9+
} catch (e) {
10+
// Not installed → no premium routes
11+
return null;
12+
}
13+
}
14+
15+
16+
export async function loadUsageDashboard() {
17+
try {
18+
// webpack won't try to resolve this at build time
19+
// eslint-disable-next-line global-require, import/no-unresolved
20+
const mod = require("ocl-analytics-web");
21+
console.log("ocl-analytics-web keys:", Object.keys(mod));
22+
return mod.UsageDashboard || mod.default || null;
23+
} catch (e) {
24+
return null;
25+
}
26+
}

src/components/app/App.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import ImportHome from '../imports/ImportHome'
3737
import ConceptsComparison from '../concepts/ConceptsComparison'
3838
import MappingsComparison from '../mappings/MappingsComparison'
3939
import CheckAuth from './CheckAuth'
40+
import { loadUsageDashboard } from "../../common/loadRoutes";
41+
42+
4043

4144
const AuthenticationRequiredRoute = ({component: Component, ...rest}) => (
4245
<Route
@@ -58,6 +61,13 @@ const SessionUserRoute = ({component: Component, ...rest}) => (
5861
/>
5962
)
6063

64+
const StaffUserRoute = ({component: Component, ...rest}) => (
65+
<Route
66+
{...rest}
67+
render={props => getCurrentUser()?.is_staff ? <Component {...props} /> : <Error404 />}
68+
/>
69+
)
70+
6171
const App = props => {
6272
const [networkError, setNetworkError] = React.useState(false)
6373
const { alert, setAlert, setToggles } = React.useContext(OperationsContext);
@@ -115,6 +125,13 @@ const App = props => {
115125
setupHotJar()
116126
}, [])
117127

128+
const [UsageDashboard, setUsageDashboard] = React.useState(null);
129+
130+
React.useEffect(() => {
131+
loadUsageDashboard().then(setUsageDashboard);
132+
}, []);
133+
console.log("UsageDashboard:", UsageDashboard)
134+
118135

119136

120137
const repoTabs = ['concepts', 'mappings', 'versions', 'summary', 'about', 'references']
@@ -136,6 +153,14 @@ const App = props => {
136153
<Route exact path="/search" component={Search} />
137154
<Route exact path="/" component={Dashboard} />
138155
<Route exact path="/imports" component={ImportHome} />
156+
{
157+
UsageDashboard &&
158+
<StaffUserRoute
159+
exact
160+
path='/admin'
161+
component={UsageDashboard}
162+
/>
163+
}
139164
<AuthenticationRequiredRoute exact path={`/:ownerType(users|orgs)/:owner/sources/:repo/:repoVersion/concepts/$match`} component={RepoConceptsMatch} />
140165
<AuthenticationRequiredRoute exact path={`/:ownerType(users|orgs)/:owner/repos/new/:step?`} component={RepoCreate} />
141166
<AuthenticationRequiredRoute exact path={`/:ownerType(users|orgs)/:owner/:repoType(sources|collections)/:repo/edit/:step?`} component={RepoCreate} />

0 commit comments

Comments
 (0)