Skip to content

Commit 4b30cb8

Browse files
committed
helm: add mosbot chart
- Use the Common chart - Add instructions for the Helm chart - Upgrade Docker base image python version - Update Dockerfile to install mosbot correctly - Remove unneded images from docker-compose.yml - Fix reStructuredText markup in docs
1 parent 957efbd commit 4b30cb8

File tree

14 files changed

+203
-41
lines changed

14 files changed

+203
-41
lines changed

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
FROM python:3.6-slim
1+
FROM python:3.7-slim
22

33
WORKDIR /usr/src/app
44

55
RUN pip install pipenv
66
COPY Pipfile Pipfile.lock ./
7-
RUN pipenv install
8-
9-
COPY dist/abot-0.0.1a0.tar.gz ./mosbot.tar.gz
10-
RUN tar xf mosbot.tar.gz --strip-components=1
7+
RUN pipenv sync
118

9+
COPY setup.cfg setup.py README.rst alembic.ini ./
10+
COPY alembic ./alembic
11+
COPY mosbot ./mosbot
1212
RUN pipenv run python setup.py develop
1313

14-
CMD ["pipenv", "run", "bot", "run"]
15-
14+
CMD ["/bin/sh", "-c", "pipenv run alembic upgrade head && pipenv run bot run"]

README.rst

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1+
12
How to get started
23
------------------
34

45
1. Install *Pipenv* at a system level
5-
6+
67
If you are not using it for your projects, you should. *Pipenv* is a mix between *pip* and *virtualenv* (it uses
78
both of them below) and basically manages everything. You can probably find *Pipenv* packaged, check their webpage
89
for installation steps.
910

1011
2. Install dependencies
11-
12+
1213
In a command line, navigate to the current project directory and install the dependencies by running one of the
1314
commands below.
1415

15-
* To use the bot: `pipenv install`
16+
* To use the bot: ``pipenv install``
1617

17-
* To develop: `pipenv install -d`
18+
* To develop: ``pipenv install -d``
1819

1920
If these steps don't work, please report it so that I can update these instructions with relevant steps.
2021

2122
3. Install *mostbot* as a package
22-
23-
Run the command `python setup.py develop`. You can also do `python setup.py install`, but it's better to keep the
24-
installation linked to this directory instead of having `setuptools` package and install the bot separately. If you
23+
24+
Run the command ``python setup.py develop``. You can also do ``python setup.py install``, but it's better to keep the
25+
installation linked to this directory instead of having ``setuptools`` package and install the bot separately. If you
2526
have doubts on what I just said, https://stackoverflow.com/questions/19048732/python-setup-py-develop-vs-install
2627

2728
4. Install a database
28-
29+
2930
Apart from the bot code, you also need a database to link the bot to. You can link it to whatever *PostgreSQL*
3031
database you want, but I would recommend you to run a local instance.
31-
32+
3233
Using *Docker* and *Docker Compose* is a really good way to run packaged software. There are complete guides on the
3334
internet about how to run them, but for the basics:
3435

3536
1. Install *Docker* either using your package manager or as suggested in *Docker*'s official webpage. By the way,
3637
the official website method is just a Python script, so you can also install it with *pip* (I would
3738
discourage this option).
38-
39+
3940
2. Install *Docker Compose*. Same thing as *Docker*: user either package manager or the official webpage script.
40-
41+
4142
3. Open another terminal in this folder. This new terminal will be used all the time to maintain up the database
4243
while your bot is running. There are other ways to run the database in the background, but I recommend this
4344
one.
44-
45-
4. In the new terminal, run `docker-compose up` to download and run the packaged software (the *PostgreSQL*
45+
46+
4. In the new terminal, run ``docker-compose up`` to download and run the packaged software (the *PostgreSQL*
4647
database in this case).
47-
48-
5. Run `alembic upgrade head` to create the database structure by setting up all the database tables, etc.
48+
49+
5. Run ``alembic upgrade head`` to create the database structure by setting up all the database tables, etc.
4950

5051
5. Launch *mosbot*
51-
52-
Go back to the first terminal, and run `bot` to launch. The output of the command should be self explanatory.
52+
53+
Go back to the first terminal, and run ``bot`` to launch. The output of the command should be self explanatory.
5354

5455

5556

@@ -59,20 +60,20 @@ Project structure
5960
This is a brief outline to cover the basics of the project structure:
6061

6162
* The more inner layer and the thing that most defines the bot is the Data Model. This are the Entities that we
62-
manage, and they are in `mosbot/db.py`.
63+
manage, and they are in ``mosbot/db.py``.
6364

6465
* From there, because we have no ORM at the moment (asyncio doesn't have an async ORM yet), we have all the functions
65-
and queries that operate on the data in `mosbot/query.py`.
66+
and queries that operate on the data in ``mosbot/query.py``.
6667

6768
* Now you should be able to gather/write data and make some operations. There are some operations that are not as
6869
"simple" as the queries, and these are the "usecases" where you have a whole flow of queries and data transformation.
69-
The place where these are stored is in `mosbot/usecase.py`
70+
The place where these are stored is in ``mosbot/usecase.py``
7071

7172
* Finally, in the most outer layer, you have the two main "interfaces", this is where we receive the data from the
72-
`abot` library and we have the handlers and commands. The files are, `mosbot/handler.py` for event handlers and
73-
`mosbot/command.py` for the commands.
73+
``abot`` library and we have the handlers and commands. The files are, ``mosbot/handler.py`` for event handlers and
74+
``mosbot/command.py`` for the commands.
7475

75-
* There are two other files, that are "transversal" that are the `mosbot/utils.py` and `mosbot/config.py`.
76+
* There are two other files, that are "transversal" that are the ``mosbot/utils.py`` and ``mosbot/config.py``.
7677

7778

7879
You should think of this architecture (file structure/function dependencies) as an onion. The idea is that the most
@@ -91,6 +92,22 @@ Further recommendations
9192
rest of alternatives. Of course, you are free to choose whichever editor you want.
9293

9394

95+
Using the Helm chart
96+
--------------------
97+
98+
1. Fetch/update chart dependencies:
99+
100+
.. code-block:: bash
101+
102+
helm dependency update ./helm
103+
104+
105+
2. Install mosbot chart:
106+
107+
.. code-block:: bash
108+
109+
helm install ./helm
110+
94111
95112
Contributions
96113
-------------

docker-compose.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
version: '2'
22
services:
3-
rabbitmq:
4-
image: rabbitmq:management
5-
ports:
6-
- "15672:15672"
7-
- "5672:5672"
8-
- "4369:4369"
9-
redis:
10-
image: redis
11-
ports:
12-
- "6379:6379"
133
postgres:
144
image: mdillon/postgis
155
ports:
166
- "5432:5432"
7+
# mosbot:
8+
# image: dtgoitia/mosbot:latest
9+
# environment:
10+
# DATABASE_URL: postgresql://postgres@postgres/postgres
11+
# depends_on:
12+
# - postgres

helm/.helmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
.vscode/

helm/Chart.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
name: mosbot
3+
description: Master of Soundtrack bot
4+
version: 0.0.1
5+
appVersion: 0.0.1
6+
home: https://github.com/txomon/mosbot
7+
sources:
8+
- https://github.com/txomon/mosbot
9+
keywords:
10+
- bot
11+
- mosbot
12+
- master of soundtrack
13+
maintainers:
14+
- name: txomon
15+

helm/charts/common-0.0.5.tgz

8.15 KB
Binary file not shown.

helm/charts/postgresql-3.13.1.tgz

17.5 KB
Binary file not shown.

helm/requirements.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dependencies:
2+
- name: common
3+
repository: http://storage.googleapis.com/kubernetes-charts-incubator
4+
version: 0.0.5
5+
- name: postgresql
6+
repository: https://kubernetes-charts.storage.googleapis.com
7+
version: 3.13.1
8+
digest: sha256:e1563a17669e7c46c9db98c4322374903cd88974b24634e0334047f98c2eacc3
9+
generated: "2019-05-19T08:39:48.617716388+01:00"

helm/requirements.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencies:
2+
- name: common
3+
repository: http://storage.googleapis.com/kubernetes-charts-incubator
4+
version: 0.0.5
5+
- name: postgresql
6+
repository: https://kubernetes-charts.storage.googleapis.com
7+
version: 3.13.1

helm/templates/NOTES.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
{{- range $host := .Values.ingress.hosts }}
4+
{{- range .paths }}
5+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
6+
{{- end }}
7+
{{- end }}
8+
{{- else if contains "NodePort" .Values.service.type }}
9+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "mosbot-chart.fullname" . }})
10+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
11+
echo http://$NODE_IP:$NODE_PORT
12+
{{- else if contains "LoadBalancer" .Values.service.type }}
13+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
14+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "mosbot-chart.fullname" . }}'
15+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "mosbot-chart.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
16+
echo http://$SERVICE_IP:{{ .Values.service.port }}
17+
{{- else if contains "ClusterIP" .Values.service.type }}
18+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "mosbot-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
19+
echo "Visit http://127.0.0.1:8080 to use your application"
20+
kubectl port-forward $POD_NAME 8080:80
21+
{{- end }}

0 commit comments

Comments
 (0)