Skip to content

Commit

Permalink
Merge pull request #15 from canonical/rock-refactor
Browse files Browse the repository at this point in the history
Rock refactor
  • Loading branch information
AmberCharitos authored May 2, 2024
2 parents f9c371c + fdce727 commit 93529f1
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 77 deletions.
146 changes: 69 additions & 77 deletions rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,23 @@ services:
platforms:
amd64:

# Please refer to
# https://discourse.ubuntu.com/t/unifying-user-identity-across-snaps-and-rocks/36469
# for more information about shared user.
# The UID 584792 corresponds to _daemon_ user.
run_user: _daemon_

parts:
backend:
superset:
after: [dependencies]
plugin: python
source: https://downloads.apache.org/superset/2.1.0/apache-superset-2.1.0-source.tar.gz # yamllint disable-line
source-checksum: sha512/62d240555ea50156fd16ad6dbc6fb26b86ca5319d0528e60cd4fbcb9fbeb9d529acfb43e272883d578df87e609a541a0116dfa8f4a955a3aeca3538adf58852a # yamllint disable-line
source-type: tar
build-packages:
- build-essential
- wget
stage-packages:
- python3.10-venv
build-environment:
- APP_HOME: "/app"
- SOURCE: "https://downloads.apache.org/superset"
- VERSION: "2.1.0"
- TAR_FILE: "apache-superset-2.1.0-source.tar.gz"
- DIST_PACKAGES: "usr/local/lib/python3.10/dist-packages/"
override-build: |
craftctl default
# make home directory
mkdir -p ${APP_HOME}
# Download the Superset tar
wget "${SOURCE}/${VERSION}/${TAR_FILE}" -O superset.tar.gz
# Download the Superset sha512
wget "${SOURCE}/${VERSION}/${TAR_FILE}.sha512" -O superset.tar.sha512
# Validate successful file download
sha_file=$(tail -n +2 superset.tar.sha512)
hash=$(echo $sha_file | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')
echo "$hash superset.tar.gz" | sha512sum --check
# Unpack tar
tar -zxvf superset.tar.gz -C ${APP_HOME} --strip-components 1
rm -rf superset.tar.gz

local-files:
plugin: dump
Expand All @@ -74,15 +57,29 @@ parts:
run-server.sh: app/k8s/run-server.sh
k8s-init.sh: app/k8s/k8s-init.sh
k8s-bootstrap.sh: app/k8s/k8s-bootstrap.sh
rock-requirements.txt: requirements/rock.txt
stage:
- app/k8s/run-server.sh
- app/k8s/k8s-init.sh
- app/k8s/k8s-bootstrap.sh
- requirements/rock.txt
permissions:
- path: app/k8s
owner: 584792
group: 584792
mode: "755"
- path: requirements
owner: 584792
group: 584792
mode: "755"

frontend:
after: [backend]
plugin: nil
source: https://downloads.apache.org/superset/2.1.0/apache-superset-2.1.0-source.tar.gz # yamllint disable-line
source-checksum: sha512/62d240555ea50156fd16ad6dbc6fb26b86ca5319d0528e60cd4fbcb9fbeb9d529acfb43e272883d578df87e609a541a0116dfa8f4a955a3aeca3538adf58852a # yamllint disable-line
source-type: tar
build-snaps:
- node/14/stable
build-environment:
- ASSETS_DIR: "/lib/python3.10/site-packages/superset/static/assets"
override-build: |
# Prepare for asset creation
cd superset-frontend
Expand All @@ -92,73 +89,68 @@ parts:
# Install frontend dependencies and build assets
npm ci
npm run build -- --output-path=/dist
# Copy assets to CRAFT_PRIME
mkdir -p "${CRAFT_PRIME}${ASSETS_DIR}"
cp -r /dist/* "${CRAFT_PRIME}${ASSETS_DIR}"
gunicorn-app:
after: [backend, frontend, local-files]
npm run build -- --output-path=${CRAFT_PART_INSTALL}/assets
organize:
assets: lib/python3.10/site-packages/superset/static/assets
stage:
- lib/python3.10/site-packages/superset/static/assets
permissions:
- path: lib/python3.10/site-packages/superset/static/assets
owner: 584792
group: 584792
mode: "755"

dependencies:
after: [local-files]
plugin: python
source: https://downloads.apache.org/superset/2.1.0/apache-superset-2.1.0-source.tar.gz # yamllint disable-line
source-checksum: sha512/62d240555ea50156fd16ad6dbc6fb26b86ca5319d0528e60cd4fbcb9fbeb9d529acfb43e272883d578df87e609a541a0116dfa8f4a955a3aeca3538adf58852a # yamllint disable-line
source-type: tar
build-packages:
- build-essential
- pkg-config
- libmysqlclient-dev
stage-packages:
- python3.10-venv
build-environment:
- APP_HOME: "/app"
- DIST_PACKAGES: "/usr/local/lib/python3.10/dist-packages"
override-build: |
# Install superset requirements
pip install --upgrade setuptools pip
pip install "cython<3.0.0"
pip install --no-build-isolation pyyaml==5.4.1
pip install -r requirements/base.txt --target=/${DIST_PACKAGES}
# Required dependencies missing from Superset requirements.txt
pip install Pillow==10.1.0
pip install requests==2.31.0
pip install jmespath==1.0.1
# Optional dependencies for Database connectors
pip install psycopg2-binary==2.9.4
pip install sqlalchemy==1.4.51
pip install Werkzeug==2.3.7
pip install Authlib==1.2.1
pip install elasticsearch-dbapi==0.2.10
pip install trino==0.327.0
pip install mysqlclient==2.1.1
pip install pyhive==0.7.0
pip install thrift==0.16.0
pip install sqlalchemy-redshift==0.8.1
pip install urllib3==1.26.11
# Monitoring
pip install sentry-sdk==0.10.2
pip install statsd==4.0.1
# Install Superset in editable mode
pip install -e .
# Copy packages to PRIME
mkdir -p ${CRAFT_PRIME}${DIST_PACKAGES}
cp -r ${DIST_PACKAGES}/* ${CRAFT_PRIME}${DIST_PACKAGES}
cp -r . ${CRAFT_PRIME}${APP_HOME}
# Install Superset requirements
pip install --upgrade setuptools pip \
--no-build-isolation pyyaml==5.4.1 \
-r requirements/base.txt \
--target=/${CRAFT_PART_INSTALL}/dist \
-r ${CRAFT_STAGE}/requirements/rock.txt \
--target=/${CRAFT_PART_INSTALL}/dist
# Copy current directory files to app
cp -r . ${CRAFT_PART_INSTALL}/app
organize:
dist: usr/local/lib/python3.10/dist-packages
stage:
- app
- usr/local/lib/python3.10/dist-packages
permissions:
- path: usr/local/lib/python3.10/dist-packages
owner: 584792
group: 584792
mode: "755"

prometheus-statsd-exporter:
plugin: dump
source: https://github.com/prometheus/statsd_exporter/releases/download/v0.26.1/statsd_exporter-0.26.1.linux-amd64.tar.gz # yamllint disable-line
source-type: tar
source-checksum: sha256/36b33a04531cf871cf8c9c5d667e3c0ca59c07b4ba496bd6cd066bec4f25cc0d # yamllint disable-line
source-type: tar
organize:
statsd_exporter: bin/statsd_exporter
stage:
- bin/statsd_exporter
permissions:
- path: bin/statsd_exporter
owner: 584792
group: 584792
mode: "755"

overlay-pkgs:
after: [superset]
plugin: nil
overlay-packages:
- ca-certificates
Expand Down
20 changes: 20 additions & 0 deletions startup-scripts/rock-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Required dependencies missing from Superset requirements.txt
cython<3.0.0
pyyaml==5.4.1
Pillow==10.1.0
requests==2.31.0
jmespath==1.0.1

# Optional dependencies for Database connectors
psycopg2-binary==2.9.4
Authlib==1.2.1
elasticsearch-dbapi==0.2.10
trino==0.327.0
mysqlclient==2.1.1
pyhive==0.7.0
thrift==0.16.0
sqlalchemy-redshift==0.8.1

# Monitoring
sentry-sdk==0.10.2
statsd==4.0.1

0 comments on commit 93529f1

Please sign in to comment.