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

Feature/develop fix #6

Merged
merged 5 commits into from
Mar 18, 2021
Merged
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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ superset-frontend/cypress-base/
superset-frontend/coverage/
superset/static/assets/
venv




# cccs-viz customizations
superset-frontend/node_modules/
superset-frontend/cccs-viz/node_modules/
# cccs-viz customizations

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@ release.json
messages.mo

docker/requirements-local.txt


# ignore cccs-viz built folders
esm/
lib/
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ RUN mkdir -p /app/superset-frontend
RUN mkdir -p /app/superset/assets
COPY ./docker/frontend-mem-nag.sh /
COPY ./superset-frontend/package* /app/superset-frontend/
RUN /frontend-mem-nag.sh \
&& cd /app/superset-frontend \
&& npm ci

# Next, copy in the rest and let webpack do its thing
COPY ./superset-frontend /app/superset-frontend

# Build cccs-viz before running install in the superset-frontend
RUN cd /app/superset-frontend/cccs-viz \
&& npm install \
&& yarn build \
&& rm -rf node_modules

RUN /frontend-mem-nag.sh \
&& cd /app/superset-frontend \
&& npm i

# This is BY FAR the most expensive step (thanks Terser!)
RUN cd /app/superset-frontend \
&& npm run ${BUILD_CMD} \
Expand Down
51 changes: 51 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Docker

# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker


trigger:
- master

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '0f6808c3-1749-435d-b894-32e5c4d8e77b'
imageRepository: 'cccs/superset'
containerRegistry: 'uchimera.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'
buildTimestamp: $[format('{0:yyyyMMddHHmmss}', pipeline.startTime)]

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- checkout: self

- bash: |
BRANCH_NAME=`echo "$SYSTEM_PULLREQUEST_SOURCEBRANCH $BUILD_SOURCEBRANCH" | sed -r 's/^\s*(refs\/heads\/)?(\S*).*$/\2/' | sed 's/\//_/g'`
echo "##vso[task.setvariable variable=BRANCH_NAME]$BRANCH_NAME"

- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: cccs/superset
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(BRANCH_NAME)
$(BRANCH_NAME)_$(buildTimestamp)_b$(Build.BuildId)


2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
x-superset-image: &superset-image apache/superset:latest-dev
x-superset-image: &superset-image uchimera.azurecr.io/cccs/superset:latest
x-superset-depends-on: &superset-depends-on
- db
- redis
Expand Down
178 changes: 178 additions & 0 deletions superset-frontend/cccs-viz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

CCCS-VIZ for Superset
=====================

<br>
<br>

Creating a custom viz
=====================

Modified instructions from
https://superset.apache.org/docs/installation/building-custom-viz-plugins

```bash
cd superset/superset-frontend/cccs-viz/plugins
mkdir plugin-chart-data-grid
cd plugin-chart-data-grid
yo @superset-ui/superset
```

Modifying your custom viz
=====================

Edit `superset/superset-frontend/package.json` and add the followin line.

```diff

"homepage": "https://superset.apache.org/",
"dependencies": {
+ "@superset-ui/plugin-chart-data-grid": "^0.0.0",

```

Edit `superset/superset-frontend/src/visualizations/presets/MainPreset.js`
```diff

+ import { DataGridChartPlugin } from '@superset-ui/plugin-chart-data-grid';

export default class MainPreset extends Preset {
constructor() {
super({
name: 'Legacy charts',
presets: [new DeckGLChartPreset()],
plugins: [
+ new DataGridChartPlugin().configure({key: 'data_grid'}),

```

Create a link of our source in the node_modules folder (hot code replacement depends on this)
```

cd superset/superset-frontend
npm link ./cccs-viz/plugins/plugin-chart-data-grid/

```

Run dev-server
```

cd superset/superset-frontend
npm run dev-server -- --host=<host ip> --port=9000

```

Develop the custom viz. You can connect to port 9000 to test your modifications. When it's ready to be deployed in the docker image you have to do the following

<br>
<br>
<br>



Test your code changes inside the docker container
==================

Once you are done developing the custom viz and are ready to commit your code and build a docker image you can test the npm install will work this is what docker file does.

Edit `superset/superset-frontend/package.json` make sure it installs from the file location (not a published npm package)

```diff

- "@superset-ui/plugin-chart-data-grid": "^0.0.0",

+ "@superset-ui/plugin-chart-hello-world": "file:./cccs-viz/plugins/plugin-chart-data-grid",

```

Edit `superset/superset-frontend/src/visualizations/presets/MainPreset.js`
Make sure to point package install dir
```diff

- import { DataGridChartPlugin } from '@superset-ui/plugin-chart-data-grid';

+ import { DataGridlineChartPlugin } from '../../../cccs-viz/plugins/plugin-chart-data-grid';

```

It's important to know that the docker-compose uses the files of the host system so you absolutely need to build your cccs-viz inside your git clone.


This will create the esm and lib files.
```bash

cd /superset/superset-frontend/cccs-viz
npm install
yarn build

```
The same goes for the frontend it will use those files so you need to build the frontend
```

cd superset/superset-frontend
npm install
npm run build

```

Now ready to test docker build
```bash

cd superset
docker build -t 'uchimera.azurecr.io/cccs/superset:latest' .

```

You can test your docker image using docker-compose, the docker-compose.yaml uses the image we just built.
```bash

cd superset
docker-compose up

```

You can connect to superset on port 8088 to test the superset server running inside the docker container.



<br>
<br>
<br>



Commiting your code
==================

When it works locally from your own docker container you can commit your changes

Add custom viz files and the config files that reference it
```bash

cd superset
git add superset-frontend/package-lock.json
git add superset-frontend/package.json
git add superset-frontend/src/visualizations/presets/MainPreset.js
git add superset-frontend/cccs-viz/plugins/plugin-chart-data-grid/
git push origin master

```

23 changes: 23 additions & 0 deletions superset-frontend/cccs-viz/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { getConfig } = require('@airbnb/config-babel');

const config = getConfig({
library: true,
react: true,
next: true,
esm: process.env.BABEL_OUTPUT === 'esm',
node: process.env.NODE_ENV === 'test',
typescript: true,
env: {
targets: false,
},
});

// Override to allow transpile es modules inside vega-lite
config.ignore = config.ignore.filter(item => item !== 'node_modules/');
config.ignore.push('node_modules/(?!(vega-lite|lodash-es))');
config.plugins = [
['babel-plugin-transform-dev', { evaluate: false }],
['babel-plugin-typescript-to-proptypes', { loose: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
];
module.exports = config;
23 changes: 23 additions & 0 deletions superset-frontend/cccs-viz/lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"lerna": "3.2.1",
"npmClient": "yarn",
"packages": ["packages/*", "plugins/*"],
"useWorkspaces": true,
"version": "0.17.9",
"ignoreChanges": [
"**/*.md",
"**/*.spec.tsx?",
"**/*.spec.jsx?",
"**/__mocks__/**"
],
"command": {
"publish": {
"message": "chore: publish %s",
"graphType": "all"
},
"version": {
"message": "chore: publish %s",
"exact": true
}
}
}
Loading