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

Superset ROCK for review #12

Open
wants to merge 1 commit into
base: rock-review-base
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Bug report
about: File a bug report
labels: bug

---

<!-- Thank you for submitting a bug report! All fields are required unless marked optional. -->

## Steps to reproduce
1.

## Expected behavior


## Actual behavior
<!-- If applicable, add screenshots -->


## Versions

<!-- Run `lsb_release -sd` -->
Operating system:

## Log output
<!-- (Optional) Copy the logs that are relevant to the bug & paste inside triple backticks below -->


## Additional context
<!-- (Optional) Add any additional information here -->
52 changes: 52 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build ROCK

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install tox
run: python3 -m pip install tox
- name: YAML Lint
run: tox -e lint

build:
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- lint
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup LXD
uses: canonical/setup-lxd@main
- name: Install dependencies
run: |
sudo snap install yq
sudo snap install rockcraft --classic --edge
- name: Build ROCK
run: |
app_version=$(yq '.version' rockcraft.yaml)
version=$(yq '(.version|split("-"))[0]' rockcraft.yaml)
base=$(yq '(.base|split("@"))[1]' rockcraft.yaml)
risk=edge
tag=${version}-${base}-${risk}

sed -i "0,/${app_version}/{s//${tag}/}" rockcraft.yaml
rockcraft pack --verbose

- name: Upload locally built ROCK artifact
uses: actions/upload-artifact@v3
with:
name: charmed-superset-rock
path: "charmed-superset-rock_*.rock"
52 changes: 52 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish ROCK
on:
push:
branches:
- main

jobs:
build:
uses: ./.github/workflows/build.yaml
publish:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker
run: |
sudo snap install docker
sudo addgroup --system docker; sudo adduser $USER docker
newgrp docker
sudo snap disable docker; sudo snap enable docker
- name: Install skopeo
run: |
sudo snap install --devmode --channel edge skopeo
- name: Install yq
run: |
sudo snap install yq
- uses: actions/download-artifact@v3
with:
name: charmed-superset-rock
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Import and push to GHCR
run: |
app_version=$(yq '.version' rockcraft.yaml)
version=$(yq '(.version|split("-"))[0]' rockcraft.yaml)
base=$(yq '(.base|split("@"))[1]' rockcraft.yaml)
risk=edge
tag=${version}-${base}-${risk}

sudo skopeo --insecure-policy copy \
oci-archive:charmed-superset-rock_${tag}_amd64.rock \
docker-daemon:ghcr.io/canonical/charmed-superset-rock:${tag}

docker push ghcr.io/canonical/charmed-superset-rock:${tag}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.rock
.tox
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Variables
REPO_FOLDER = charmed-superset-rock
REPO = https://github.com/canonical/$(REPO_FOLDER).git
ROCK_DEV = rock-dev
ROCK_VERSION = 2.1.0
UBUNTU_VER = 22.04
DOCKER_NAME = superset-ui-services
DOCKER_PORT = 8088
DOCKER_ARGS = superset-ui -g 'daemon off:' \; start superset-ui

REQUIRED_VARS := ROCK_DEV UBUNTU_VER REPO_FOLDER DOCKER_NAME DOCKER_PORT DOCKER_ARGS ROCK_VERSION

$(foreach var,$(REQUIRED_VARS),\
$(if $(value $(var)),,$(error $(var) is not set)))

# Targets
.PHONY: all dev build install clean clean-all

all: dev build install

dev: install-multipass setup-multipass clone install-prerequisites configure-prerequisites

build: pack

install: run

clean-all:
multipass delete -p $(ROCK_DEV)

install-multipass:
sudo snap install multipass

setup-multipass:
@if multipass --format=table list | awk '{print $1}' | grep $(ROCK_DEV); then \
echo '$(ROCK_DEV) exists'; \
else \
multipass launch $(UBUNTU_VER) -n $(ROCK_DEV) -m 8g -c 2 -d 20G; \
fi

clone:
multipass exec $(ROCK_DEV) -- bash -c '[ -d "$(REPO_FOLDER)/.git" ] || git clone $(REPO)'

install-prerequisites:
multipass exec $(ROCK_DEV) -- bash -c 'sudo snap install rockcraft --edge --classic &&\
sudo snap install skopeo --edge --devmode &&\
sudo snap install lxd && sudo lxd init --auto'
multipass exec $(ROCK_DEV) -- sudo snap install docker

configure-prerequisites:
multipass exec $(ROCK_DEV) -- bash -c 'if getent group docker > /dev/null; then echo "The docker group exists"; else sudo groupadd docker && echo "The docker group has been created"; fi; sudo usermod -aG docker $$USER'
multipass exec $(ROCK_DEV) -- bash -c 'sudo snap disable docker && sudo snap enable docker'

clean:
multipass exec $(ROCK_DEV) -- bash -c 'docker ps -q -f "name=$(DOCKER_NAME)" && docker stop $(DOCKER_NAME) && docker rm $(DOCKER_NAME) && docker rmi charmed-superset-rock:$(ROCK_VERSION)'
multipass exec $(ROCK_DEV) -- bash -c 'rm $(REPO_FOLDER)/charmed-superset-rock_$(ROCK_VERSION)-$(UBUNTU_VER)-edge_amd64.rock'

pack:
multipass exec $(ROCK_DEV) -- bash -c 'cd $(REPO_FOLDER) && rockcraft pack'

run:
multipass exec $(ROCK_DEV) -- bash -c 'cd $(REPO_FOLDER) &&\
sudo skopeo --insecure-policy copy oci-archive:charmed-superset-rock_$(ROCK_VERSION)-$(UBUNTU_VER)-edge_amd64.rock docker-daemon:charmed-superset-rock:$(ROCK_VERSION)'
multipass exec $(ROCK_DEV) -- bash -c "cd $(REPO_FOLDER) &&\
docker run -d --name $(DOCKER_NAME) -p $(DOCKER_PORT):$(DOCKER_PORT) charmed-superset-rock:$(ROCK_VERSION) --args $(DOCKER_ARGS)"
@IP_ADDRESS=$$(multipass --format=table list | grep $(ROCK_DEV) | awk '{print $$3}') && \
echo "Waiting for Superset..."; \
while ! nc -z $$IP_ADDRESS $(DOCKER_PORT); do \
sleep 1; \
done && \
echo "Superset is up on $$IP_ADDRESS:$(DOCKER_PORT)"
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Charmed Apache Superset ROCK

This repository contains the packaging metadata for creating a Charmed Superset ROCK. This ROCK image is based on the upstream [Apache Superset](https://downloads.apache.org/superset/) image.

For more information on ROCKs, visit the [rockcraft Github](https://github.com/canonical/rockcraft).

## Building the ROCK
The steps outlined below are based on the assumption that you are building the ROCK with the latest LTS of Ubuntu.
If you are using another version of Ubuntu or another operating system, the process may be different.
To avoid any issue with other operating systems you can simply build the image with [multipass](https://multipass.run/):
```bash
sudo snap install multipass
multipass launch -n rock-dev -m 8g -c 2 -d 20G
multipass shell rock-dev
```
### Clone Repository
```bash
git clone https://github.com/canonical/charmed-superset-rock.git
cd charmed-superset-rock
```
### Installing & Configuring Prerequisites
```bash
sudo snap install rockcraft --edge --classic
sudo snap install skopeo --edge --devmode
sudo lxd init --auto

# Note: Docker must be installed after LXD is initialized due to firewall rules incompatibility.
sudo snap install docker
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

# Note: disabling and enabling docker snap is required to avoid sudo requirement.
# As described in https://github.com/docker-snap/docker-snap.
sudo snap disable docker
sudo snap enable docker
```
### Packing and Running the ROCK
```bash
rockcraft pack
sudo skopeo --insecure-policy copy oci-archive:charmed-superset-rock_2.1.0-22.04-edge_amd64.rock docker-daemon:charmed-superset-rock:2.1.0
docker run -d --name superset-ui-services -p 8088:8088 charmed-superset-rock:2.1.0 --args superset-ui -g 'daemon off:' \; start superset-ui
```
### Login
To access Superset, now exit the multipass instance run `multipass list` for the below output.
```
Name State IPv4 Image
rock-dev Running 10.137.215.60 Ubuntu 22.04 LTS
10.194.234.1
172.17.0.1
```
Navigate to `<VM IP Address>:8088` (in this case 10.137.215.60:8088) and login with `admin`/`admin`.
Further information on connecting data sources and creating dashboards can be found at [superset.apache.org](https://superset.apache.org/docs/creating-charts-dashboards/creating-your-first-dashboard/).

## Using Makefile

`make dev` will create the multipass image, clone the repo, install and configure the prerequisites.
`make build` will pack the rock for you
`make install` will build the oci image and run it
`make clean` will remove build artifacts and enable you to rebuild
`make clean-all` will remove the image and get you ready to start from `make dev`

## License
The Charmed Superset ROCK is free software, distributed under the Apache
Software License, version 2.0. See
[LICENSE](https://github.com/canonical/charmed-superset-rock/blob/main/LICENSE)
for more information.
Loading
Loading