Last active
January 25, 2018 08:36
-
-
Save melihovv/7ff0a54d488393629a959fd35fa9bba2 to your computer and use it in GitHub Desktop.
Docker compose goodness (from serversforhackers.com)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
docker build -f app/Dockerfile -t shippingdocker.com/app:latest ./app | |
docker build -f node/Dockerfile -t shippingdocker.com/node:latest ./node |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Set environment variables for dev or CI | |
export APP_PORT=${APP_PORT:-80} | |
export DB_PORT=${DB_PORT:-3306} | |
export DB_ROOT_PASS=${DB_ROOT_PASS:-secret} | |
export DB_NAME=${DB_NAME:-helpspot} | |
export DB_USER=${DB_USER:-helpspot} | |
export DB_PASS=${DB_PASS:-secret} | |
# Decide which docker-compose file to use | |
COMPOSE_FILE="dev" | |
# Disable pseudo-TTY allocation for CI (Jenkins) | |
TTY="" | |
if [ ! -z "$BUILD_NUMBER" ]; then | |
COMPOSE_FILE="ci" | |
TTY="-T" | |
fi | |
COMPOSE="docker-compose -f docker-compose.$COMPOSE_FILE.yml" | |
if [ $# -gt 0 ];then | |
if [ "$1" == "art" ]; then | |
shift 1 | |
$COMPOSE run --rm $TTY \ | |
-w /var/www/html \ | |
app \ | |
php artisan "$@" | |
# If "composer" is used, pass-thru to "composer" | |
# inside a new container | |
elif [ "$1" == "composer" ]; then | |
shift 1 | |
$COMPOSE run --rm $TTY \ | |
-w /var/www/html \ | |
app \ | |
composer "$@" | |
# If "test" is used, run unit tests, | |
# pass-thru any extra arguments to php-unit | |
elif [ "$1" == "test" ]; then | |
shift 1 | |
$COMPOSE run --rm $TTY \ | |
-w /var/www/html \ | |
app \ | |
./vendor/bin/phpunit "$@" | |
elif [ "$1" == "t" ]; then | |
shift 1 | |
$COMPOSE exec \ | |
app \ | |
sh -c "cd /var/www/html && ./vendor/bin/phpunit $@" | |
# If "npm" is used, run npm | |
# from our node container | |
elif [ "$1" == "npm" ]; then | |
shift 1 | |
$COMPOSE run --rm $TTY \ | |
-w /var/www/html \ | |
node \ | |
npm "$@" | |
# If "gulp" is used, run gulp | |
# from our node container | |
elif [ "$1" == "gulp" ]; then | |
shift 1 | |
$COMPOSE run --rm $TTY \ | |
-w /var/www/html \ | |
node \ | |
./node_modules/.bin/gulp "$@" | |
else | |
$COMPOSE "$@" | |
fi | |
else | |
$COMPOSE ps | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
app: | |
build: | |
context: ./docker/app | |
dockerfile: Dockerfile | |
image: shippingdocker.com/app | |
volumes: | |
- .:/var/www/html | |
networks: | |
- sdnet | |
node: | |
build: | |
context: ./docker/node | |
dockerfile: Dockerfile | |
image: shippingdocker.com/node | |
volumes: | |
- .:/var/www/html | |
networks: | |
- sdnet | |
mysql: | |
image: mysql:5.7 | |
volumes: | |
- mysqldata:/var/lib/mysql | |
networks: | |
- sdnet | |
redis: | |
image: redis:alpine | |
volumes: | |
- redisdata:/data | |
networks: | |
- sdnet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
app: | |
extends: | |
file: docker-compose.base.yml | |
service: app | |
node: | |
extends: | |
file: docker-compose.base.yml | |
service: node | |
redis: | |
extends: | |
file: docker-compose.base.yml | |
service: redis | |
networks: | |
sdnet: | |
driver: "bridge" | |
volumes: | |
mysqldata: | |
driver: "local" | |
redisdata: | |
driver: "local" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
app: | |
extends: | |
file: docker-compose.base.yml | |
service: app | |
ports: | |
- "${APP_PORT}:80" | |
node: | |
extends: | |
file: docker-compose.base.yml | |
service: node | |
mysql: | |
extends: | |
file: docker-compose.base.yml | |
service: mysql | |
ports: | |
- "${DB_PORT}:3306" | |
environment: | |
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASS}" | |
MYSQL_DATABASE: "${DB_NAME}" | |
MYSQL_USER: "${DB_USER}" | |
MYSQL_PASSWORD: "${DB_PASS}" | |
redis: | |
extends: | |
file: docker-compose.base.yml | |
service: redis | |
networks: | |
sdnet: | |
driver: "bridge" | |
volumes: | |
mysqldata: | |
driver: "local" | |
redisdata: | |
driver: "local" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:16.04 | |
MAINTAINER Chris Fidao | |
RUN apt-get update \ | |
&& apt-get install -y locales \ | |
&& locale-gen en_US.UTF-8 | |
ENV LANG en_US.UTF-8 | |
ENV LANGUAGE en_US:en | |
ENV LC_ALL en_US.UTF-8 | |
RUN apt-get update \ | |
&& apt-get install -y nginx curl zip unzip git software-properties-common supervisor sqlite3 \ | |
&& add-apt-repository -y ppa:ondrej/php \ | |
&& apt-get update \ | |
&& apt-get install -y php7.0-fpm php7.0-cli php7.0-mcrypt php7.0-gd php7.0-mysql \ | |
php7.0-pgsql php7.0-imap php-memcached php7.0-mbstring php7.0-xml php7.0-curl \ | |
php7.0-sqlite3 php7.0-xdebug \ | |
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \ | |
&& mkdir /run/php \ | |
&& apt-get remove -y --purge software-properties-common \ | |
&& apt-get -y autoremove \ | |
&& apt-get clean \ | |
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ | |
&& echo "daemon off;" >> /etc/nginx/nginx.conf | |
RUN ln -sf /dev/stdout /var/log/nginx/access.log \ | |
&& ln -sf /dev/stderr /var/log/nginx/error.log | |
COPY default /etc/nginx/sites-available/default | |
COPY php-fpm.conf /etc/php/7.0/fpm/php-fpm.conf | |
EXPOSE 80 | |
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf | |
CMD ["/usr/bin/supervisord"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: up down log tinker artisan test | |
# Set dir of Makefile to a variable to use later | |
MAKEPATH := $(abspath $(lastword $(MAKEFILE_LIST))) | |
PWD := $(dir $(MAKEPATH)) | |
up: | |
docker-compose up -d | |
down: | |
docker-compose down | |
log: | |
tail -f $(PWD)storage/logs/laravel.log | awk '\ | |
{matched=0}\ | |
/INFO:/ {matched=1; print "\033[0;37m" $$0 "\033[0m"}\ | |
/WARNING:/ {matched=1; print "\033[0;34m" $$0 "\033[0m"}\ | |
/ERROR:/ {matched=1; print "\033[0;31m" $$0 "\033[0m"}\ | |
/Next/ {matched=1; print "\033[0;31m" $$0 "\033[0m"}\ | |
/ALERT:/ {matched=1; print "\033[0;35m" $$0 "\033[0m"}\ | |
/Stack trace:/ {matched=1; print "\033[0;35m" $$0 "\033[0m"}\ | |
matched==0 {print "\033[0;33m" $$0 "\033[0m"}\ | |
' | |
tinker: | |
docker run -it --rm \ | |
-e "HOME=/home" \ | |
-v $(PWD).tinker:/home/.config \ | |
-v $(PWD):/opt \ | |
-w /opt \ | |
--network=zondaroad_appnet \ | |
shippingdocker/php:latest \ | |
php artisan tinker | |
ART="" | |
artisan: | |
docker run -it --rm \ | |
-e "HOME=/home" \ | |
-v $(PWD).tinker:/home/.config \ | |
-v $(PWD):/opt \ | |
-w /opt \ | |
--network=zondaroad_appnet \ | |
shippingdocker/php:latest \ | |
php artisan $(ART) | |
test: | |
docker run -it --rm \ | |
-v $(PWD):/opt \ | |
-w /opt \ | |
--network=zondaroad_appnet \ | |
shippingdocker/php:latest \ | |
./vendor/bin/phpunit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
root /var/www/html/public; | |
index index.html index.htm index.php; | |
server_name _; | |
charset utf-8; | |
location = /favicon.ico { log_not_found off; access_log off; } | |
location = /robots.txt { log_not_found off; access_log off; } | |
location / { | |
try_files $uri $uri/ /index.php$is_args$args; | |
} | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
} | |
error_page 404 /index.php; | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;; | |
; FPM Configuration ; | |
;;;;;;;;;;;;;;;;;;;;; | |
; All relative paths in this configuration file are relative to PHP's install | |
; prefix (/usr). This prefix can be dynamically changed by using the | |
; '-p' argument from the command line. | |
;;;;;;;;;;;;;;;;;; | |
; Global Options ; | |
;;;;;;;;;;;;;;;;;; | |
[global] | |
; Pid file | |
; Note: the default prefix is /var | |
; Default Value: none | |
pid = /run/php/php7.0-fpm.pid | |
; Error log file | |
; If it's set to "syslog", log is sent to syslogd instead of being written | |
; in a local file. | |
; Note: the default prefix is /var | |
; Default Value: log/php-fpm.log | |
error_log = /proc/self/fd/2 | |
; syslog_facility is used to specify what type of program is logging the | |
; message. This lets syslogd specify that messages from different facilities | |
; will be handled differently. | |
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON) | |
; Default Value: daemon | |
;syslog.facility = daemon | |
; syslog_ident is prepended to every message. If you have multiple FPM | |
; instances running on the same server, you can change the default value | |
; which must suit common needs. | |
; Default Value: php-fpm | |
;syslog.ident = php-fpm | |
; Log level | |
; Possible Values: alert, error, warning, notice, debug | |
; Default Value: notice | |
;log_level = notice | |
; If this number of child processes exit with SIGSEGV or SIGBUS within the time | |
; interval set by emergency_restart_interval then FPM will restart. A value | |
; of '0' means 'Off'. | |
; Default Value: 0 | |
;emergency_restart_threshold = 0 | |
; Interval of time used by emergency_restart_interval to determine when | |
; a graceful restart will be initiated. This can be useful to work around | |
; accidental corruptions in an accelerator's shared memory. | |
; Available Units: s(econds), m(inutes), h(ours), or d(ays) | |
; Default Unit: seconds | |
; Default Value: 0 | |
;emergency_restart_interval = 0 | |
; Time limit for child processes to wait for a reaction on signals from master. | |
; Available units: s(econds), m(inutes), h(ours), or d(ays) | |
; Default Unit: seconds | |
; Default Value: 0 | |
;process_control_timeout = 0 | |
; The maximum number of processes FPM will fork. This has been design to control | |
; the global number of processes when using dynamic PM within a lot of pools. | |
; Use it with caution. | |
; Note: A value of 0 indicates no limit | |
; Default Value: 0 | |
; process.max = 128 | |
; Specify the nice(2) priority to apply to the master process (only if set) | |
; The value can vary from -19 (highest priority) to 20 (lower priority) | |
; Note: - It will only work if the FPM master process is launched as root | |
; - The pool process will inherit the master process priority | |
; unless it specified otherwise | |
; Default Value: no set | |
; process.priority = -19 | |
; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. | |
; Default Value: yes | |
daemonize = no | |
; Set open file descriptor rlimit for the master process. | |
; Default Value: system defined value | |
;rlimit_files = 1024 | |
; Set max core size rlimit for the master process. | |
; Possible Values: 'unlimited' or an integer greater or equal to 0 | |
; Default Value: system defined value | |
;rlimit_core = 0 | |
; Specify the event mechanism FPM will use. The following is available: | |
; - select (any POSIX os) | |
; - poll (any POSIX os) | |
; - epoll (linux >= 2.5.44) | |
; - kqueue (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0) | |
; - /dev/poll (Solaris >= 7) | |
; - port (Solaris >= 10) | |
; Default Value: not set (auto detection) | |
;events.mechanism = epoll | |
; When FPM is build with systemd integration, specify the interval, | |
; in second, between health report notification to systemd. | |
; Set to 0 to disable. | |
; Available Units: s(econds), m(inutes), h(ours) | |
; Default Unit: seconds | |
; Default value: 10 | |
;systemd_interval = 10 | |
;;;;;;;;;;;;;;;;;;;; | |
; Pool Definitions ; | |
;;;;;;;;;;;;;;;;;;;; | |
; Multiple pools of child processes may be started with different listening | |
; ports and different management options. The name of the pool will be | |
; used in logs and stats. There is no limitation on the number of pools which | |
; FPM can handle. Your system will tell you anyway :) | |
; Include one or more files. If glob(3) exists, it is used to include a bunch of | |
; files from a glob(3) pattern. This directive can be used everywhere in the | |
; file. | |
; Relative path can also be used. They will be prefixed by: | |
; - the global prefix if it's been set (-p argument) | |
; - /usr otherwise | |
include=/etc/php/7.0/fpm/pool.d/*.conf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[supervisord] | |
nodaemon=true | |
[program:nginx] | |
command=nginx | |
stdout_logfile=/dev/stdout | |
stdout_logfile_maxbytes=0 | |
stderr_logfile=/dev/stderr | |
stderr_logfile_maxbytes=0 | |
[program:php-fpm] | |
command=php-fpm7.0 | |
stdout_logfile=/dev/stdout | |
stdout_logfile_maxbytes=0 | |
stderr_logfile=/dev/stderr | |
stderr_logfile_maxbytes=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment