Skip to content

add instructions to build a quick docker image for dev and production #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
.gitignore
Dockerfile*
DockerFile*
docker-compose*
README.md
LICENSE
.vscode
*.sock

24 changes: 24 additions & 0 deletions contrib/docker/DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM debian:stable

RUN apt-get update
RUN apt-get upgrade -y

# we need this to make https://deb.oxen.io fetches work
RUN apt-get install -y ca-certificates curl apt-utils ucf vim

# install the Oxen apt repository public signing key:
RUN curl -so /etc/apt/trusted.gpg.d/oxen.gpg https://deb.oxen.io/pub.gpg

# there is no lsb-release package on the base debian build
RUN echo "deb https://deb.oxen.io $(cat /etc/os-release | grep VERSION_CODENAME | cut -d "=" -f2) main" > /etc/apt/sources.list.d/oxen.list
RUN cat /etc/apt/sources.list.d/oxen.list
RUN apt-get update

RUN echo sogs-standalone session-pysogs/url-http string http://example.com | debconf-set-selections
RUN apt-get install -y sogs-standalone

# just add an alias to the pysogs start command
RUN echo '#!/bin/bash\n/usr/bin/uwsgi --uid _loki --ini /etc/sogs/uwsgi-standalone.ini' > /usr/bin/start-sogs-uwsgi && \
chmod +x /usr/bin/start-sogs-uwsgi

EXPOSE 80
30 changes: 30 additions & 0 deletions contrib/docker/DockerFile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# check docker/Readme.md
FROM debian:stable

RUN apt-get update
RUN apt-get upgrade -y

# we need this to make https://deb.oxen.io fetches work
RUN apt-get install -y ca-certificates

COPY contrib/deb.oxen.io.gpg /etc/apt/trusted.gpg.d/oxen.gpg


# there is no lsb-release package on the base debian build
RUN echo "deb https://deb.oxen.io $(cat /etc/os-release | grep VERSION_CODENAME | cut -d "=" -f2) main" > /etc/apt/sources.list.d/oxen.list
RUN cat /etc/apt/sources.list.d/oxen.list
RUN apt-get update
RUN apt -y install git vim python3-oxenmq python3-oxenc python3-pyonionreq python3-coloredlogs python3-uwsgidecorators python3-flask \
python3-cryptography python3-nacl python3-pil python3-protobuf python3-openssl python3-qrencode python3-better-profanity \
python3-sqlalchemy python3-sqlalchemy-utils uwsgi-plugin-python3 python3-pytest python3-pycryptodome python3-qrcode

# just add an alias to the pysogs-start command
RUN echo '#!/bin/bash\nuwsgi contrib/docker/uwsgi-sogs-docker.ini' > /usr/bin/start-sogs-uwsgi && \
chmod +x /usr/bin/start-sogs-uwsgi


RUN mkdir session-pysogs
WORKDIR session-pysogs


EXPOSE 80
75 changes: 75 additions & 0 deletions contrib/docker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Docker for pysogs production

Build the docker container image with

```
sudo docker build . -f contrib/docker/DockerFile -t pysogs-prod
```

Create docker volumes so we can persist data, config and key from the container to the host between container restarts

```
sudo docker volume create pysogs-data
sudo docker volume create pysogs-config
```

Start the container and mount the volumes with

```
sudo docker run -i -p 8080:80 -v pysogs-data:/var/lib/session-open-group-server -v pysogs-config:/etc/sogs/ -v pysogs-config:/etc/sogs/ -t pysogs-prod:latest
```

# Docker for pysogs development

The file DockerFile.dev is specifically made for development if you are not running linux.
It lets you create a docker running linux and the pysogs in it even if you are running Macos or Windows.
It creates a docker container with the content of this git repository mounted.
Basically, whatever you edit in this repository will be represented on the docker container. So when you run the container, it will run your code.

> **WARNING**: Not for production use. This docker image is strictly for development use and not supported for production use.

## Build the container image

You need to have docker installed on your computer. Follow the docker documentation for your system first.
Once you can run the hello world from github you should be fine

```
docker run hello-world # this command should print "Hello from Docker!"

```

Then, build the container image for pysogs-dev as

```
git clone [email protected]:oxen-io/session-pysogs.git
cd session-pysogs
sudo docker build . -f contrib/docker/DockerFile.dev -t pysogs-dev
```

Before you can run the container you need to set the base config. You can do so by copying `sogs.ini.sample` to `sogs.ini` and replacing the line with base_url with `base_url = http://localhost`.

> **WARNING**: Not for production use. This docker image is strictly for development use and not supported for production use.

Next, you can run and attach to the container with

```
sudo docker run -i -p 8080:80 -v $PWD:/session-pysogs -t pysogs-dev:latest
```

To start the pysogs once you have a shell in the container do:

```
start-sogs-uwsgi
```

To create a room once you have a shell inside the container do

```
python3 -msogs --add-room fishing --name "Fish Talk"
```

To play with Session and your own development pysogs you need to host you pysogs on a publicly accessible ip.
So this docker needs to be deployed on a server of some sort. Then, you can open the folder remotely (with the ssh vscode extension) or edit the files directly over ssh.
Using the vscode extension, you can also have a shell opened on the remote host, and so be able to quickly stop and restart the `start-sogs-uwsgi` command inside the container on code changes.

More doc at https://github.com/oxen-io/session-pysogs/blob/dev/administration.md#sogs-administration
30 changes: 30 additions & 0 deletions contrib/docker/uwsgi-sogs-docker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# uwsgi configuration for listening directly on port 80; this is the simplest setup, but is less
# flexible and slightly less performant than proxying through a front-end server (e.g. nginx) and
# cannot be used if anything else on the system always wants to serve any HTTP traffic.
#
# Note that this configuration is meant for setups where sogs will be directly serving public HTTP
# requests, and is sub-optimal for handling proxied requests; for that see the
# uwsgi-sogs-proxied.ini configuration instead.

# Configuration requires:
# - change the chdir= to the path where you want to write the sogs data files (database, uploads,
# keys, etc.)
#
# - change uid= and gid= values to the system user/group names that the script should run as. DO
# NOT RUN AS root! That path that you specify for `chdir=` should be owned by this user/group.
#
# - tweak the `processes` argument, if desired and you have more than 2 cores and expect a very busy
# SOGS.
#
# - if using uwsgi in vassal mode then put the configuration file into /etc/uwsgi/vassals
#
[uwsgi]
chdir = /session-pysogs
uid = root
gid = root
plugins = python3,http
processes = 2
enable-threads = true
http = :80
mount = /=sogs.web:app
mule = sogs.mule:run
2 changes: 1 addition & 1 deletion sogs.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
[rooms]

; How many days we consider a user to be "active" in a room without having at least retrieved
; messages from the room, in days. (This must be active_prune_threshold, below).
; messages from the room, in days. (This must be <= active_prune_threshold, below).
;
;active_threshold = 7

Expand Down