diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/Dockerfile.diaspora b/Dockerfile.diaspora new file mode 100644 index 0000000..3322c94 --- /dev/null +++ b/Dockerfile.diaspora @@ -0,0 +1,65 @@ +FROM debian:stretch as base + +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get install -y -qq \ + build-essential \ + libssl-dev \ + libcurl4-openssl-dev \ + libxml2-dev \ + libxslt-dev \ + imagemagick \ + ghostscript \ + curl \ + libmagickwand-dev \ + git \ + libpq-dev \ + cmake \ + nodejs \ + # Packages for RVM + gawk \ + libyaml-dev \ + libsqlite3-dev \ + sqlite3 \ + autoconf \ + libgmp-dev \ + libgdbm-dev \ + libncurses5-dev \ + automake \ + bison \ + libffi-dev \ + libgmp-dev \ + libreadline-dev \ + && rm -rf /var/lib/apt/lists/* + +ARG EXT_UID +ARG EXT_GID +RUN addgroup --system --gid ${EXT_GID} diaspora +RUN adduser --system --uid ${EXT_UID} --gid ${EXT_GID} diaspora + +USER diaspora +RUN mkdir /home/diaspora/diaspora +WORKDIR /home/diaspora/diaspora + +# Install RVM + Ruby +ENV LANG=C.UTF8 + +RUN curl -sSL https://rvm.io/mpapis.asc | gpg --import - \ + && curl -L https://s.diaspora.software/1t | bash \ + && rm -rf ~/.gnupg +SHELL ["/bin/bash", "--login", "-c"] + +RUN rvm install 2.4 + +# Install bundler +RUN echo diaspora > .ruby-gemset \ + && echo 2.4 > .ruby-version \ + && touch Gemfile \ + && cd ../diaspora \ + && gem install bundler \ + && rm .ruby-* Gemfile + +# Finish setup +COPY ./start.sh ../start.sh + +CMD ["../start.sh"] diff --git a/README.md b/README.md index b354b3e..31d77e3 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# diaspora-docker \ No newline at end of file +# diaspora-docker + +This image is intended exclusively for development. + +## Build And Run + +1. Copy `example.env` to `.env` +1. Set `EXT_UID` and `EXT_GID` in `.env` according to your user's user and group ID +1. Execute `docker-compose build diaspora` (takes some time) +1. Copy or link your diaspora code to `./diaspora.docker` +1. Execute `docker-compose up` + +- To restart, do `docker-compose restart diaspora` or (faster) `docker-compose exec diaspora /bin/bash --login -c "bin/eye restart diaspora"` +- To start without migrations and bundle install, set any value for `DIASPORA_DOCKER_DEV_INSTALL_GEMS` and `DIASPORA_DOCKER_DEV_DB_MIGRATE` in `.env`. It is only executed if these variables are empty + +## TODO + +- Control migrations and bundle installing more intuitively +- Create external script for controlling/handling the setup diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2cde805 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: "3" + +volumes: + postgres_db: + + +services: + + diaspora: + build: + context: . + dockerfile: Dockerfile.diaspora + args: + EXT_UID: "${EXT_UID}" + EXT_GID: "${EXT_GID}" + image: diaspora:dev-latest + environment: + DIASPORA_DOCKER_DEV_INSTALL_GEMS: "${DIASPORA_DOCKER_DEV_INSTALL_GEMS}" + DIASPORA_DOCKER_DEV_DB_MIGRATE: "${DIASPORA_DOCKER_DEV_DB_MIGRATE}" + ports: + - 8080:3000 + volumes: + - ./diaspora.docker:/home/diaspora/diaspora:rw + depends_on: + - postgres +# - redis + + postgres: + image: postgres:9.6 + ports: + - 55432:5432 + volumes: + - postgres_db:/var/lib/postgresql + +# redis: +# image: redis:latest diff --git a/example.env b/example.env new file mode 100644 index 0000000..54d81b7 --- /dev/null +++ b/example.env @@ -0,0 +1,4 @@ +EXT_UID=1000 +EXT_GID=1000 +DIASPORA_DOCKER_DEV_INSTALL_GEMS= +DIASPORA_DOCKER_DEV_DB_MIGRATE= diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..b46356e --- /dev/null +++ b/start.sh @@ -0,0 +1,19 @@ +#!/bin/bash --login + +action_install_gems() { + script/configure_bundler + bin/bundle config --local path vendor/bundle + bin/bundle install --full-index +} + +action_db_migrate() { + bin/rake db:create db:migrate +} + +[ -z $DIASPORA_DOCKER_DEV_INSTALL_GEMS ] && action_install_gems + +[ -z $DIASPORA_DOCKER_DEV_DB_MIGRATE ] && action_db_migrate + +[ ! -f public/source.tar.gz ] && touch public/source.tar.gz + +exec ./script/server