Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A smart way to use the CLI to replace the WORDPRESS_CONFIG_EXTRA variable #544

Closed
kamihicouki opened this issue Oct 24, 2020 · 1 comment · Fixed by #557
Closed

A smart way to use the CLI to replace the WORDPRESS_CONFIG_EXTRA variable #544

kamihicouki opened this issue Oct 24, 2020 · 1 comment · Fixed by #557
Labels
Request Request for image modification or feature

Comments

@kamihicouki
Copy link

kamihicouki commented Oct 24, 2020

Hi everyone, nice to meet you all.
I've been looking at the documents and discussions in the following order and have come up with a better alternative, so I'll post it.

  1. https://hub.docker.com/_/wordpress/
  2. Inject configuration using environment variable #142
  3. echo >&2
    echo >&2 'WARNING: environment variable "WORDPRESS_CONFIG_EXTRA" is set, but "wp-config.php" already exists'
    echo >&2 ' The contents of this variable will _not_ be inserted into the existing "wp-config.php" file.'
    echo >&2 ' (see https://github.com/docker-library/wordpress/issues/333 for more details)'
    echo >&2

I feel that the Command line interface for WordPress | WP-CLI project is the best way to accurately, reliably, and quickly rewrite the values of variables in wp-config.php.

And it is fortunately available as a wordpress - Docker Hub official image.

MySQL is an essential part of WordPress.
Likewise, considering that WP-CLI is essential for a flexible WordPress/wp-config.php configuration, how about the following?
I think the idempotence of the configuration will be preserved.

---
version: "2.4"
services:
  wp-init:
    image: wordpress:cli
    restart: on-failure
    environment:
      - WP_CONFIG_DB_CHARSET=utf8mb4
      - WP_CONFIG_DB_HOST=db
      - WP_CONFIG_TABLE_PREFIX=wp_
    # ... other WP_CONFIG_* variables or env_file load files/variables.
    volumes:
      - wordpress:/var/www/html
      - ./wp-config.sh:/wp-config.sh:ro
    working_dir: /var/www/html
    user: root
    command: sh /wp-config.sh
#!/bin/sh

printenv | sed 's/^WP_CONFIG_//;t;d' | sed 's/=/ /' | while read LINE; do wp --allow-root config set $LINE; done

This is just part of my idea of how to do it.
What are your thoughts on this?
Have a great day.

@kamihicouki kamihicouki changed the title WORDPRESS_CONFIG_EXTRA 変数を代替するCLIを用いたスマートな方法 A smart way to use the CLI to replace the WORDPRESS_CONFIG_EXTRA variable Oct 24, 2020
@wglambert wglambert added the Request Request for image modification or feature label Oct 26, 2020
@tianon
Copy link
Member

tianon commented Oct 26, 2020

I think this is interesting, but I'm not sure what you're proposing as a change for this repository?

Frankly, we'd love to completely deprecate our environment variables in favor of proper upstream-supported wp-config.php usage (but that's difficult to accomplish, given it's been in wide use for so long).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Request Request for image modification or feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants