Skip to content

Commit 4765126

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 4765126

File tree

14 files changed

+196
-41
lines changed

14 files changed

+196
-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: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,54 @@ How to get started
22
------------------
33

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

1010
2. Install dependencies
11-
11+
1212
In a command line, navigate to the current project directory and install the dependencies by running one of the
1313
commands below.
1414

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

17-
* To develop: `pipenv install -d`
17+
* To develop: ``pipenv install -d``
1818

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

2121
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
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
2525
have doubts on what I just said, https://stackoverflow.com/questions/19048732/python-setup-py-develop-vs-install
2626

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

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

5050
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.
51+
52+
Go back to the first terminal, and run ``bot`` to launch. The output of the command should be self explanatory.
5353

5454

5555

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

6161
* 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`.
62+
manage, and they are in ``mosbot/db.py``.
6363

6464
* 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`.
65+
and queries that operate on the data in ``mosbot/query.py``.
6666

6767
* Now you should be able to gather/write data and make some operations. There are some operations that are not as
6868
"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`
69+
The place where these are stored is in ``mosbot/usecase.py``
7070

7171
* 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.
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.
7474

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

7777

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

9393

94+
Using the Helm chart
95+
--------------------
96+
97+
1. Install dependencies:
98+
99+
.. code-block:: bash
100+
101+
cd ./helm
102+
helm dependency update
103+
94104
95105
Contributions
96106
-------------

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)