Skip to content

Commit

Permalink
Add setup, clean and status to docker-compose wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
CSammy committed Apr 14, 2018
1 parent 9cbd52f commit 9e9faec
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 86 deletions.
17 changes: 7 additions & 10 deletions Dockerfile.diaspora
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ruby:2.4.4-slim-stretch

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update \
&& apt-get install -y -qq \
build-essential \
libssl-dev \
Expand All @@ -21,8 +21,8 @@ RUN apt-get update \

ARG EXT_UID
ARG EXT_GID
RUN addgroup --system --gid ${EXT_GID} diaspora
RUN adduser --system --uid ${EXT_UID} --gid ${EXT_GID} diaspora
RUN addgroup --system --gid ${EXT_GID} diaspora \
&& adduser --system --uid ${EXT_UID} --gid ${EXT_GID} diaspora

USER diaspora
ENV DIASPORA_HOME /home/diaspora/diaspora
Expand All @@ -31,11 +31,8 @@ WORKDIR $DIASPORA_HOME

ENV GEM_HOME $DIASPORA_HOME/vendor/bundle
ENV BUNDLE_PATH="$GEM_HOME" \
BUNDLE_BIN="$GEM_HOME/bin" \
BUNDLE_APP_CONFIG="$DIASPORA_HOME/.bundle"
BUNDLE_BIN="$GEM_HOME/bin" \
BUNDLE_APP_CONFIG="$DIASPORA_HOME/.bundle"
ENV PATH $BUNDLE_BIN:$PATH

# Finish setup
COPY ./start.sh ../start.sh

CMD ["../start.sh"]
CMD ["./script/server"]
11 changes: 11 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.4"

services:
diaspora:
build:
context: .
dockerfile: Dockerfile.diaspora
args:
EXT_UID: "${EXT_UID}"
EXT_GID: "${EXT_GID}"
image: diaspora:dev-latest
52 changes: 30 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
version: "3"
version: "3.4"

volumes:
postgres_db:
x-diaspora-base: &diaspora-base
image: diaspora:dev-latest
volumes:
- "${DIASPORA_PATH}:/home/diaspora/diaspora:rw"

x-diaspora-db: &diaspora-db
depends_on:
- "${DIASPORA_DOCKER_DB}"

volumes:
postgresql_data:
mysql_data:

services:
diaspora-bundle:
<< : *diaspora-base
command: /bin/sh -c "script/configure_bundler && bin/bundle install --full-index"

diaspora-migrations:
<< : *diaspora-base
<< : *diaspora-db
command: /bin/sh -c "bin/rake db:create db:migrate"

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}"
<< : *diaspora-base
<< : *diaspora-db
ports:
- 8080:3000
volumes:
- ./diaspora.docker:/home/diaspora/diaspora:rw
depends_on:
- postgres
# - redis

postgres:
postgresql:
image: postgres:9.6
ports:
- 55432:5432
volumes:
- postgres_db:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql

# redis:
# image: redis:latest
mysql:
image: mysql:5.7
ports:
- 53306:3306
volumes:
- mysql_data:/var/lib/mysql
18 changes: 0 additions & 18 deletions start.sh

This file was deleted.

105 changes: 69 additions & 36 deletions wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,116 @@
print_usage() {
echo "$SCRIPT_NAME COMMAND"
echo
echo "COMMAND"
echo " build"
# echo " bundle"
# echo " migrate"
# echo " setup"
echo " start"
echo " stop"
# echo " clean"
echo "Commands:"
echo " build Rebuild image"
echo " bundle Install gems using bundle"
echo " migrate Execute pending migrations (incl. database setup)"
echo " setup Build, bundle and migrate"
echo " start Start diaspora\* incl. database"
echo " stop Stop all diaspora\*-related containers"
echo " clean Delete all diaspora\*-related containers and volumes"
echo " status Show currently running containers and related images"
# echo " rspec"
}

dia_build() {
if [ -z "$UID" -o -z "$GID" ]; then
# $UID is not builtin, determine using a program
if ! type "id" 2>&1 >/dev/null; then
echo "Fatal: Cannot determine UID or GID."
exit 1
fi
EXT_UID=$(id -u)
EXT_GID=$(id -g)
else
EXT_UID=$UID
EXT_GID=$GID
fi
docker-compose rm -v diaspora
EXT_UID=$EXT_UID EXT_GID=$EXT_GID docker-compose -f docker-compose.build.yml build diaspora
}

dia_bundle() {
docker-compose up $option diaspora-bundle
docker-compose rm --stop -v --force diaspora-bundle
}

dia_migrate() {
docker-compose up $option diaspora-migrations
}

dia_setup() {
dia_build
# This is just a temporary (dev-only) solution
[ ! -f $DIASPORA_PATH/public/source.tar.gz ] && touch $DIASPORA_PATH/public/source.tar.gz
# do bundle install
# start db container
# do db migrate
# start dia container
}

dia_build() {
docker-compose build diaspora
dia_bundle
dia_migrate
}

dia_start() {
docker-compose up
docker-compose up $option diaspora
}

dia_stop() {
docker-compose stop
}

dia_clean() {
docker-compose down
}

dia_status() {
docker-compose ps
docker-compose images
}


SCRIPT_NAME=$(basename $0)
SCRIPT_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
DIASPORA_PATH=

if [ -z "$UID" -o -z "$GID" ]; then
# $UID is not builtin, determine using a program
if ! type "id" 2>&1 >/dev/null; then
echo "Fatal: Cannot determine UID or GID."
exit 1
fi
EXT_UID=$(id -u)
EXT_GID=$(id -g)
else
EXT_UID=$UID
EXT_GID=$GID
fi
export DIASPORA_PATH=./diaspora.docker
export DIASPORA_DOCKER_DB=postgresql

export EXT_UID
export EXT_GID
export DIASPORA_PATH

if [ $# -lt 1 ]; then
print_usage
exit 1
fi

command=$1
dia_command=$1
shift
if [ $# -eq 1 -a "$1" -eq "-d" ]; then
export option="-d"
fi

case $command in
case $dia_command in
--help|-h)
print_usage
exit 0
;;
build)
dia_build
;;
bundle)
dia_bundle
;;
migrate)
dia_migrate
;;
setup)
dia_setup
;;
start)
dia_start
;;
stop)
dia_stop
;;
clean)
dia_clean
;;
status)
dia_status
;;
*)
print_usage
exit 1
Expand Down

0 comments on commit 9e9faec

Please sign in to comment.