Skip to content

Commit

Permalink
Merge 450ee11 into bd6d97e
Browse files Browse the repository at this point in the history
  • Loading branch information
phlax committed Apr 3, 2018
2 parents bd6d97e + 450ee11 commit 4d16c91
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .Makeyfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"shell": {
"git": "git",
"build-base": "docker-compose build base",
"build-dev": "docker-compose build webapp",
"compose": "docker-compose",
"db": "docker-compose run --rm webapp /home/pootle/pootle_env/src/pootle/docker/bin/run_pootle db",
"runserver": "docker-compose run --rm webapp /home/pootle/pootle_env/src/pootle/docker/bin/run_pootle server",
"pootle": "docker-compose run --rm webapp /home/pootle/pootle_env/src/pootle/docker/bin/run_pootle pootle"
}
}
54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# docker-compose for Pootle development.
#
# Note: Requires docker-compose 1.10+.
version: "2"
services:
# Pootle base image
# This image handles user creation and permissions, so that code can be
# shared from your local folder into the docker container.
base:
build:
context: ./docker/base
image: local/pootle:base

# Webapp app
webapp:
build:
context: ./docker/dev
image: local/pootle:dev
networks:
- pootle-bridge
env_file:
- docker/dev/webapp.env
environment:
- LOCAL_USER_ID=1000
depends_on:
- mariadb
- redis
command: ["/home/pootle/pootle_env/src/pootle/docker/bin/run_pootle", "server"]
ports:
- "8000:8000"
volumes:
- .:/home/pootle/pootle_env/src/pootle

mariadb:
image: mariadb
restart: always
networks:
- pootle-bridge
environment:
MYSQL_ROOT_PASSWORD: CHANGEME
MYSQL_DATABASE: pootledb
MYSQL_USER: pootle
MYSQL_PASSWORD: CHANGEME

redis:
image: redis
restart: always
networks:
- pootle-bridge


networks:
pootle-bridge:
driver: bridge
62 changes: 62 additions & 0 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# translate/pootle:dev-base
#
# VERSION 0.0.1

FROM debian:stretch

MAINTAINER Ryan Northey <ryan@synca.io>

ENV DEBIAN_FRONTEND=noninteractive \
INSTALL_DIR=~/pootle_env \
POOTLE_PKG='-e git://github.com/translate/pootle#egg=pootle'

ENV POOTLE_LOG_DIR="$INSTALL_DIR/var/logs" \
POOTLE_DB_DIR="$INSTALL_DIR/var/db"

RUN apt-get update \
&& apt-get install -y \
build-essential \
coreutils \
curl \
git \
libjpeg-dev \
libfreetype6-dev \
liblcms2-dev \
libmariadbclient-dev-compat \
libtiff5-dev \
libwebp-dev \
libxml2-dev \
libxslt-dev \
locales \
python-pip \
python-dev \
sudo \
zlib1g-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
&& update-locale LANG=en_US.UTF-8 \
&& pip install virtualenv \
&& groupadd -r pootle \
&& useradd \
-m \
-d /home/pootle \
-k /etc/skel \
-s /bin/bash \
-g pootle \
pootle

RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.10/gosu-$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
&& curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.10/gosu-$(dpkg --print-architecture | awk -F- '{ print $NF }').asc" \
&& gpg --verify /usr/local/bin/gosu.asc \
&& rm /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu

COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]


EXPOSE 8000
12 changes: 12 additions & 0 deletions docker/base/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Add local user
# Either use the LOCAL_USER_ID if passed in at runtime or
# fallback

USER_ID=${LOCAL_USER_ID:-10001}

echo "Starting with UID : $USER_ID"
usermod -o -u $USER_ID pootle
export HOME=/home/pootle
exec /usr/local/bin/gosu pootle "$@"
52 changes: 52 additions & 0 deletions docker/base/not
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
&& /etc/init.d/mysql start \
&& mysql -e "\
CREATE DATABASE pootledb \
CHARACTER SET utf8 \
DEFAULT COLLATE utf8_general_ci; \
GRANT ALL PRIVILEGES ON pootledb.* \
TO pootle@localhost \
IDENTIFIED BY 'CHANGEME'; \
FLUSH PRIVILEGES;" \
&& mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql \
&& /etc/init.d/redis-server start \
&& sudo -u pootle \
bash -c "\
mkdir -p $INSTALL_DIR \
&& cd $INSTALL_DIR \
&& virtualenv . \
&& . bin/activate \
&& mkdir -p ~/.pootle \
&& mkdir -p $POOTLE_LOG_DIR \
&& mkdir -p $POOTLE_DB_DIR \
&& pip install \
MySQL-python \
$POOTLE_PKG \
&& pootle init \
--db=mysql \
&& echo 'DEBUG = True' \
>> /home/pootle/pootle_env/pootle.conf" \
&& /etc/init.d/redis-server stop \
&& /etc/init.d/mysql stop



CMD (if [ ! -z "$USERID" ]; \
then \
usermod -u "$USERID" pootle; \
fi) \
&& sudo -u pootle \
/bin/bash -c "bash --rcfile <(echo \"\
cd $INSTALL_DIR \
&& . bin/activate \
&& cd src/pootle \
&& pip install -e . \
&& (if [ ! -e "$INSTALL_DIR/src/pootle/pootle/static/js/node_modules" ]; \
then \
cd $INSTALL_DIR/src/pootle/pootle/static/js/ \
&& npm install \
&& cd $INSTALL_DIR; \
fi) \
&& (pootle rqworker &) \
&& (pootle webpack --dev &) \")" \
&& /etc/init.d/redis-server stop \
&& /etc/init.d/mysql stop
40 changes: 40 additions & 0 deletions docker/bin/run_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

if [ "$1" == "drop" ]; then
cd /home/pootle/pootle_env \
&& . bin/activate \
&& cd src/pootle \
&& pip install -e . \
&& echo 'Dropping pootle db' \
&& echo 'drop database pootledb' | pootle dbshell;
fi


if [ "$1" == "create" ]; then
cd /home/pootle/pootle_env \
&& . bin/activate \
&& cd src/pootle \
&& pip install -e . \
&& echo 'Creating pootle db' \
&& echo 'CREATE DATABASE pootledb CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;' | mysql -h mariadb -u root -p;
fi


if [ "$1" == "show" ]; then
cd /home/pootle/pootle_env \
&& . bin/activate \
&& cd src/pootle \
&& pip install -e . \
&& echo 'Listing dbs' \
&& echo 'show databases;' | pootle dbshell;
fi


if [ "$1" == "load" ]; then
cd /home/pootle/pootle_env \
&& . bin/activate \
&& cd src/pootle \
&& pip install -e . \
&& echo "Loading db $2" \
&& mysql -h mariadb -u root -p pootledb < "/home/pootle/pootle_env/src/pootle/$2"
fi
26 changes: 26 additions & 0 deletions docker/bin/run_pootle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Runs commands in container

echo 'Running something'

if [ "$1" == "shell" ]; then
echo 'Running shell'
/home/pootle/pootle_env/src/pootle/docker/bin/run_shell
fi

if [ "$1" == "db" ]; then
echo 'Running db command'
/home/pootle/pootle_env/src/pootle/docker/bin/run_db "${@:2}"
fi

if [ "$1" == "pootle" ]; then
echo 'Running pootle command'
/home/pootle/pootle_env/src/pootle/docker/bin/run_shell "${@:2}"
fi


if [ "$1" == "server" ]; then
echo 'Running server'
/home/pootle/pootle_env/src/pootle/docker/bin/run_shell "runserver 0.0.0.0:8000"
fi
21 changes: 21 additions & 0 deletions docker/bin/run_shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Prepares then runs the webapp.

cd /home/pootle/pootle_env \
&& /bin/bash -c "bash --rcfile <(echo \"\
cd $INSTALL_DIR \
&& . bin/activate \
&& ls \
&& cd src/pootle \
&& ls \
&& pip install -e . \
&& . ~/.nvm/nvm.sh \
&& nvm use node \
&& (if [ ! -e "$INSTALL_DIR/src/pootle/pootle/static/js/node_modules" ]; \
then \
cd $INSTALL_DIR/src/pootle/pootle/static/js/ \
&& npm install \
&& cd $INSTALL_DIR; \
fi) \
&& pootle $@ \")"
41 changes: 41 additions & 0 deletions docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# translate/pootle:dev
#
# VERSION 0.0.1

FROM local/pootle:base

MAINTAINER Ryan Northey <ryan@synca.io>

RUN apt-get update \
&& apt-get install -y \
mariadb-client \
&& apt-get clean \
&& sudo -u pootle \
bash -c "\
mkdir -p $INSTALL_DIR \
&& cd $INSTALL_DIR \
&& virtualenv . \
&& . bin/activate \
&& mkdir -p ~/.pootle \
&& mkdir -p $POOTLE_LOG_DIR \
&& mkdir -p $POOTLE_DB_DIR \
&& curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& . ~/.nvm/nvm.sh \
&& nvm install node \
&& pip install \
MySQL-python \
$POOTLE_PKG \
&& pootle init \
--db=mysql \
&& echo 'CACHES[\"default\"][\"LOCATION\"] = \"redis://redis:6379/1\"' \
>> /home/pootle/pootle_env/pootle.conf \
&& echo 'CACHES[\"redis\"][\"LOCATION\"] = \"redis://redis:6379/2\"' \
>> /home/pootle/pootle_env/pootle.conf \
&& echo 'CACHES[\"lru\"][\"LOCATION\"] = \"redis://redis:6379/3\"' \
>> /home/pootle/pootle_env/pootle.conf \
&& echo 'DATABASES[\"default\"][\"HOST\"] = \"mariadb\"' \
>> /home/pootle/pootle_env/pootle.conf \
&& echo 'DATABASES[\"default\"][\"PASSWORD\"] = \"CHANGEME\"' \
>> /home/pootle/pootle_env/pootle.conf \
&& echo 'DEBUG = True' \
>> /home/pootle/pootle_env/pootle.conf"
4 changes: 4 additions & 0 deletions docker/dev/webapp.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECRET_KEY=insert_random_key
DJANGO_DEV=True
DJANGO_DEBUG=True
SITE_URL=http://localhost:8000
2 changes: 2 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Markdown==2.6.9
translate-toolkit==2.2.5
# If you want to use Translate Toolkit 'master'
#-e git+https://github.com/translate/translate.git#egg=translate-toolkit-2.2.5

makeyfile

0 comments on commit 4d16c91

Please sign in to comment.