Compare commits

..

4 Commits

Author SHA1 Message Date
b89beaed58 Add reminder not to edit the settings file 2018-01-04 06:37:38 +01:00
323fb01588 Add option to override settings 2018-01-04 06:36:49 +01:00
ad512e2af5 Update license and readme 2018-01-04 06:36:42 +01:00
524b9f1c0e Initial commit 2018-01-04 06:34:06 +01:00
15 changed files with 556 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
env.shinc

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) <year> <copyright holders> Copyright (c) 2017 Čech - iSlužby s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,3 +1,8 @@
# Docker-development # Docker-development
Development tools in docker Development tools in docker
use `./run.sh init` in each of the project directories that you want to use
to override the default settings use a file `env.shinc`

5
adminer/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
ARG IMAGE_NAME
ARG IMAGE_VERSION
FROM ${IMAGE_NAME}:${IMAGE_VERSION}
RUN sed -i 's/max_execution_time.*/max_execution_time = 600/g' /etc/php5/cli/php.ini && sed -i 's/max_input_time.*/max_input_time = 600/g' /etc/php5/fpm/php.ini

53
adminer/run.sh Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
IMAGE_NAME="clue/adminer"
IMAGE_VERSION="latest"
PROJECT_NAME=adminer
source ${SCRIPT_PATH}/../common.shinc
#
# Project specific variables
#
DOMAIN_NAME="adminer.loc"
init() {
__init
# Create networks
NETWORKS=(${DB_NETWORK} ${PROXY_NETWORK})
__createNetworks
__build || return $?
echo " docker create \
--name ${PROJECT_NAME} \
-e VIRTUAL_HOST=${DOMAIN_NAME} \
--restart=unless-stopped \
--net ${DB_NETWORK} \
--net ${PROXY_NETWORK} \
${PROJECT_NAME}:latest"
docker create \
--name ${PROJECT_NAME} \
-e VIRTUAL_HOST=${DOMAIN_NAME} \
--restart=unless-stopped \
${PROJECT_NAME}:latest
[[ $? -ne 0 ]] && return 1
docker network connect ${DB_NETWORK} ${PROJECT_NAME}
[[ $? -ne 0 ]] && return 1
docker network connect ${PROXY_NETWORK} ${PROJECT_NAME}
[[ $? -ne 0 ]] && return 1
__ask_to_start
}
"$@"

106
common.shinc Normal file
View File

@ -0,0 +1,106 @@
#!/usr/bin/env bash
REQUIRED_VARIABLES=(PROJECT_NAME SCRIPT_PATH IMAGE_NAME IMAGE_VERSION)
for _var in ${REQUIRED_VARIABLES[@]}; do
if [ -z ${!_var+x} ]; then
echo "Missing definition of variable: ${_var}"
exit 2
fi
done
source ${SCRIPT_PATH}/../settings.shinc
source ${SCRIPT_PATH}/../env.shinc
source ${SCRIPT_PATH}/../functions.shinc
#
# Commonly used functions
#
stop() {
__msg "Stopping container... " 0 no
STATUS=$(docker stop ${PROJECT_NAME} > /dev/null 2>&1)
if [[ $? -ne 0 ]]; then
__err "${STATUS}"
return 1
else
__success "[ok]"
fi
return 0
}
start() {
__msg "Starting container... " 0 no
STATUS=$(docker start ${PROJECT_NAME} 2>&1)
if [[ $? -ne 0 ]]; then
__err "${STATUS}"
return 1
else
__success "[ok]"
fi
return 0
}
remove() {
stop
__msg "Removing container... " 0 no
STATUS=$(docker rm ${PROJECT_NAME} 2>&1)
if [[ $? -ne 0 ]]; then
__err "${STATUS}"
return 1
else
__success "[ok]"
fi
return 0
}
logs() {
docker logs "$@" ${PROJECT_NAME}
return $?
}
exec() {
# Test if bash is available
docker exec -it ${PROJECT_NAME} /bin/bash -c "echo 'test'" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
docker exec -it ${PROJECT_NAME} /bin/bash
return $?
fi
# Test if bash is available
docker exec -it ${PROJECT_NAME} /bin/sh -c "echo 'test'" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
docker exec -it ${PROJECT_NAME} /bin/sh
return $?
fi
__err "Could not find either sh or bash in the container"
return 1
}
help() {
echo "┌──────────────────────────────────────────────────────────────┐"
echo "│ Available commands │"
echo "└──────────────────────────────────────────────────────────────┘"
echo -e -n "$LOG"
echo " > init - Initializes the environment"
echo " > start - Start containers"
echo " > stop - Stops containers"
echo " > remove - Removes traces of the container"
echo " > logs - Shows logs"
echo " > exec - Enters the containers tty"
echo " > help - Display this help"
echo -e -n "${NORMAL}"
echo "└──────────────────────────────────────────────────────────────┘"
return 0
}

108
functions.shinc Normal file
View File

@ -0,0 +1,108 @@
#!/usr/bin/env bash
# Indent output by 2 x {n} spaces
__indent() {
if [[ $1 != "" ]] && [[ $1 -ne 0 ]]; then
printf ' %0.s' {1..$1}
fi
}
__newLine() {
if [[ $1 = "" ]]; then
echo
fi
}
__msg() {
echo -ne "${C_WHITE}"
__indent $2
echo -ne "$1${C_NONE}"
__newLine $3
}
__warn() {
echo -ne "${C_WARN}"
__indent $2
echo -ne "$1${C_NONE}"
__newLine $3
}
__success() {
echo -ne "${C_GREEN}"
__indent $2
echo -ne "$1${C_NONE}"
__newLine $3
}
__err() {
echo -ne "${C_ERR}"
__indent $2
echo -ne "$1${C_NONE}"
__newLine $3
}
#
# Internal functions
#
__createNetworks() {
for _var in ${NETWORKS[@]}; do
if [[ ${_var} = "" ]]; then
continue
fi
docker network inspect ${_var} > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
# If it does not, create it
__warn "The network ${_var} does not exist. Creating... " 1 no
STATUS=$(docker network create ${_var} 2>&1)
if [[ $? -ne 0 ]]; then
__err "${STATUS}"
return 117
else
__success "[ok]"
fi
fi
done
return 0
}
init() {
__err "The init function was not overridden"
return 137
}
__init() {
__msg "Initializing ${PROJECT_NAME}"
# Make sure we have the latest build
docker pull ${IMAGE_NAME}:${IMAGE_VERSION}
return $?
}
__build() {
docker build \
--build-arg IMAGE_NAME=${IMAGE_NAME} \
--build-arg IMAGE_VERSION=${IMAGE_VERSION} \
-t ${PROJECT_NAME}:latest \
${SCRIPT_PATH}
return $?
}
__ask_to_start() {
__success "Start the container? [(y)/n]... "
read START
if [[ ${START} != "" ]] && [[ ${START} != "y" ]] && [[ ${START} != "Y" ]]; then
return 0
fi
start
return $?
}

48
mailhog/run.sh Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
IMAGE_NAME="mailhog/mailhog"
IMAGE_VERSION="latest"
PROJECT_NAME=mailhog
source ${SCRIPT_PATH}/../common.shinc
#
# Project specific variables
#
SMTP_PORT=1025
WEB_PORT=8025
DOMAIN_NAME="mailhog.loc"
init() {
__init
NETWORKS=(${SMTP_NETWORK} ${PROXY_NETWORK})
__createNetworks
docker create \
--name ${PROJECT_NAME} \
-e VIRTUAL_HOST=${DOMAIN_NAME} \
-e VIRTUAL_PORT=${WEB_PORT} \
-p ${SMTP_PORT}:1025 \
${IMAGE_NAME}:${IMAGE_VERSION}
[[ $? -ne 0 ]] && return 1
docker network connect ${SMTP_NETWORK} ${PROJECT_NAME}
[[ $? -ne 0 ]] && return 1
docker network connect ${PROXY_NETWORK} ${PROJECT_NAME}
[[ $? -ne 0 ]] && return 1
__ask_to_start
}
"$@"
exit $?

69
maria-db/run.sh Executable file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bash
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
IMAGE_NAME="mariadb"
IMAGE_VERSION="10.1"
PROJECT_NAME=maria-db
source ${SCRIPT_PATH}/../common.shinc
#
# Project specific variables
#
DB_VOLUME=mariadb_shared
BACKUP_DIR=${SCRIPT_PATH}/backup
init() {
__init
# Create networks
NETWORKS=(${DB_NETWORK})
__createNetworks
# Create the database container
docker create \
--name ${PROJECT_NAME} \
--restart=unless-stopped \
-v ${DB_VOLUME}:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=${DB_PASSWORD} \
--net ${DB_NETWORK} \
${IMAGE_NAME}:${IMAGE_VERSION}
[[ $? -ne 0 ]] && return 1
__ask_to_start
}
# Used for exporting the whole database filesystem
export() {
stop
local user=$(id -u)
mkdir -p ${BACKUP_DIR} && \
docker run --rm --volumes-from ${PROJECT_NAME} -v ${BACKUP_DIR}:/backup busybox tar cvf /backup/backup.tar /var/lib/mysql && chown -R ${user}:${user} ./backup
if [[ $? -ne 0 ]]; then
__err "Could not create the backup"
exit 2
fi
start
return $?
}
# Used for importing the whole database filesystem
import() {
stop
docker run --rm --volumes-from ${PROJECT_NAME} -v ${BACKUP_DIR}:/backup busybox sh -c "rm -rf /var/lib/mysql/* && tar xvf /backup/backup.tar --directory /"
start
return $?
}
"$@"
exit $?

5
nginx/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
ARG IMAGE_NAME
ARG IMAGE_VERSION
FROM ${IMAGE_NAME}:${IMAGE_VERSION}
COPY conf.d/ /etc/nginx/conf.d/

View File

@ -0,0 +1,4 @@
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;

View File

@ -0,0 +1 @@
client_max_body_size 2000m;

58
nginx/run.sh Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
IMAGE_NAME="jwilder/nginx-proxy"
IMAGE_VERSION="latest"
PROJECT_NAME=nginx-proxy
source ${SCRIPT_PATH}/../common.shinc
#
# Project specific variables
#
init() {
__init
NETWORKS=(${PROXY_NETWORK})
__createNetworks
__build || return $?
# Create the nginx-proxy container
docker create \
--name ${PROJECT_NAME} \
-v /var/run/docker.sock:/tmp/docker.sock:ro \
--restart=unless-stopped \
-p 80:80 \
-p 443:443 \
--net ${PROXY_NETWORK} \
${PROJECT_NAME}:latest
[[ $? -ne 0 ]] && return 1
__ask_to_start
}
fix() {
local upperDir=$(docker inspect ${PROJECT_NAME} --format "{{.GraphDriver.Data.UpperDir}}")
[[ $? -ne 0 ]] && __err "Could not determine the nginx proxy filesystem path" && return 2
stop
sudo rm $(docker inspect ${PROJECT_NAME} --format "{{.GraphDriver.Data.UpperDir}}")/etc/nginx/conf.d/default.conf
if [[ $? -eq 0 ]]; then
__success "Succesfully removed the nginx configuration, restart the container"
return 0
else
__err "Could not remove the configuration file"
return 1
fi
}
"$@"
exit $?

46
pgsql-db/run.sh Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
SCRIPT_PATH=$( cd "$(dirname "$0")" ; pwd -P )
IMAGE_NAME="mdillon/postgis"
IMAGE_VERSION="9.5"
PROJECT_NAME=pgsql-db
source ${SCRIPT_PATH}/../common.shinc
#
# Project specific variables
#
DB_VOLUME=pgsql_persistent
PORT=5432
init() {
__init
NETWORKS=(${DB_NETWORK})
__createNetworks
__msg "Removing old postgres bin volume..."
docker volume rm -f ${PGSQL_DB_BIN} &&
docker create \
--name ${PROJECT_NAME} \
--restart=unless-stopped \
-v ${DB_VOLUME}:/var/lib/postgresql/data \
-v ${PGSQL_DB_BIN}:/usr/lib/postgresql/${IMAGE_VERSION}/bin \
-e POSTGRES_USER=${DB_USER} \
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
--net ${DB_NETWORK} \
-p ${PORT}:5432 \
${IMAGE_NAME}:${IMAGE_VERSION}
[[ $? -ne 0 ]] && return 1
__ask_to_start
}
"$@"
exit $?

44
settings.shinc Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
# DO NOT EDIT THIS FILE DIRECTLY, USE env.shinc FILE TO OVERRIDE THE FOLLOWING VARIABLES
#
# Networks
#
# Reverse proxy
PROXY_NETWORK="web-server"
# Databases
DB_NETWORK="database"
# Mail
SMTP_NETWORK="smtp"
#
# Database settings
#
DB_USER="root"
DB_PASSWORD="megaheslo"
PGSQL_DB_BIN="postgres_bin_dir"
#
# Colors
#
C_NONE="\033[0m" # Reset formating
C_ERR="\033[41;1m" # Red
C_WARN="\033[1;33m" # Yellow
C_HIGHLIGHT="\033[1;95m" # Purple
C_LOG="\033[1;3;36m" # Cyan
C_GREEN="\033[32m"
C_WHITE="\033[1;37m"