Skip to content

Commit

Permalink
Merge pull request #147 from DSD-DBS/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
MoritzWeber0 authored Aug 2, 2022
2 parents e9be94f + e4bbe98 commit 3566e03
Show file tree
Hide file tree
Showing 187 changed files with 5,390 additions and 8,238 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
# Backend
- package-ecosystem: "pip"
directory: "/backend"
schedule:
interval: "weekly"
# Frontend
- package-ecosystem: "npm"
directory: "/frontend"
schedule:
interval: "weekly"
# Capella Dockerimages
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "weekly"

15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
# SPDX-License-Identifier: Apache-2.0

repos:
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
types: [python]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
types: [python]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
types_or: [ts, css, html]
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.13
hooks:
Expand Down
36 changes: 30 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ Do not use it in production!
4. Verify that the server runs, e.g. by navigating to
[Well Known](https://localhost:8083/default/.well-known/openid-configuration)

## t4cserver

1. Navigate to `mocks/t4cserver/`.
1. Setup a local python environment
```sh
python3 -m venv .venv
source.venv/bin/activate
pip install -U pip setuptools
pip install -e '.[options]'
```

1. Launch the server :
The port must match the key modelsources.t4c.usageAPI in the backend
config. Change it to 7000 for example.
```sh
source .venv/bin/activate # if not sourced before
uvicorn mock:app --host 0.0.0.0 --port 7000 --reload
```

## Backend

Requirements:
Expand All @@ -92,16 +111,21 @@ Run the following steps:
make create-cluster
```

1. In order to use Guacamole, the cluster must be deployed:
```sh
make deploy
```

1. Navigate to the `backend` directory of your cloned repository.
1. We recommend that you develop inside of a virtual environment. To set it up,
run the following commands:

```sh
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip setuptools
pip install -e '.[dev]'
```
```sh
python3 -m venv .venv
source .venv/bin/activate
pip install -U pip setuptools
pip install -e '.[dev]'
```

1. The backend uses various configuration settings. You can find them in the `config`
directory.
Expand Down
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ frontend:
capella: capella-download
docker build -t base capella-dockerimages/base
docker build -t capella/base capella-dockerimages/capella

capella/remote: capella
docker build -t capella/remote -t $(LOCAL_REGISTRY_NAME):$(REGISTRY_PORT)/t4c/client/remote capella-dockerimages/remote
docker push $(LOCAL_REGISTRY_NAME):$(REGISTRY_PORT)/t4c/client/remote

Expand All @@ -39,8 +41,10 @@ capella-download:
curl -L --output capella.tar.gz 'https://ftp.acc.umu.se/mirror/eclipse.org/capella/core/products/releases/5.2.0-R20211130-125709/capella-5.2.0.202111301257-linux-gtk-x86_64.tar.gz'; \
fi

t4c-client:
t4c-client: capella
docker build -t t4c/client/base capella-dockerimages/t4c
docker build -t t4c/client/remote -t $(LOCAL_REGISTRY_NAME):$(REGISTRY_PORT)/t4c/client/remote --build-arg BASE_IMAGE=t4c/client/base capella-dockerimages/remote
docker push $(LOCAL_REGISTRY_NAME):$(REGISTRY_PORT)/t4c/client/remote

readonly:
docker build -t capella/ease --build-arg BASE_IMAGE=capella/base --build-arg BUILD_TYPE=online capella-dockerimages/ease
Expand All @@ -61,10 +65,10 @@ mock:

capella-dockerimages: capella t4c-client readonly ease

deploy: backend frontend capella mock helm-deploy open rollout
deploy: backend frontend capella/remote mock helm-deploy open rollout

# Deploy with full T4C support:
deploy-t4c: backend frontend capella t4c-client readonly-ease mock helm-deploy
deploy-t4c: backend frontend capella t4c-client readonly ease mock helm-deploy open rollout

helm-deploy:
k3d cluster list $(CLUSTER_NAME) 2>&- || $(MAKE) create-cluster
Expand Down Expand Up @@ -125,12 +129,12 @@ delete-cluster:

.provision-guacamole:
export MSYS_NO_PATHCONV=1; \
kubectl exec --namespace $(NAMESPACE) $$(kubectl get pod --namespace $(NAMESPACE) -l id=$(RELEASE)-deployment-guacamole-guacamole --no-headers | cut -f1 -d' ') -- /opt/guacamole/bin/initdb.sh --postgres | \
kubectl exec -ti --namespace $(NAMESPACE) $$(kubectl get pod --namespace $(NAMESPACE) -l id=$(RELEASE)-deployment-guacamole-postgres --no-headers | cut -f1 -d' ') -- psql -U guacamole guacamole && \
kubectl exec --context k3d-$(CLUSTER_NAME) --namespace $(NAMESPACE) $$(kubectl get pod --context k3d-$(CLUSTER_NAME) --namespace $(NAMESPACE) -l id=$(RELEASE)-deployment-guacamole-guacamole --no-headers | cut -f1 -d' ') -- /opt/guacamole/bin/initdb.sh --postgres | \
kubectl exec -ti --context k3d-$(CLUSTER_NAME) --namespace $(NAMESPACE) $$(kubectl get pod --context k3d-$(CLUSTER_NAME) --namespace $(NAMESPACE) -l id=$(RELEASE)-deployment-guacamole-postgres --no-headers | cut -f1 -d' ') -- psql -U guacamole guacamole && \
touch .provision-guacamole

.provision-backend:
echo "insert into repository_user_association values ('$(MY_EMAIL)', 'default', 'WRITE', 'MANAGER');" | kubectl exec --namespace $(NAMESPACE) $$(kubectl get pod --namespace $(NAMESPACE) -l id=$(RELEASE)-deployment-backend-postgres --no-headers | cut -f1 -d' ') -- psql -U backend backend && \
echo "insert into repository_user_association values ('$(MY_EMAIL)', 'default', 'WRITE', 'MANAGER');" | kubectl exec --context k3d-$(CLUSTER_NAME) --namespace $(NAMESPACE) $$(kubectl get pod --context k3d-$(CLUSTER_NAME) --namespace $(NAMESPACE) -l id=$(RELEASE)-deployment-backend-postgres --no-headers | cut -f1 -d' ') -- psql -U backend backend && \
touch .provision-backend

# Execute with `make -j3 dev`
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ When you have all that installed you can do the following:
```zsh
git clone --recurse-submodules https://github.com/DSD-DBS/capella-collab-manager.git
cd capella-collab-manager
```

Create a local k3d cluster and deploy the application

```zsh
# Create a local k3d cluster
make create-cluster

# Deploy the application (choose one of the two options)
# WITHOUT TeamForCapella session support
make deploy

# WITH TeamForCapella session support
make deploy-t4c
```

It can take a long time to run, but shouldn't take more than 5 minutes. Meanwhile, the following message appears several times:
Expand Down
6 changes: 6 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
config
.venv
.vscode
build
*.egg-info
.mypy_cache
.pytest_cache
3 changes: 2 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ COPY . /backend
WORKDIR /backend
RUN pip install .

CMD ["uvicorn", "t4cclient.__main__:app", "--host", "0.0.0.0"]
RUN chmod +x /backend/startup.sh
CMD ["/backend/startup.sh"]
24 changes: 21 additions & 3 deletions backend/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
DB_PORT = 5432
DB_PASSWORD = dev
DB_USER = dev
DB_NAME = dev
VENV = .venv

database:
docker start capella-collab-postgres || \
docker run -d \
--name capella-collab-postgres \
-p $(DB_PORT):5432 \
-e POSTGRES_PASSWORD=dev \
-e POSTGRES_USER=dev \
-e POSTGRES_DB=dev \
-e POSTGRES_PASSWORD=$(DB_PASSWORD) \
-e POSTGRES_USER=$(DB_USER) \
-e POSTGRES_DB=$(DB_NAME) \
postgres

app:
Expand All @@ -20,8 +23,23 @@ app:
$(VENV)/Scripts/uvicorn t4cclient.__main__:app --reload; \
fi

install:
$(VENV)/bin/pip install -e ".[dev]"

dev: database app

cleanup:
docker stop capella-collab-postgres
docker rm capella-collab-postgres

dump:
docker run -e PGPASSWORD=$(DB_PASSWORD) --entrypoint pg_dump --network host postgres:latest -h 'localhost' -p $(DB_PORT) -U '$(DB_USER)' $(DB_NAME) > $$(pwd)/../local/tmp.sql

psql:
docker run -e PGPASSWORD=$(DB_PASSWORD) -it --network host --entrypoint="psql" postgres:latest -h 'localhost' -p $(DB_PORT) -U '$(DB_USER)' $(DB_NAME)

clear:
echo "DROP DATABASE $(DB_NAME); CREATE DATABASE $(DB_NAME);" | docker run -e PGPASSWORD=$(DB_PASSWORD) -i --network host --entrypoint="psql" postgres:latest -h 'localhost' -p $(DB_PORT) -U '$(DB_USER)' postgres

load: clear
cat $$(pwd)/../local/load.sql | docker run -i -e PGPASSWORD=$(DB_PASSWORD) --network host --entrypoint="psql" postgres:latest -h 'localhost' -p $(DB_PORT) -U '$(DB_USER)' $(DB_NAME)
2 changes: 1 addition & 1 deletion backend/config/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ modelsources:
t4c:

usageAPI: http://localhost:8080/mock
restAPI: http://localhost:8080/mock/api/v1.0
restAPI: http://localhost:7000/mock/api/v1.0

username: sampleuser
password: samplepassword
Expand Down
5 changes: 0 additions & 5 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ line-length = 88
target-version = ["py310",]

[tool.isort]
ensure_newline_before_comments = true
force_grid_wrap = 0
import_heading_stdlib = "Standard library:"
import_heading_thirdparty = "3rd party:"
import_heading_firstparty = "1st party:"
import_heading_localfolder = "local:"
include_trailing_comma = true
known_local_folder = ["t4cclient", "tests",]
line_length = 88
Expand Down
4 changes: 2 additions & 2 deletions backend/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ capellacollab.extensions.modelsources =
git = t4cclient.extensions.modelsources.git
t4c = t4cclient.extensions.modelsources.t4c
capellacollab.operators =
k8s = t4cclient.core.operators.k8s:KubernetesOperator
docker = t4cclient.core.operators.docker:DockerOperator
k8s = t4cclient.sessions.operators.k8s:KubernetesOperator
docker = t4cclient.sessions.operators.docker:DockerOperator
capellacollab.authentication.providers =
oauth = t4cclient.core.authentication.provider.oauth
azure = t4cclient.core.authentication.provider.azure
6 changes: 6 additions & 0 deletions backend/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

# When running inside the cluster, the k8s service host should not use the proxy
export no_proxy=$no_proxy,$KUBERNETES_SERVICE_HOST,$no_proxy_additional
uvicorn t4cclient.__main__:app --host 0.0.0.0
2 changes: 2 additions & 0 deletions backend/t4cclient/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0
4 changes: 2 additions & 2 deletions backend/t4cclient/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

os.environ["ALEMBIC_CONTEXT"] = "1"

from alembic import context
from sqlalchemy import engine_from_config, pool
from t4cclient.config import config as cfg

from alembic import context
from t4cclient.config import config as cfg

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '0a16fb85f762'
down_revision = 'd6a23ac7f263'
revision = "0a16fb85f762"
down_revision = "d6a23ac7f263"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('EASEBackup', sa.Column('username', sa.String(), nullable=True))
op.add_column("EASEBackup", sa.Column("username", sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('EASEBackup', 'username')
op.drop_column("EASEBackup", "username")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
from alembic import op

# revision identifiers, used by Alembic.
revision = '279ec954b302'
revision = "279ec954b302"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('sessions', sa.Column('rdp_password', sa.String(), nullable=True))
op.add_column('sessions', sa.Column('guacamole_password', sa.String(), nullable=True))
op.add_column("sessions", sa.Column("rdp_password", sa.String(), nullable=True))
op.add_column(
"sessions", sa.Column("guacamole_password", sa.String(), nullable=True)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('sessions', 'guacamole_password')
op.drop_column('sessions', 'rdp_password')
op.drop_column("sessions", "guacamole_password")
op.drop_column("sessions", "rdp_password")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@
import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = '377b60de4441'
down_revision = '6a8bdec1dccb'
revision = "377b60de4441"
down_revision = "6a8bdec1dccb"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('git_models', sa.Column('project_name', sa.String(), nullable=False))
op.create_foreign_key(None, 'git_models', 'projects', ['project_name'], ['name'])
op.add_column("git_models", sa.Column("project_name", sa.String(), nullable=False))
op.create_foreign_key(None, "git_models", "projects", ["project_name"], ["name"])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'git_models', type_='foreignkey')
op.drop_column('git_models', 'project_name')
op.drop_constraint(None, "git_models", type_="foreignkey")
op.drop_column("git_models", "project_name")
# ### end Alembic commands ###
Loading

0 comments on commit 3566e03

Please sign in to comment.