From 227b97be3a290807726ff57977ad5998b9de09a2 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Tue, 3 Apr 2018 13:45:13 +0100 Subject: [PATCH 1/5] Add docker builds --- docker/base/Dockerfile | 62 +++++++++++++++++++++++++++++++++++++++ docker/base/entrypoint.sh | 12 ++++++++ docker/base/not | 52 ++++++++++++++++++++++++++++++++ docker/dev/Dockerfile | 41 ++++++++++++++++++++++++++ docker/dev/webapp.env | 4 +++ 5 files changed, 171 insertions(+) create mode 100644 docker/base/Dockerfile create mode 100755 docker/base/entrypoint.sh create mode 100644 docker/base/not create mode 100644 docker/dev/Dockerfile create mode 100644 docker/dev/webapp.env diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile new file mode 100644 index 00000000000..e0b96b1a436 --- /dev/null +++ b/docker/base/Dockerfile @@ -0,0 +1,62 @@ +# translate/pootle:dev-base +# +# VERSION 0.0.1 + +FROM debian:stretch + +MAINTAINER Ryan Northey + +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 diff --git a/docker/base/entrypoint.sh b/docker/base/entrypoint.sh new file mode 100755 index 00000000000..eb7d29cc3e3 --- /dev/null +++ b/docker/base/entrypoint.sh @@ -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 "$@" diff --git a/docker/base/not b/docker/base/not new file mode 100644 index 00000000000..fdb17d56a7e --- /dev/null +++ b/docker/base/not @@ -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 diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile new file mode 100644 index 00000000000..acc0a1b11d4 --- /dev/null +++ b/docker/dev/Dockerfile @@ -0,0 +1,41 @@ +# translate/pootle:dev +# +# VERSION 0.0.1 + +FROM local/pootle:base + +MAINTAINER Ryan Northey + +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" diff --git a/docker/dev/webapp.env b/docker/dev/webapp.env new file mode 100644 index 00000000000..fd4a40d7aed --- /dev/null +++ b/docker/dev/webapp.env @@ -0,0 +1,4 @@ +SECRET_KEY=insert_random_key +DJANGO_DEV=True +DJANGO_DEBUG=True +SITE_URL=http://localhost:8000 From 804a221635fbf701685bcdfdaad1bc4a0a996cc0 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Tue, 3 Apr 2018 13:45:25 +0100 Subject: [PATCH 2/5] Add docker compose file --- docker-compose.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000000..7666b4bfbe0 --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file From c679dedeeb77f8a3d3adb6a89ef3f08a6413b9b2 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Tue, 3 Apr 2018 14:29:32 +0100 Subject: [PATCH 3/5] Add makeyfile --- .Makeyfile.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .Makeyfile.json diff --git a/.Makeyfile.json b/.Makeyfile.json new file mode 100644 index 00000000000..8889326983c --- /dev/null +++ b/.Makeyfile.json @@ -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" + } +} From f6c2d4727c6ec54b9e89e564b74032fe4c646351 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Tue, 3 Apr 2018 14:30:14 +0100 Subject: [PATCH 4/5] Add makeyfile to requirements --- requirements/base.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements/base.txt b/requirements/base.txt index 463e0f276ec..4c4e8a36315 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -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 From 450ee11fed01db6515d9f50ddf5982da229bfbd2 Mon Sep 17 00:00:00 2001 From: Ryan Northey Date: Tue, 3 Apr 2018 14:37:59 +0100 Subject: [PATCH 5/5] Add docker bin files --- docker/bin/run_db | 40 ++++++++++++++++++++++++++++++++++++++++ docker/bin/run_pootle | 26 ++++++++++++++++++++++++++ docker/bin/run_shell | 21 +++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 docker/bin/run_db create mode 100755 docker/bin/run_pootle create mode 100755 docker/bin/run_shell diff --git a/docker/bin/run_db b/docker/bin/run_db new file mode 100755 index 00000000000..4cbfc11b172 --- /dev/null +++ b/docker/bin/run_db @@ -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 diff --git a/docker/bin/run_pootle b/docker/bin/run_pootle new file mode 100755 index 00000000000..e90232614a8 --- /dev/null +++ b/docker/bin/run_pootle @@ -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 diff --git a/docker/bin/run_shell b/docker/bin/run_shell new file mode 100755 index 00000000000..d88cdc06a4b --- /dev/null +++ b/docker/bin/run_shell @@ -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 $@ \")"