Skip to content
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

[Suggestion] Set up Docker containers #48

Open
bakersemail opened this issue Aug 28, 2017 · 1 comment
Open

[Suggestion] Set up Docker containers #48

bakersemail opened this issue Aug 28, 2017 · 1 comment

Comments

@bakersemail
Copy link

bakersemail commented Aug 28, 2017

Hi team,

I found it a little difficult to get a local environment set up for this without digging through the code for database configuration. I think a docker container would make it easier to set up a local development service as well as the eventual deployment to production.

Here's some files which might help get this started:


rundocker.sh (the script to start the local service from)

#!/bin/bash

echo "Stopping any existing containers"
sudo docker rm -f $(sudo docker ps -aq --filter "name=sisters-of-the-road") 2>/dev/null

echo "Building image"
sudo docker build -t sisters-of-the-road/barter:latest .
if [ $? -ne 0 ]; then
  echo "Could not build image"
  exit 1
fi

echo "Starting container"
sudo docker run -it --name sisters-of-the-road-barter -p 8000:8000 sisters-of-the-road/barter /rundockerserver.sh

Dockerfile

FROM ubuntu:latest

# Prepare all deps
RUN apt-get update
RUN apt-get install -y git-core
RUN apt-get install -y python-setuptools python3-dev build-essential
RUN apt-get install -y python3-pip python3-venv
RUN apt-get install -y npm
RUN apt-get install -y postgresql-9.5
RUN apt-get install -y sudo

### Database set up
USER postgres

RUN ls /etc/postgresql/
RUN    /etc/init.d/postgresql start &&\
    psql --command "CREATE USER sisters WITH SUPERUSER PASSWORD 'sisters';" &&\
    createdb -O sisters barter

RUN echo "host all  all    0.0.0.0/0  md5" >> /etc/postgresql/9.5/main/pg_hba.conf
CMD ["/usr/lib/postgresql/9.5/bin/postgres", "-D", "/var/lib/postgresql/9.5/main", "-c", "config_file=/etc/postgresql/9.5/main/postgresql.conf"]

### Application set up
USER root
RUN service postgresql start

RUN pip3 install --upgrade pip
RUN python3 -m venv venv
RUN npm install npm@latest -g
RUN ln -s /usr/bin/nodejs /usr/bin/node

RUN git clone https://github.com/codeforgoodconf/sisters-of-the-road-admin.git
RUN (cd sisters-of-the-road-admin/; npm install; ./node_modules/.bin/webpack --config webpack.config.js)
RUN (. venv/bin/activate; cd sisters-of-the-road-admin/; pip install --upgrade pip; pip install -r requirements.txt)

COPY rundockerserver.sh /
RUN chmod +x /rundockerserver.sh

EXPOSE 8000

rundockerserver.sh

#!/bin/bash

sudo service postgresql start

python3 -m venv /venv
source /venv/bin/activate

cd sisters-of-the-road-admin/
pip install -r requirements.txt
python manage.py migrate

echo "from django.contrib.auth.models import User; User.objects.filter(email='[email protected]').delete(); User.objects.create_superuser('admin', '[email protected]', 'password')" | python manage.py shell
python manage.py runserver 0.0.0.0:8000

By running the rundocker.sh, it should start a local service up which you can immediately test against and use the default admin account: admin / password.

Let me know what your thoughts are. I'd be willing to help extend this concept if your team find it useful.

Cheers,
Steven

@meli-lewis
Copy link
Collaborator

Steven,

This would be useful, and thanks both for the suggestion and your notes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants