Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generate a Database as an image

License

NotificationsYou must be signed in to change notification settings

axelerant/db-docker

Repository files navigation

Generate a Database as an image

Introduction

This tool was written for Axelerant specific processes but can be used generally by overriding certain configuration. By default, you wouldn't be able to use this plugin if you cannot access Axelerant's GitLab repository. You may use it with your own Docker image registry or even with Docker Hub.

Prerequisites

  • Reasonably updated version of composer with recent version of PHP. Tested with composer 1.10.1 and composer 2+.
  • Recent version of Docker.

Optional requirements (only for default workflow)

By default, this plugin generates the image with name prefixed with Axelerant's Docker registry. The below requirements apply if you don't override the image name using configuration incomposer.json.

  • Ability to clone from gitorious.xyz.
  • Logged in to Axelerant's GitLab Container Registry. To verify, rundocker login registry.gitorious.xyz. Optional if you use the--no-push option.

Installation

Install with composer into any Drupal project.

composer require --dev axelerant/db-docker

Usage

Options may be specified using the command line or by specifying them in theextra section in yourcomposer.json file. See the section below onConfiguration for more details.

$ composer db-docker --helpUsage:  db-docker [options]Options:  -t, --docker-tag[=DOCKER-TAG]  The Docker tag to build  -r, --git-remote[=GIT-REMOTE]  The git remote to use to determine the image name  -s, --db-source[=DB-SOURCE]    Source of the database ("lando", "drush", or "file")  -f, --db-file[=DB-FILE]        The path to the database file (required if db-source is set to file)      --no-push                  Set to not push the image after building  -h, --help                     Display this help message  -q, --quiet                    Do not output any message  -V, --version                  Display this application version      --ansi                     Force ANSI output      --no-ansi                  Disable ANSI output  -n, --no-interaction           Do not ask any interactive question      --profile                  Display timing and memory usage information      --no-plugins               Whether to disable plugins.  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.      --no-cache                 Prevent use of the cache  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debugHelp:  Generate a Docker image for the database.

Warning: The above usage is generated by runningcomposer db-docker --help and is generated by composer. Some options such as--no-plugins are not compatible. The option--no-plugins tells composer not to load any plugins, which means thatdb-docker won't be loaded at all.

Examples

To let the plugin guess defaults, build the image, and push it.

composer db-docker

To explicitly specify a SQL file to build the image.

composer db-docker --db-source=file --db-file=<filename># The file can either be plain SQL or gzipped.

Configuration

The plugin also supports configuration via composer.jsonextra section.

{"name":"drupal/site",// ..."require": {// ...    },"require-dev": {// ..."axelerant/db-docker":"^1.0"    },"extra": {"dbdocker": {"docker-image-name":"auto","docker-tag":"auto","docker-base": {"base-flavor":"bitnami","image":"bitnami/mariadb:10.4","user":"drupal8","password":"drupal8","database":"drupal8"            },"git-remote":"origin","db-source":"","no-push":false        }    }}

These options work the same way as the options available via the command line. Option values specified on the command line take precedence followed by the options in theextra section ofcomposer.json. Finally, values are guessed as described below.

Image details

By default, the image name and tag will be guessed using the method described below in theDefault Options section. You can override both of them using thedocker-image-name anddocker-tag settings in the configuration incomposer.json as shown above. Additionally, you may also specify thedocker-tag via the command line.

Base image

You can use thedocker-base configuration to specify the base image to use to build the database image. When not specified, the default image used is Bitnami's MariaDB 10.4 image with default access details which is compatible withLando's Drupal 8 recipe. You may override this to fit in your workflow as desired.

The base image details cannot be customized from the command line. They must be specified via thecomposer.json's extra section.

DDEV base image

The defaults fordocker-base depend on the value ofbase-flavor setting. By default, thebase-flavor is set tobitnami and the defaults are set as above. However, ifbase-flavor isddev, the defaults change to the following:

{"extra": {"dbdocker": {"docker-base": {"base-flavor":"ddev","image":"drud/ddev-dbserver-mariadb-10.4:v1.17.0","user":"db","password":"db","database":"db"            }        }    }}

These are the defaults required for building database images compatible for DDEV.

Default options

The plugin tries to guess most values for input to correctly select the source, build the image, and push it.

Determining the image name

The image name can be specified using thedocker-image-name incomposer.json as described above. If not specified (or set to"auto"), the image name is constructed from the git repository.

The image name is determined based on the git repository'sorigin remote (overridable using the--git-remote option). The remote URL should be a Git URL (not a HTTP URL) of typegit@gitorious.xyz:<group>/<project>.git. For this, it would determine the image nameregistry.gitorious.xyz/<group>/<project>/db. See the next section for the image tag.

It's important to note that the image name is constructed only for Axelerant Gitlab repositories. If you want to use another Docker registry (such as Docker Hub or Quay.io), please use the option incomposer.json to specify the proper name.

Determining the image tag

The image tag, unless specified with the--docker-tag option, is assumed to be the current branch name. If the current branch ismaster, the image tag is used aslatest.

Determining the database source

These database sources are supported:file,lando,ddev, anddrush. The source can be explicitly specified using the--db-source option. If not specified, the following rules are used to determine the source.

  • If the--db-file option is present, then the source is set asfile.
  • If a file called.lando.yml is present, then the source is set aslando.
    • As an exception to above, the plugin attempts to detect if it is running inside a lando container. If so, the source is set todrush.
  • If a directory called.ddev is present, then the source is set asddev.
    • As an exception to above, the plugin attempts to detect if it is running inside a DDEV container. If so, the source is set todrush.
  • If the above conditions fail, then the source is assumed to bedrush.

In case the source islando,ddev, ordrush, thedrush sql:dump command is used to obtain the SQL file. If the source islando orddev, then the drush command is executed inside the relevant container like so:lando drush ... orddev drush ....

Reporting problems

If you see a bug or an improvement, create a pull request. For support, raise a request on Axelerant Slack #internal-support channel.

About

Generate a Database as an image

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp