emojirades


Nameemojirades JSON
Version 1.10.0 PyPI version JSON
download
home_pagehttps://github.com/emojirades/emojirades
SummarySlack bot that understands the Emojirades game!
upload_time2023-04-17 11:11:08
maintainer
docs_urlNone
authorThe Emojirades Team
requires_python>=3.8
licenseAGPLv3
keywords slack slackbot emojirades plusplus game
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Emojirades
Slack bot that understands the emojirades game and handles score keeping.

![CI Status](https://github.com/emojirades/emojirades/actions/workflows/ci.yml/badge.svg) ![PyPI version](https://badge.fury.io/py/emojirades.svg)

# Developing
## Install the dependencies
```bash
pip3 install --upgrade pip wheel
```

## Install the module & dependencies
```bash
pip3 install -e .[dev]
```

## Run the tests
```bash
# Linter
pylint emojirades

# Formatter
black --check .

# Tests w/no stdout
pytest

# Tests w/stdout
pytest -s
```

## Creating new DB revisions
If you make changes to `emojirades/persistence/models` you'll need to generate new revisions. This tracks the changes and applies them to the DB at each bots startup
```
cd emojirades/persistence/models
alembic revision --autogenerate --message "<useful insightful few words>"
```

# Running
## Set Environment Variables
If you're using an auth file from AWS S3 you'll need to set the appropriate `AWS_` environment variables!

## Separate Database
Using a database like PostgreSQL, you'll need to have created a database with a username and password before starting this.

If you've just created a fresh DB, you'll need to load the initial database:
```
emojirades -vv init --db-uri "sqlite:///emojirades.db"
```

After initialising the DB you can load in any optional pre-existing state.

The json files must be a list of objects, with each objects `key: value` representing a column in the associated model

If you are coming from the old style of state.json and scores.json you can run the following to produce json files that can be used in the above populate command

```
./bin/old_to_new_persistence.py --workspace-id TABC123 --state-file state.json --score-file scores.json
```

This will produce `state.json.processed`, `scores.json.processed_scores` and `scores.json.processed_score_history`

They can be populated by running:
```
emojirades -vv populate --db-uri "sqlite:///emojirades.db" --table gamestate --data-file state.json.processed
emojirades -vv populate --db-uri "sqlite:///emojirades.db" --table scoreboard --data-file scores.json.processed_scores
emojirades -vv populate --db-uri "sqlite:///emojirades.db" --table scoreboard_history --data-file scores.json.processed_score_history
```

## Run the daemon for a single workspace
This command uses locally stored files to keep the game state:

`emojirades single --db-uri sqlite:///emojirades.db --auth-uri auth.json`

This command uses a separate PostgreSQL DB and an auth file from AWS S3:

`emojirades single --db-uri postgresql://user:pass@hostname/database --auth-uri s3://bucket/auth.json`

## Run the daemon for multiple workspaces
Here we provide a local folder of workspaces and an optional set of workspace ids (will load all in folder by default):

`emojirades mulitple --workspaces-dir path/to/workspaces [--workspace-id A1B2C3D4E]`

Here we provide an S3 path of workspaces and an optional set of workspace ids (will load all in folder by default):

`emojirades multiple --workspaces-dir s3://bucket/path/to/workspaces [--workspace-id A1B2C3D4E]`

Here we provide an S3 path of workspaces and an AWS SQS queue to listen to for new workspaces:

`emojirades multiple --workspaces-dir s3://bucket/path/to/workspaces --onboarding-queue workspace-onboarding-queue`

Here we provide an S3 path of workspaces and override the db_uri:

`emojirades multiple --workspaces-dir s3://bucket/path/to/workspaces --db-uri sqlite:///emojirades.db`

The workspaces directory must be in the following format (local or s3):
```
./workspaces

./workspaces/shards
./workspaces/shards/0
./workspaces/shards/0/A1B2C3D4E.json
./workspaces/shards/0/Z9Y8X7W6V.json

./workspaces/directory
./workspaces/directory/A1B2C3D4E
./workspaces/directory/A1B2C3D4E/auth.json
./workspaces/directory/Z9Y8X7W6V
./workspaces/directory/Z9Y8X7W6V/auth.json
```

Each instance of the bot will listen to a specific shard (specified as the --workspaces-dir).

The contents of the shard config (eg. `./workspaces/shards/0/A1B2C3D4E.json`) will be a file similar to:
```
{
  "workspace_id": "A1B2C3D4E",
  "db_uri": "sqlite:////data/emojirades.db",  # Optional, needed if you do not specify one with the bot itself
  "auth_uri": "s3://bucket/workspaces/directory/A1B2C3D4E/auth.json",
}
```

The concept above with the two different directories is shards to allow for the bot to scale out horizontally. As the bot(s) get busier, the operator can increase the shard count (number of bot instances) and new onboarded workspaces are allocated to the next available shard with capacity.

The emojirades bot will take care of running multiple games across different channels in a single workspace. This is a limitation in the design currently where you need a bot-per-workspace.

## Service configuration
```
cp emojirades.service /etc/systemd/system/
sudo chmod 0664 /etc/systemd/system/emojirades.service

# Edit the /etc/systemd/system/emojirades.service file and update the user and group

cp emojirades.config /etc/emojirades
sudo chmod 0400 /etc/emojirades

# Edit the /etc/emojirades config file with your configuration for the bot

sudo systemctl daemon-reload
sudo systemctl enable emojirades
sudo systemctl start emojirades

```
# Release process
1. Checkout master branch
2. Update `emojirades/__init__.py` with the new version (vX.Y.Z)
3. Commit
4. Tag the commit with vX.Y.Z
5. `git push; git push --tags` together
4. Github Actions will trigger the Release Job when a tagged commit to master is detected
    1. Changelog will be generated and a Github Release as well with the changelog
    2. New python wheel will be built and published to PyPI and attached to the Release
    3. New container image will be built and published to Github Container Registry

## Building the Container Image
```
docker build --pull --no-cache -t ghcr.io/emojirades/emojirades:X.Y.Z -t ghcr.io/emojirades/emojirades:latest .
```

## Running the Container
In this example we run the game with S3 hosted configuration for a single workspace.

```
docker run -d \
  --name emojirades \
  --restart=always \
  -v "/path/to/your/.aws/:/root/.aws/:ro" \
  -v "emojirades-data:/data" \
  -e "AWS_PROFILE=emojirades" \
  ghcr.io/emojirades/emojirades:X.Y.X \
    --db-uri sqlite:////data/emojirades.db \
    --auth-uri s3://bucket/path/to/auth.json \
    -vv
```

## Migrating from SQLite to Postgres
This assumes you have a local copy of your sqlite DB file and already setup and can access your postgres DB.

```bash
# Sourced venv/etc

# Init the DB to setup the table structure
./bin/emojirades init --db-uri 'postgresql+psycopg2://user:password@host:port/dbname'

# Run the migration script
./bin/sqlite_to_postgres.py \
    --source-db-uri 'sqlite+pysqlite:///relative/path/to/emojirades.db' \
    --target-db-uri 'postgresql+psycopg2://user:password@host:port/dbname'

# Update the sequences by logging into postgres and resetting them to +1
emojirades=# select max(event_id) from gamestate_history;
 max
------
 3086
(1 row)

emojirades=# ALTER SEQUENCE gamestate_history_event_id_seq RESTART WITH 3087;
ALTER SEQUENCE

emojirades=# select max(event_id) from scoreboard_history;
 max
------
 1622
(1 row)

emojirades=# ALTER SEQUENCE scoreboard_history_event_id_seq RESTART WITH 1623;
ALTER SEQUENCE
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/emojirades/emojirades",
    "name": "emojirades",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "slack slackbot emojirades plusplus game",
    "author": "The Emojirades Team",
    "author_email": "support@emojirades.io",
    "download_url": "https://files.pythonhosted.org/packages/f6/c5/95562b9f96ec33ba2de7a8e5ecc9d68416a95c4d586cade7615b8f879739/emojirades-1.10.0.tar.gz",
    "platform": null,
    "description": "# Emojirades\nSlack bot that understands the emojirades game and handles score keeping.\n\n![CI Status](https://github.com/emojirades/emojirades/actions/workflows/ci.yml/badge.svg) ![PyPI version](https://badge.fury.io/py/emojirades.svg)\n\n# Developing\n## Install the dependencies\n```bash\npip3 install --upgrade pip wheel\n```\n\n## Install the module & dependencies\n```bash\npip3 install -e .[dev]\n```\n\n## Run the tests\n```bash\n# Linter\npylint emojirades\n\n# Formatter\nblack --check .\n\n# Tests w/no stdout\npytest\n\n# Tests w/stdout\npytest -s\n```\n\n## Creating new DB revisions\nIf you make changes to `emojirades/persistence/models` you'll need to generate new revisions. This tracks the changes and applies them to the DB at each bots startup\n```\ncd emojirades/persistence/models\nalembic revision --autogenerate --message \"<useful insightful few words>\"\n```\n\n# Running\n## Set Environment Variables\nIf you're using an auth file from AWS S3 you'll need to set the appropriate `AWS_` environment variables!\n\n## Separate Database\nUsing a database like PostgreSQL, you'll need to have created a database with a username and password before starting this.\n\nIf you've just created a fresh DB, you'll need to load the initial database:\n```\nemojirades -vv init --db-uri \"sqlite:///emojirades.db\"\n```\n\nAfter initialising the DB you can load in any optional pre-existing state.\n\nThe json files must be a list of objects, with each objects `key: value` representing a column in the associated model\n\nIf you are coming from the old style of state.json and scores.json you can run the following to produce json files that can be used in the above populate command\n\n```\n./bin/old_to_new_persistence.py --workspace-id TABC123 --state-file state.json --score-file scores.json\n```\n\nThis will produce `state.json.processed`, `scores.json.processed_scores` and `scores.json.processed_score_history`\n\nThey can be populated by running:\n```\nemojirades -vv populate --db-uri \"sqlite:///emojirades.db\" --table gamestate --data-file state.json.processed\nemojirades -vv populate --db-uri \"sqlite:///emojirades.db\" --table scoreboard --data-file scores.json.processed_scores\nemojirades -vv populate --db-uri \"sqlite:///emojirades.db\" --table scoreboard_history --data-file scores.json.processed_score_history\n```\n\n## Run the daemon for a single workspace\nThis command uses locally stored files to keep the game state:\n\n`emojirades single --db-uri sqlite:///emojirades.db --auth-uri auth.json`\n\nThis command uses a separate PostgreSQL DB and an auth file from AWS S3:\n\n`emojirades single --db-uri postgresql://user:pass@hostname/database --auth-uri s3://bucket/auth.json`\n\n## Run the daemon for multiple workspaces\nHere we provide a local folder of workspaces and an optional set of workspace ids (will load all in folder by default):\n\n`emojirades mulitple --workspaces-dir path/to/workspaces [--workspace-id A1B2C3D4E]`\n\nHere we provide an S3 path of workspaces and an optional set of workspace ids (will load all in folder by default):\n\n`emojirades multiple --workspaces-dir s3://bucket/path/to/workspaces [--workspace-id A1B2C3D4E]`\n\nHere we provide an S3 path of workspaces and an AWS SQS queue to listen to for new workspaces:\n\n`emojirades multiple --workspaces-dir s3://bucket/path/to/workspaces --onboarding-queue workspace-onboarding-queue`\n\nHere we provide an S3 path of workspaces and override the db_uri:\n\n`emojirades multiple --workspaces-dir s3://bucket/path/to/workspaces --db-uri sqlite:///emojirades.db`\n\nThe workspaces directory must be in the following format (local or s3):\n```\n./workspaces\n\n./workspaces/shards\n./workspaces/shards/0\n./workspaces/shards/0/A1B2C3D4E.json\n./workspaces/shards/0/Z9Y8X7W6V.json\n\n./workspaces/directory\n./workspaces/directory/A1B2C3D4E\n./workspaces/directory/A1B2C3D4E/auth.json\n./workspaces/directory/Z9Y8X7W6V\n./workspaces/directory/Z9Y8X7W6V/auth.json\n```\n\nEach instance of the bot will listen to a specific shard (specified as the --workspaces-dir).\n\nThe contents of the shard config (eg. `./workspaces/shards/0/A1B2C3D4E.json`) will be a file similar to:\n```\n{\n  \"workspace_id\": \"A1B2C3D4E\",\n  \"db_uri\": \"sqlite:////data/emojirades.db\",  # Optional, needed if you do not specify one with the bot itself\n  \"auth_uri\": \"s3://bucket/workspaces/directory/A1B2C3D4E/auth.json\",\n}\n```\n\nThe concept above with the two different directories is shards to allow for the bot to scale out horizontally. As the bot(s) get busier, the operator can increase the shard count (number of bot instances) and new onboarded workspaces are allocated to the next available shard with capacity.\n\nThe emojirades bot will take care of running multiple games across different channels in a single workspace. This is a limitation in the design currently where you need a bot-per-workspace.\n\n## Service configuration\n```\ncp emojirades.service /etc/systemd/system/\nsudo chmod 0664 /etc/systemd/system/emojirades.service\n\n# Edit the /etc/systemd/system/emojirades.service file and update the user and group\n\ncp emojirades.config /etc/emojirades\nsudo chmod 0400 /etc/emojirades\n\n# Edit the /etc/emojirades config file with your configuration for the bot\n\nsudo systemctl daemon-reload\nsudo systemctl enable emojirades\nsudo systemctl start emojirades\n\n```\n# Release process\n1. Checkout master branch\n2. Update `emojirades/__init__.py` with the new version (vX.Y.Z)\n3. Commit\n4. Tag the commit with vX.Y.Z\n5. `git push; git push --tags` together\n4. Github Actions will trigger the Release Job when a tagged commit to master is detected\n    1. Changelog will be generated and a Github Release as well with the changelog\n    2. New python wheel will be built and published to PyPI and attached to the Release\n    3. New container image will be built and published to Github Container Registry\n\n## Building the Container Image\n```\ndocker build --pull --no-cache -t ghcr.io/emojirades/emojirades:X.Y.Z -t ghcr.io/emojirades/emojirades:latest .\n```\n\n## Running the Container\nIn this example we run the game with S3 hosted configuration for a single workspace.\n\n```\ndocker run -d \\\n  --name emojirades \\\n  --restart=always \\\n  -v \"/path/to/your/.aws/:/root/.aws/:ro\" \\\n  -v \"emojirades-data:/data\" \\\n  -e \"AWS_PROFILE=emojirades\" \\\n  ghcr.io/emojirades/emojirades:X.Y.X \\\n    --db-uri sqlite:////data/emojirades.db \\\n    --auth-uri s3://bucket/path/to/auth.json \\\n    -vv\n```\n\n## Migrating from SQLite to Postgres\nThis assumes you have a local copy of your sqlite DB file and already setup and can access your postgres DB.\n\n```bash\n# Sourced venv/etc\n\n# Init the DB to setup the table structure\n./bin/emojirades init --db-uri 'postgresql+psycopg2://user:password@host:port/dbname'\n\n# Run the migration script\n./bin/sqlite_to_postgres.py \\\n    --source-db-uri 'sqlite+pysqlite:///relative/path/to/emojirades.db' \\\n    --target-db-uri 'postgresql+psycopg2://user:password@host:port/dbname'\n\n# Update the sequences by logging into postgres and resetting them to +1\nemojirades=# select max(event_id) from gamestate_history;\n max\n------\n 3086\n(1 row)\n\nemojirades=# ALTER SEQUENCE gamestate_history_event_id_seq RESTART WITH 3087;\nALTER SEQUENCE\n\nemojirades=# select max(event_id) from scoreboard_history;\n max\n------\n 1622\n(1 row)\n\nemojirades=# ALTER SEQUENCE scoreboard_history_event_id_seq RESTART WITH 1623;\nALTER SEQUENCE\n```\n",
    "bugtrack_url": null,
    "license": "AGPLv3",
    "summary": "Slack bot that understands the Emojirades game!",
    "version": "1.10.0",
    "split_keywords": [
        "slack",
        "slackbot",
        "emojirades",
        "plusplus",
        "game"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5308460464e14d910e41166463444e0d2839d6ad2a7a8218b2404edb202487f0",
                "md5": "83dabe4d1af821e5177c0b7fb054fd6f",
                "sha256": "e710250e324800abb48ec76bdb998540c3f69ab6647a6e07ae3f770d72ba7b7b"
            },
            "downloads": -1,
            "filename": "emojirades-1.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "83dabe4d1af821e5177c0b7fb054fd6f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 57719,
            "upload_time": "2023-04-17T11:11:06",
            "upload_time_iso_8601": "2023-04-17T11:11:06.895692Z",
            "url": "https://files.pythonhosted.org/packages/53/08/460464e14d910e41166463444e0d2839d6ad2a7a8218b2404edb202487f0/emojirades-1.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6c595562b9f96ec33ba2de7a8e5ecc9d68416a95c4d586cade7615b8f879739",
                "md5": "4971cd77c254fe04e92b0c87d645a5d7",
                "sha256": "6f0356405cf3142007a9966bdd42b926e9455a248a7aea9409165f01458a2172"
            },
            "downloads": -1,
            "filename": "emojirades-1.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4971cd77c254fe04e92b0c87d645a5d7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 51580,
            "upload_time": "2023-04-17T11:11:08",
            "upload_time_iso_8601": "2023-04-17T11:11:08.251920Z",
            "url": "https://files.pythonhosted.org/packages/f6/c5/95562b9f96ec33ba2de7a8e5ecc9d68416a95c4d586cade7615b8f879739/emojirades-1.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-17 11:11:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "emojirades",
    "github_project": "emojirades",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "emojirades"
}
        
Elapsed time: 0.14322s