From b1e7513ad1de8008fb550beef9013af909fa7c64 Mon Sep 17 00:00:00 2001 From: Tom Broughton Date: Sat, 20 Jul 2019 11:54:49 +0100 Subject: [PATCH] removed taskman and introduced secrets via env vars --- .gitignore | 5 ++++ README.md | 22 ++++----------- composer.json | 13 ++++----- docker-compose.yml | 31 +++++++++++++++++--- docker/php/Dockerfile | 8 ++++-- docker/php/entrypoint.sh | 33 ++++++++++++++++++++++ taskman.yml.dist | 61 ---------------------------------------- template.env | 8 ++++++ 8 files changed, 90 insertions(+), 91 deletions(-) create mode 100755 docker/php/entrypoint.sh delete mode 100644 taskman.yml.dist create mode 100644 template.env diff --git a/.gitignore b/.gitignore index 82cca4e..211245d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,8 @@ docker-compose.*.yml /.mysql_history /.bash_history + +.env +\#* +.\#* +mysql/ diff --git a/README.md b/README.md index 04cc232..faa3082 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,13 @@ -# Install Backdrop +## Install Backdrop +* `cp template.env .env` and edit * `docker-compose up -d` -* `docker-compose exec php composer install` -* `docker-compose exec php ./vendor/bin/taskman backdrop:install` ## Play with drush -* `docker-compose exec php ./vendor/bin/drush --root=build status` +* `docker exec backdrop ./vendor/bin/drush --root=build status` -Backdrop should be available at: http://127.0.0.1:8080 +## Access in browser -Login is `admin` - -Password is `admin` - -## Available Taskman commands: - -To install Backdrop -* `docker-compose exec php ./vendor/bin/taskman backdrop:install` - -To remove the files and database (_usually before installing_) -* `docker-compose exec php ./vendor/bin/taskman backdrop:reset` +* +* admin user is admin, password set in .env diff --git a/composer.json b/composer.json index d3b10c9..a16c136 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,9 @@ -{ + { "name": "backdrop-docker/backdrop", "description": "Run Backdrop using Docker containers.", - "minimum-stability": "dev", - "prefer-stable": true, - "require-dev": { - "backdrop/backdrop": "^1", - "backdrop/drush": "^1", - "phptaskman/drupal": "^0.1", - "drush/drush": "^8.2" + "require": { + "backdrop/backdrop": "1.13.2-rc2", + "backdrop/drush": "1.0.0", + "drush/drush": "8.3.0" } } diff --git a/docker-compose.yml b/docker-compose.yml index 4145cb5..0eca5ca 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,8 @@ -version: '2' +version: '3' services: web: image: nginx + container_name: nginxbackdrop ports: - "8080:80" volumes: @@ -15,11 +16,19 @@ services: build: context: docker/php args: - TIMEZONE: Europe/Brussels + TIMEZONE: Europe/London + container_name: backdrop volumes: - .:/var/www restart: always working_dir: "/var/www" + environment: + BACKDROP_DB_HOST: "${BACKDROP_DB_HOST}" + BACKDROP_DB_PORT: "${BACKDROP_DB_PORT}" + BACKDROP_DB_NAME: "${BACKDROP_DB_NAME}" + BACKDROP_DB_USER: "${BACKDROP_DB_USER}" + BACKDROP_DB_PASSWORD: "${BACKDROP_DB_USER_PASSWORD}" + BACKDROP_ADMIN_PASS: "${BACKDROP_ADMIN_PASS}" depends_on: - db - composer @@ -29,6 +38,20 @@ services: - .:/var/www working_dir: "/var/www" db: - image: percona/percona-server:5.7 + image: mariadb:latest + container_name: ${BACKDROP_DB_HOST} + ports: + - ${BACKDROP_DB_PORT}:3306 + volumes: + - ./mysql:/var/lib/mysql + - ./docker/mysql/custom-mysql.conf:/etc/mysql/conf.d/custom.cnf environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "yes" + MYSQL_DATABASE: "${BACKDROP_DB_NAME}" + MYSQL_ROOT_PASSWORD: "${BACKDROP_DB_ROOT_PASSWORD}" + MYSQL_USER: "${BACKDROP_DB_USER}" + MYSQL_PASSWORD: "${BACKDROP_DB_USER_PASSWORD}" + +networks: + default: + external: + name: web diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 6e0c2f6..94c3b5a 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,7 +1,7 @@ FROM php:7.3-fpm ARG TIMEZONE -RUN apt-get update && apt-get install -y mysql-client unzip curl sqlite3 git +RUN apt-get update && apt-get install -y mariadb-client unzip curl sqlite3 git # install the PHP extensions we need and remove dependencies once its built. RUN set -ex; \ @@ -43,7 +43,7 @@ RUN set -ex; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ rm -rf /var/lib/apt/lists/* -ADD . / +#ADD . / # Set timezone RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone @@ -55,3 +55,7 @@ RUN usermod -u 1000 www-data USER www-data WORKDIR /var/www + +#ADD --chown=root:www-data entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/var/www/docker/php/entrypoint.sh"] diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh new file mode 100755 index 0000000..666f329 --- /dev/null +++ b/docker/php/entrypoint.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# this entrpoint to docker container for backdrop will check for +# backdrop webserver files and if they don't exist then it will +# install via composer and copy the files to the relevant places +# +# the environment variables are created on container creation and for +# development purposes are stored in .env file - see template.env + +install_backdrop(){ + ./vendor/bin/drush cc drush + cp -r ./vendor/backdrop/backdrop ./build + cp -r ./vendor/backdrop/drush ./.drush/commands + + ./vendor/bin/drush --root=build si \ + --account-mail=tom@polydigital.co.uk \ + --db-url=mysql://$BACKDROP_DB_USER:$BACKDROP_DB_PASSWORD@$BACKDROP_DB_HOST:$BACKDROP_DB_PORT/$BACKDROP_DB_NAME + + ./vendor/bin/drush --root=build user-password admin --password=$BACKDROP_ADMIN_PASSWORD +} + +# let's check to see if composer has already installed the files +if [ ! -f ./vendor/backdrop/backdrop/settings.php ]; then + composer install +fi + +# if our the webserver files don't exist then we need to deploy them +# from the container +if [ ! -f /var/www/html/build/settings.php ]; then + install_backdrop +fi + +php-fpm # -F -R diff --git a/taskman.yml.dist b/taskman.yml.dist deleted file mode 100644 index 00c387f..0000000 --- a/taskman.yml.dist +++ /dev/null @@ -1,61 +0,0 @@ -backdrop: - root: build - base_url: "http://127.0.0.1:8080" - - site: - name: "Site name" - mail: "info@example.org" - profile: "standard" - update: "false" - locale: "en" - sites_subdir: "default" - - # Administrator account information. - account: - name: "admin" - password: "admin" - mail: "admin@example.org" - - # Database settings. - database: - scheme: "mysql" - host: "db" - port: "3306" - name: "backdrop" - user: "root" - password: "" - - site-install: - options: - account-name: ${backdrop.account.name} - account-pass: ${backdrop.account.password} - account-mail: ${backdrop.account.mail} - - drush: - options: - uri: "${backdrop.base_url}" - -commands: - backdrop:install: - - { task: "copy", from: "vendor/backdrop/backdrop/", to: "${backdrop.root}", force: true } - - { task: "copy", from: "vendor/backdrop/drush/", to: ".drush/commands", force: true } - - ./vendor/bin/drush cc drush - - { task: "chmod", file: "${backdrop.root}/files", permissions: 0777, recursive: true } - - { task: "append", file: "${backdrop.root}/settings.local.php", text: "