├── bashrc.sh ├── apache.conf ├── drushrc.php ├── Dockerfile ├── .gitlab-ci.yml └── README.md /bashrc.sh: -------------------------------------------------------------------------------- 1 | export PATH="$PATH:/var/www/drupal/vendor/bin" 2 | -------------------------------------------------------------------------------- /apache.conf: -------------------------------------------------------------------------------- 1 | 2 | DocumentRoot ${DOCROOT} 3 | 4 | -------------------------------------------------------------------------------- /drushrc.php: -------------------------------------------------------------------------------- 1 | /usr/local/etc/php/conf.d/drupal-01.ini 10 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin -- --filename=composer 11 | 12 | # Create directories for Drupal 13 | RUN mkdir -p /tmp/drupal && chown www-data:www-data /tmp/drupal 14 | RUN chown www-data:www-data /var/www 15 | WORKDIR /var/www/drupal 16 | 17 | # Config 18 | ENV DOCROOT=/var/www/drupal/web 19 | ADD apache.conf /etc/apache2/sites-enabled/000-default.conf 20 | ADD bashrc.sh /var/www/.bashrc 21 | ADD drushrc.php /etc/drush/drushrc.php 22 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - pre-build 3 | - build 4 | 5 | list-tags: 6 | stage: pre-build 7 | only: 8 | - master 9 | image: everpeace/curl-jq 10 | variables: 11 | BASE_TAGS_API_URL: https://hub.docker.com/v2/repositories/drupaldocker/php/tags/?page_size=9999 12 | BASE_TAGS_FILTER: apache 13 | script: 14 | - curl --insecure --silent $BASE_TAGS_API_URL | jq '."results"[]["name"]' --raw-output | grep $BASE_TAGS_FILTER > tags_list.txt 15 | artifacts: 16 | untracked: true 17 | 18 | .paralel-build: ¶lel-build 19 | stage: build 20 | image: docker:latest 21 | services: 22 | - docker:dind 23 | only: 24 | - master 25 | variables: 26 | JOBS_NUMBER: 10 27 | script: 28 | # Select tags to process 29 | - export TAGS=$(awk "NR % $JOBS_NUMBER == ${CI_JOB_NAME#'build '}" tags_list.txt) 30 | # Login to image registry 31 | - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY 32 | - | 33 | for TAG in ${TAGS//\\n/ } 34 | do 35 | docker build --pull -t "$CI_REGISTRY_IMAGE:$TAG" --build-arg "BASE_IMAGE_TAG=$TAG" . 36 | docker push "$CI_REGISTRY_IMAGE:$TAG" 37 | done 38 | 39 | # Fake "build matrix" feature 40 | build 0: 41 | <<: *paralel-build 42 | build 1: 43 | <<: *paralel-build 44 | build 2: 45 | <<: *paralel-build 46 | build 3: 47 | <<: *paralel-build 48 | build 4: 49 | <<: *paralel-build 50 | build 5: 51 | <<: *paralel-build 52 | build 6: 53 | <<: *paralel-build 54 | build 7: 55 | <<: *paralel-build 56 | build 8: 57 | <<: *paralel-build 58 | build 9: 59 | <<: *paralel-build -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Drupal - Composer - Docker 2 | 3 | Docker image with out-of-box support for Composer workflow. Recommanded Composer template: https://github.com/drupal-composer/drupal-project 4 | 5 | - [Composer](https://getcomposer.org) is pre-installed 6 | - CLI utilities installed by Composer (Drush, Drupal Console, ...) are in PATH, so you can call them from anywhere in the container 7 | - Drush [will know](https://github.com/iBobik/drupal-composer-docker/blob/master/drushrc.php#L4) where is Drupal root, so you do not have to be in the project directory 8 | - DocumentRoot is in /var/www/drupal/web, so Drupal is in subdirectory of project root (/var/www/drupal - where composer.json is located). Can be overriden by environment variable `DOCROOT`. 9 | 10 | ## Tags 11 | Tags of this image follow `apache` tags of [drupaldocker/php image](https://hub.docker.com/r/drupaldocker/php/). 12 | 13 | It uses GitLab CI and it's registry, so **you have to prepend image by: `registry.gitlab.com`** You can use also [Docker Hub](https://hub.docker.com/r/bobik/drupal-composer), but there is only `7.1-apache` tag, because Docker Hub does not support scripting in build process. 14 | 15 | Available tags can be seen on [GitLab project page](https://gitlab.com/janpoboril/drupal-composer-docker/container_registry). 16 | 17 | ## How to use it 18 | 19 | Pull and run image by CLI: 20 | ``` 21 | docker run -d -p 8080:80 --name my-drupal-app -v $(pwd)/drupal:/var/www/drupal registry.gitlab.com/janpoboril/drupal-composer-docker:7.1-apache 22 | ``` 23 | or better use in `docker-compose.yml` like: 24 | ``` 25 | services: 26 | web: 27 | image: registry.gitlab.com/janpoboril/drupal-composer-docker:7.1-apache 28 | ports: 29 | - "8080:80" 30 | volumes: 31 | - ./web/drupal:/var/www/drupal 32 | ``` 33 | or as a base for your own image in `Dockerfile` beginning with: 34 | ``` 35 | FROM registry.gitlab.com/janpoboril/drupal-composer-docker:7.1-apache 36 | ``` 37 | 38 | ### Initializing Drupal project 39 | 40 | This image does not contain Drupal code, so you have many options how to use it. Recommended way how to initialize new project by Composer: 41 | 42 | Open shell into container: 43 | ``` 44 | docker exec -it -u www-data myproject_web_1 bash 45 | ``` 46 | And clone template (you should be in `~/drupal` - default working directory): 47 | ``` 48 | composer create-project drupal-composer/drupal-project:8.x-dev . --stability dev --no-interaction 49 | ``` 50 | 51 | Then Drupal is ready to run in browser or install modules by Composer: 52 | ``` 53 | composer require drupal/devel:~1.0 54 | ``` 55 | See [template's README](https://github.com/drupal-composer/drupal-project) for more examples how to use it. 56 | 57 | **Warning about Drush and Console:** Current versions does not understand projects where Drupal is in a subdirectory (composer.json and index.php are not siblings), so if you try to download a module by them (e.g. `drush dl devel` including `drush en devel`) they will not use Composer but will use "old-school http tar.gz" method (module will not be recorded into composer.json). 58 | --------------------------------------------------------------------------------