Skip to content

Commit

Permalink
Copy docker from Youps -- murmur docker is now working
Browse files Browse the repository at this point in the history
  • Loading branch information
soyapark committed Nov 25, 2019
1 parent 51350eb commit ede583c
Show file tree
Hide file tree
Showing 18 changed files with 400 additions and 56 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ schema/migrations/*
# Google secrets file
gmail_setup/client_secrets.json

sandbox/
sandbox/

env/

.env
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:2
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y mysql-client cron && rm -rf /var/lib/apt
RUN apt-get update && rm -rf /var/lib/apt
RUN mkdir -p /home/ubuntu/production/mailx
WORKDIR /home/ubuntu/production/mailx
COPY ./murmur-env/. /opt/murmur/
# COPY tasks-cron-docker /etc/cron.d/tasks-cron
# RUN crontab /etc/cron.d/tasks-cron
COPY requirements.txt /home/ubuntu/production/mailx/requirements.txt
RUN pip install --upgrade pip && pip install -r requirements.txt --no-cache-dir
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.PHONY: default
default: build reset-db start

# build the docker image
.PHONY: build
build:
docker-compose build

# start the docker image
.PHONY: start
start:
docker-compose up --force-recreate --build -d

# stop the docker image
.PHONY: stop
stop:
docker-compose down

# stop the docker image and remove database information
.PHONY: clean
clean:
docker-compose down -v

# reset the database
.PHONY: reset-db
reset-db:
mkdir -p schema/migrations
docker-compose run web scripts/new_database_unsafe.sh

# attach a shell to the running docker image
.PHONY: shell
shell:
docker exec -it murmur_web /bin/sh -c "[ -e /bin/bash ] && /bin/bash || /bin/sh" || echo "\e[33mmake sure you already ran make start\e[0m"

.PHONY: solo-shell
solo-shell:
docker-compose run web /bin/sh -c "[ -e /bin/bash ] && /bin/bash || /bin/sh"

# get a manage.py shell for running django things
.PHONY: django-shell
django-shell:
docker exec -it murmur_web python manage.py shell && from schema.youps import *

# show logs for the running docker containers
.PHONY: logs
logs:
docker-compose logs -f

# old script for updating code on the server after pushing
.PHONY: update-dev
update-dev:
ssh -t [email protected] " \
cd /home/ubuntu/production/mailx; \
git pull; \
sudo lamson restart || sudo lamson start; \
./youps_reboot.sh \
"
4 changes: 2 additions & 2 deletions browser/templates/murmur/mobile_list_posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ <h4><label class="label2" id="tag_{{ forloop.counter0 }}" style="background-colo

<div class="post-list-container">

{% if active_group.name != "No Groups Yet" %}
{% if active_group.name != "No Groups Yet" and is_member%}
<a href="/groups/{{ active_group.name }}/create_post"><button type="button">+ New Post</button></a>
<a href="/groups/{{ active_group.name }}"><button type="button">View Group Info</button></a>
<BR><BR>
<input type="text" class="default-text" value="Search within posts" title="Search within posts"/>
{% elif not is_member %}
<a href="/accounts/login/"><button type="button">Join the list</button></a>
<a href="/accounts/login/?next=/groups/{{ active_group.name }}"><button type="button">Join the list</button></a>
<a href="/accounts/register/">Don't have a Murmur account yet?</a>
{% else %}
<i>You are not in any groups yet. <a href="/group_list">Join or create a new group.</a>
Expand Down
1 change: 1 addition & 0 deletions browser/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <h3>{{ website | title }} Login</h3>
{{ form.as_p }}
<br />
<input type="submit" class="btn btn-primary" value="Log In" />
<!-- https://stackoverflow.com/questions/24234134/django-1-6-redirect-to-last-page-after-login -->
<input type="hidden" name="next" value="{{ next }}" />
</form>
<br />
Expand Down
2 changes: 1 addition & 1 deletion config/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ formatter=defaultFormatter
args=("logs/murmur_smtp.log",)

[formatter_defaultFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
format=%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s
datefmt=
4 changes: 2 additions & 2 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# You may add additional parameters such as `username' and `password' if your
# relay server requires authentication, `starttls' (boolean) or `ssl' (boolean)
# for secure connections.
relay_config = {'host': 'localhost', 'port': 8825}
relay_config = {'host': os.getenv('RELAY_HOST', 'localhost'), 'port': 587 }

receiver_config = {'host': 'localhost', 'port': 8823}
receiver_config = {'host': '0.0.0.0', 'port': 25}

handlers = ['smtp_handler.main']

Expand Down
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3"

services:
db:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_PASS}
volumes:
- youps-db:/var/lib/mysql
restart: always
web:
build: .
container_name: murmur_web
command: bash -c "lamson start; cron && python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/home/ubuntu/production/mailx
ports:
- "8000:8000"
depends_on:
- db
- smtp
environment:
- RELAY_HOST=${RELAY_HOST} # only for local development
- DATABASE_NAME=${DATABASE_NAME}
- MYSQL_PASS=${MYSQL_PASS}
- DOMAIN_NAME=${DOMAIN_NAME}
- DATABASE_HOST=${DATABASE_HOST}
restart: on-failure
smtp:
image: namshi/smtp
expose:
- 587
environment:
- GMAIL_USER=${GMAIL_USER}
- GMAIL_PASSWORD=${GMAIL_PASSWORD}
- PORT=587
restart: always
volumes:
youps-db:
63 changes: 37 additions & 26 deletions http_handler/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,50 @@
_WEBSITE_FILE_PATH = '/opt/murmur/website'

def _get_env():
f = open(_ENV_FILE_PATH)
env = f.read()
try:
f = open(_ENV_FILE_PATH)
env = f.read()

if env[-1] == '\n':
env = env[:-1]

f.close()
return env
except Exception:
return "local"

if env[-1] == '\n':
env = env[:-1]

f.close()
return env
ENV = _get_env()

def _get_debug():
f = open(_DEBUG_FILE_PATH)
debug = f.read()

if debug[-1] == '\n':
debug = debug[:-1]

f.close()
if debug == 'true':
try:
f = open(_DEBUG_FILE_PATH)
debug = f.read()

if debug[-1] == '\n':
debug = debug[:-1]

f.close()
if debug == 'true':
return True
else:
return False
except Exception:
return True
else:
return False

DEBUG = _get_debug()

def _get_website():
f = open(_WEBSITE_FILE_PATH)
website = f.read()

if website[-1] == '\n':
website = website[:-1]

f.close()
return website
try:
f = open(_WEBSITE_FILE_PATH)
website = f.read()

if website[-1] == '\n':
website = website[:-1]

f.close()
return website
except Exception:
return "murmur"

WEBSITE = _get_website()

Expand Down Expand Up @@ -192,6 +202,7 @@ def _get_website():
WSGI_APPLICATION = 'http_handler.wsgi.application'

TEMPLATE_DIRS = (
"/home/ubuntu/production/mailx/browser/templates"
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
Expand Down Expand Up @@ -275,7 +286,7 @@ def _get_website():
'level': 'DEBUG',
'class': 'logging.FileHandler',
# TODO change this to relative path
'filename': '/home/ubuntu/murmur/logs/murmur.log',
'filename': '/home/ubuntu/production/mailx/logs/murmur.log',
'formatter': 'custom.debug'
}
},
Expand Down
1 change: 1 addition & 0 deletions murmur-env/debug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
1 change: 1 addition & 0 deletions murmur-env/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local
1 change: 1 addition & 0 deletions murmur-env/protocol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http
1 change: 1 addition & 0 deletions murmur-env/website
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
murmur
28 changes: 4 additions & 24 deletions schema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Post(models.Model):
# if the author is null, then the person who wrote the message isn't actually
# a member of this group on Murmur, and it was likely received via a list that
# fwds to this Murmur group
poster_email = models.EmailField(max_length=255, null=True)
poster_email = models.EmailField(max_length=100, null=True)

# often "from" header is Firstname LastName <[email protected]>. if so, save that name.
poster_name = models.CharField(max_length=50, null=True)
Expand Down Expand Up @@ -198,7 +198,7 @@ class Meta:

class ForwardingList(models.Model):
id = models.AutoField(primary_key=True)
email = models.EmailField(verbose_name='email address',max_length=255)
email = models.EmailField(verbose_name='email address',max_length=100)
timestamp = models.DateTimeField(auto_now=True)
group = models.ForeignKey('Group')
url = models.URLField(null=True, blank=True)
Expand Down Expand Up @@ -236,7 +236,7 @@ class Meta:
class WhiteOrBlacklist(models.Model):
id = models.AutoField(primary_key=True)
group = models.ForeignKey('Group')
email = models.EmailField(max_length=255)
email = models.EmailField(max_length=100)

# only one of the following can be true
whitelist = models.BooleanField(default=False)
Expand Down Expand Up @@ -275,7 +275,7 @@ def create_superuser(self, email, password):
class UserProfile(AbstractBaseUser):
email = models.EmailField(
verbose_name='email address',
max_length=255,
max_length=100,
unique=True,
)
first_name = models.CharField('first name', max_length=30, blank=True)
Expand Down Expand Up @@ -319,26 +319,6 @@ def is_staff(self):
"Is the user a member of staff?"
return self.is_admin

class ImapAccount(models.Model):
newest_msg_id = models.IntegerField(default=-1)

email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
password = models.CharField('password', max_length=100, blank=True)
host = models.CharField('host', max_length=100)

is_oauth = models.BooleanField(default=False)
access_token = models.CharField('access_token', max_length=100, blank=True)
refresh_token = models.CharField('refresh_token', max_length=100, blank=True)

arrive_action = models.CharField('access_token', max_length=1000, blank=True)
custom_action = models.CharField('custom_action', max_length=1000, blank=True)
timer_action = models.CharField('timer_action', max_length=1000, blank=True)
repeat_action = models.CharField('repeat_action', max_length=1000, blank=True)

class Following(models.Model):
id = models.AutoField(primary_key=True)
thread = models.ForeignKey('Thread')
Expand Down
Loading

0 comments on commit ede583c

Please sign in to comment.