Skip to content

Commit

Permalink
Added docker for development support + added docker-squash to reduce …
Browse files Browse the repository at this point in the history
…docker image size (#1167)
  • Loading branch information
Mokto authored and asbiin committed May 2, 2018
1 parent a394425 commit 39c9c31
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 30 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,18 @@ jobs:
- checkout:
<<: *post_checkout
- *prepare-environment
- run:
name: Install docker_squash
command: |
sudo apt-get update
sudo apt-get install -y python-pip
pip install docker-squash "docker < 3"
- run:
name: Make docker image
command: |
docker-compose --version
make docker_build
make docker_squash
- run:
name: Publish docker image
command: |
Expand Down
Binary file modified .circleci/config.yml.sig
Binary file not shown.
9 changes: 1 addition & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.circleci/
.git/
.gitattributes
.github/
Expand All @@ -8,7 +9,6 @@ bootstrap/cache/*
database/*.sqlite
.env
CODE_OF_CONDUCT.md
CONTRIBUTING.md
docker-compose.yml
Dockerfile
.dockerignore
Expand All @@ -35,12 +35,5 @@ storage/framework/sessions/*
storage/framework/views/*
storage/logs/*
.styleci.yml
storage/app/public/*
storage/debugbar/*
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/views/*
storage/logs/*
tests/
.travis.yml*
vendor/
71 changes: 71 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
APP_ENV=local
APP_DEBUG=true

APP_KEY=ChangeMeBy32KeyLengthOrGenerated
HASH_SALT=ChangeMeBy20+KeyLength
HASH_LENGTH=18

APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=monica
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_PREFIX=

# Mail credentials used to send emails from the application.
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=ValidEmailAddress
MAIL_FROM_NAME="Some Name"
APP_EMAIL_NEW_USERS_NOTIFICATION=EmailThatWillSendNotificationsForNewUser

# Default timezone for new users. Users can change this setting inside the
# application at their leisure.
# Must be exactly one of the timezones used in this list:
# https://github.com/monicahq/monica/blob/master/resources/views/settings/index.blade.php#L70
APP_DEFAULT_TIMEZONE=US/Eastern

# Default locale used in the application.
APP_DEFAULT_LOCALE=en

# Ability to disable signups on your instance.
# Can be true or false. Default to false.
APP_DISABLE_SIGNUP=false

# Frequency of creation of new log files. Logs are written when an error occurs.
# Refer to config/logging.php for the possible values.
LOG_CHANNEL=syslog

SENTRY_SUPPORT=false
SENTRY_DSN=

CHECK_VERSION=false

REQUIRES_SUBSCRIPTION=false

# Change this only if you know what you are doing
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

# Default filesystem to store uploaded files.
# Possible values: public|s3
DEFAULT_FILESYSTEM=public

# AWS keys for S3 when using this storage method
AWS_KEY=
AWS_SECRET=
AWS_REGION=us-east-1
AWS_BUCKET=
AWS_SERVER=

# Enable Two Factor Authentication
2FA_ENABLED=false
70 changes: 48 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ FROM alpine:3.6

EXPOSE 80:80

RUN apk update && apk upgrade; \
apk add --virtual .build-deps \
curl openssl; \
apk add apache2 make netcat-openbsd \
RUN apk update && apk upgrade
RUN apk add --virtual .build-deps \
curl openssl
RUN apk add apache2 make netcat-openbsd \
#- base
php7 php7-apache2 php7-intl php7-openssl php7-ctype \
php7-zip php7-zlib \
Expand Down Expand Up @@ -33,9 +33,9 @@ RUN apk update && apk upgrade; \
#- vinkla/hashids
php7-bcmath \
#- sentry/sentry
php7-curl; \
# Create apache2 dir needed for httpd
mkdir -p /run/apache2
php7-curl
# Create apache2 dir needed for httpd
RUN mkdir -p /run/apache2

# Create a user to own all the code and assets and give them a working
# directory
Expand All @@ -45,24 +45,50 @@ WORKDIR /var/www/monica
# Copy the local (outside Docker) source into the working directory,
# copy system files into their proper homes, and set file ownership
# correctly
ADD . .
RUN cp .env.example .env; \
chown -R monica:monica . && \
chgrp -R apache bootstrap/cache storage && \
chmod -R g+w bootstrap/cache storage && \
# Apache2 conf
cp scripts/docker/000-default.conf /etc/apache2/conf.d/; \
# Composer installation
scripts/docker/install-composer.sh; \
# Set crontab for schedules
echo '* * * * * /usr/bin/php /var/www/monica/artisan schedule:run' | crontab -u monica -; \
# Cleanup
apk del .build-deps && rm -rf /var/cache/apk/*
COPY readme.md \
CONTRIBUTING.md \
CHANGELOG \
CONTRIBUTORS \
LICENSE \
.env.example \
artisan \
composer.json \
composer.lock \
package.json \
app.json \
nginx_app.conf \
webpack.mix.js \
yarn.lock \
./
COPY app ./app
COPY bootstrap ./bootstrap
COPY config ./config
COPY database ./database
COPY public ./public
COPY resources ./resources
COPY routes ./routes
COPY scripts ./scripts

RUN mkdir -p bootstrap/cache
RUN mkdir -p storage
COPY .env.example .env
RUN chown -R monica:monica .
RUN chgrp -R apache bootstrap/cache storage
RUN chmod -R g+w bootstrap/cache storage

# Apache2 conf
COPY scripts/docker/000-default.conf /etc/apache2/conf.d/
# Composer installation
RUN scripts/docker/install-composer.sh
# Set crontab for schedules
RUN echo '* * * * * /usr/bin/php /var/www/monica/artisan schedule:run' | crontab -u monica -
# Cleanup
RUN apk del .build-deps && rm -rf /var/cache/apk/*

# Install composer dependencies and prepare permissions for Apache
USER monica
RUN composer install --no-interaction --no-suggest --no-dev && \
composer clear-cache
RUN composer install --no-interaction --no-suggest --no-dev
RUN composer clear-cache
USER root

# This is the command that the container will run by default
Expand Down
67 changes: 67 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
FROM alpine:3.6

EXPOSE 80:80

RUN apk update && apk upgrade; \
apk add --virtual .build-deps \
curl openssl; \
apk add apache2 make netcat-openbsd \
#- base
php7 php7-apache2 php7-intl php7-openssl php7-ctype \
php7-zip php7-zlib \
php7-redis \
#- Authentication Guards
php7-session php7-tokenizer \
#- laravel/cashier sabre/vobject sabre/xml
php7-dom \
#- intervention/image
php7-fileinfo \
#- laravel/cashier
php7-gd \
#- composer
php7-phar php7-json php7-iconv \
#- laravel/framework sabre/vobject
php7-mbstring \
#- league/flysystem-aws-s3-v3
php7-simplexml \
#- sabre/vobject sabre/xml
php7-xml php7-xmlreader php7-xmlwriter \
#- mysql
php7-mysqli php7-pdo_mysql \
#- pgsql
php7-pgsql php7-pdo_pgsql \
#- vinkla/hashids
php7-bcmath \
#- sentry/sentry
php7-curl; \
# Create apache2 dir needed for httpd
mkdir -p /run/apache2

# Create a user to own all the code and assets and give them a working
# directory
RUN adduser -D monica apache -h /var/www/monica
WORKDIR /var/www/monica

# Copy the local (outside Docker) source into the working directory,
# copy system files into their proper homes, and set file ownership
# correctly
ADD . .
ADD .env.dev .env
RUN chown -R monica:monica . && \
chgrp -R apache bootstrap/cache storage && \
chmod -R g+w bootstrap/cache storage && \
# Apache2 conf
cp scripts/docker/000-default.conf /etc/apache2/conf.d/; \
# Composer installation
scripts/docker/install-composer.sh; \
# Cleanup
apk del .build-deps && rm -rf /var/cache/apk/*


# Install composer dependencies and prepare permissions for Apache
USER monica
RUN composer install --no-interaction --no-suggest
USER root

# This is the command that the container will run by default
ENTRYPOINT ["make", "-f", "/var/www/monica/scripts/docker/Makefile"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ docker_build:
docker-compose build
docker images

DOCKER_SQUASH := $(shell which docker-squash)
ifeq ($(TAG),)
DOCKER_SQUASH := ~/.local/bin/docker-squash
endif

docker_squash:
docker-squash -t monicahq/monicahq:latest monicahq/monicahq:latest
docker images

docker_tag:
docker tag monicahq/monicahq monicahq/monicahq:$(GIT_TAG)

Expand Down
43 changes: 43 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3'
services:
monicahq:
build:
context: .
dockerfile: Dockerfile.dev
links:
- mysql
ports:
- 8080:80
env_file: .env.dev
environment:
- PASSWORD_CLIENT_ID=10
- PASSWORD_CLIENT_SECRET=4eYqKmvMr1nLhRNiI30fkPARM77j90MgBTaJADgN
volumes:
- /var/www/monica/storage
- ./app:/var/www/monica/app
- ./routes:/var/www/monica/routes
- ./database:/var/www/monica/database

mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=sekret_root_password
- MYSQL_DATABASE=monica
- MYSQL_USER=homestead
- MYSQL_PASSWORD=secret
volumes:
- /var/lib/mysql

phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql
environment:
PMA_HOST: mysql
PMA_USER: root
PMA_PASSWORD: sekret_root_password
restart: always
ports:
- "3000:80"
volumes:
- "/sessions"

0 comments on commit 39c9c31

Please sign in to comment.