Skip to content

Commit

Permalink
Setting dev environment with codespace (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet authored Oct 6, 2022
1 parent 4248686 commit 021e838
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 100 deletions.
13 changes: 13 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3/.devcontainer/base.Dockerfile

# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

COPY requirements.txt /tmp/pip-tmp/
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
&& rm -rf /tmp/pip-tmp
45 changes: 45 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.6-bullseye",
// Options
"NODE_VERSION": "lts/*"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"docker-in-docker": "latest",
"github-cli": "latest"
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ test_settings.yml
__pycache__
.eggs
bert_e.egg-info
.tox/
.tox/
settings.yml
128 changes: 30 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,47 @@

Scality's automated branch merging tool.

### How to install?

Make sure you are using Python version 3.5 or above.

```bash
$ mkdir bert-e && cd bert-e
$ virtualenv --python=python3 venv
$ source venv/bin/activate
$ pip install pip==9.0.1
# Install bert-e from bitbucket
$ pip install git+ssh://git@bitbucket.org/scality/bert-e.git
# Or, install bert-e from a local checkout
$ pip install --upgrade your_bert_e_code_directory_path
```
## User documentation

### How do I launch the standalone webhook listener (server.py) ?
User documentation can be found [here](./bert_e/docs/USER_DOC.md)

```bash
usage: bert-e-serve [-h] [--host HOST] [--port PORT]
[--settings-file SETTINGS_FILE] [--verbose]
## API documentation

Handles webhook calls.
API documentation can be found [here](./bert_e/docs/API_DOC.md)

optional arguments:
-h, --help show this help message and exit
--host HOST server host (defaults to 0.0.0.0)
--port PORT, -p PORT server port (defaults to 5000)
--settings-file SETTINGS_FILE, -f SETTINGS_FILE
settings-file location
--verbose, -v verbose mode
```
## Develop on Bert-E

First you have to export the following environment variables:
A codespace environment has been setup to develop on Bert-E.
It is the only supported method to develop on Bert-E.

* `BERT_E_GITHOST_PWD` Bert-E's password on Bitbucket or Github.
* `BERT_E_JIRA_TOKEN` Bert-E's API token on Jira. Can be created [here](https://id.atlassian.com/manage/api-tokens)
* `WEBHOOK_LOGIN`, `WEBHOOK_PWD` The HTTP BasicAuth credentials used to
authenticate the git host webhook requests.
* `BERT_E_CLIENT_ID`, `BERT_E_CLIENT_SECRET` the OAuth key
used to authenticate users who want to login and access Bert-E's API.
All above instructions will assume you are inside the codespace environment

Ensure settings-file contains configuration for the project you want
Bert-E to handle. A commented sample file is included (settings.sample.yml).
Place the template in a file called:
### Run the bot locally

{settings_dir}/{owner}/{slug}
```shell
$ cp settings.sample.yml settings.yml
# Configure settings.yml to your liking
$ tox -e run
```

Then simply run:
### Run local tests

```
$ bert-e-serve --host 0.0.0.0 --port 8080
```
A series of test scenario will be executed locally using mocks.

The server is now listening for webhooks on
`http://<webhook_login>:<webhook_pwd>@localhost:8080/bitbucket/`.

You can access the monitoring page without authentication on
`http://localhost:8080/`.


### How to launch tests?

You should check that you have set a password to your bitbucket account.
If the text input `Old password` doesn't appear here:
`https://bitbucket.org/account/password/change/<your_login>/`, you must set a password.

```bash
$ python -m bert_e.tests.test_bert_e <owner> \
<bert_e_username> <bert_e_password> \
<eva_username> <eva_password> \
<your_login> <your_password>
.............................................................s........
----------------------------------------------------------------------
Ran 103 tests in 152.139s

OK (skipped=2)


$ python -m bert_e.tests.test_bert_e --help
usage: test_bert_e.py [-h] [--repo-prefix REPO_PREFIX] [-v] [--failfast]
[--git-host GIT_HOST] [--disable-queues]
owner robot_username robot_password contributor_username
contributor_password admin_username admin_password
[tests [tests ...]]

Launches Bert-E tests.

positional arguments:
owner Owner of test repository (aka Bitbucket/GitHub team)
robot_username Robot Bitbucket/GitHub username
robot_password Robot Bitbucket/GitHub password
contributor_username Contributor Bitbucket/GitHub username
contributor_password Contributor Bitbucket/GitHub password
admin_username Privileged user Bitbucket/GitHub username
admin_password Privileged user Bitbucket/GitHub password
tests run only these tests

optional arguments:
-h, --help show this help message and exit
--repo-prefix REPO_PREFIX
Prefix of the test repository
-v Verbose mode
--failfast Return on first failure
--git-host GIT_HOST Choose the git host to run tests (slower tests)
--disable-queues deactivate queue feature during tests
```shell
$ tox -e tests
```

### How to Launch Static Checker File?
### Run tests against githost

```
$ flake8 bert-e/
```
This step will run the same tests as above but instead
of using mocks to interact with a githost, it will interact
with the one you have configured.

Credentials are required to run this step, checkout [`tox.ini`](./tox.ini)
file for more details about which credentials are required.

### Extra commands

Checkout the [`tox.ini`](./tox.ini) for all available commands to develop with
bert-e.
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ commands =
coverage html

[testenv:run]
passenv = BERT_E_* WEBHOOK_LOGIN
passenv = BERT_E_* WEBHOOK_*
setenv =
BERT_E_CLIENT_SECRET = {env:BERT_E_CLIENT_SECRET:'bert_e_client_secret'}
BERT_E_CLIENT_ID = {env:BERT_E_CLIENT_ID:'bert_e_client_id'}
BERT_E_GITHOST_PWD = {env:GITHUB_TOKEN}
BERT_E_JIRA_TOKEN = {env:BERT_E_JIRA_TOKEN:'jira_token'}
WEBHOOK_LOGIN = {env:WEBHOOK_LOGIN:'webhook'}
WEBHOOK_PWD = {env:WEBHOOK_PWD:'webhook'}

commands = bert-e-serve -v -f {env:BERT_E_SETTINGS:'settings.yml'}

[testenv:tests-githost]
Expand Down

0 comments on commit 021e838

Please sign in to comment.