-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdocker-compose.adminer.yaml
More file actions
138 lines (132 loc) · 5.23 KB
/
docker-compose.adminer.yaml
File metadata and controls
138 lines (132 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ddev-generated
services:
adminer:
container_name: ddev-${DDEV_SITENAME}-adminer
image: ${ADMINER_DOCKER_IMAGE:-adminer:standalone}-${DDEV_SITENAME}-built
build:
dockerfile_inline: |
ARG ADMINER_DOCKER_IMAGE="scratch"
FROM $$ADMINER_DOCKER_IMAGE
# Switch the adminer user.
USER root
# Accept build arguments for user creation
ARG username
ARG uid
ARG gid
# Free up the uid and gid if they're currently used, but ensure the original adminer group still exists
RUN existing_user=$(getent passwd "$$uid" | cut -d: -f1); \
existing_group=$(getent group "$$gid" | cut -d: -f1); \
existing_adminer_gid=$(getent group adminer | cut -d: -f3); \
if [[ -n "$$existing_group" ]]; then echo "Deleting existing group: $$existing_group ($$gid)"; delgroup "$$existing_group"; fi; \
if [[ -n "$$existing_user" ]]; then echo "Deleting existing user: $$existing_user ($$uid)"; deluser "$$existing_user"; fi; \
addgroup -g "$$existing_adminer_gid" adminer || addgroup adminer || true
# Ensure tty group exists
RUN getent group tty || addgroup tty
# Create group and user, trying multiple methods for compatibility
RUN (addgroup -g "$$gid" "$$username" || addgroup "$$username" || true) && \
(adduser -G tty -s "/bin/sh" -D -u "$$uid" "$$username" || \
adduser -G tty -s "/bin/sh" -D "$$username" || \
adduser -G tty -s "/bin/sh" "$$username") && \
addgroup "$$username" adminer
# Ensure the plugins-enabled directory is writable by the group.
RUN chmod 775 /var/www/html/plugins-enabled
# Switch to the created user
USER "$$username"
args:
ADMINER_DOCKER_IMAGE: ${ADMINER_DOCKER_IMAGE:-adminer:standalone}
username: ${DDEV_USER}
uid: ${DDEV_UID}
gid: ${DDEV_GID}
environment:
- ADMINER_DEFAULT_DRIVER=${ADMINER_DEFAULT_DRIVER:-${DDEV_DATABASE_FAMILY:-server}}
- ADMINER_DEFAULT_SERVER=${ADMINER_DEFAULT_SERVER:-db}
- ADMINER_DEFAULT_DB=${ADMINER_DEFAULT_DB:-db}
- ADMINER_DEFAULT_USERNAME=${ADMINER_DEFAULT_USERNAME:-db}
- ADMINER_DEFAULT_PASSWORD=${ADMINER_DEFAULT_PASSWORD:-db}
- ADMINER_PLUGINS=${ADMINER_PLUGINS:-ddev-passwordless-login tables-filter}
- ADMINER_DESIGN=${ADMINER_DESIGN:-}
- VIRTUAL_HOST=$DDEV_HOSTNAME
- HTTP_EXPOSE=9100:8080
- HTTPS_EXPOSE=9101:8080
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
volumes:
- ".:/mnt/ddev_config"
- "../:/mnt/ddev_app"
- "ddev-global-cache:/mnt/ddev-global-cache"
depends_on:
- db
command: ["php", "-S", "[::]:8080", "-t", "/var/www/html", "ddev-adminer.php"]
configs:
- source: ddev-adminer.php
target: /var/www/html/ddev-adminer.php
mode: "0444"
- source: ddev-passwordless-login.php
target: /var/www/html/plugins/ddev-passwordless-login.php
mode: "0444"
- source: entrypoint.sh
target: /usr/local/bin/entrypoint.sh
mode: "0755"
configs:
ddev-adminer.php:
content: |
<?php
// Let static files be served directly
$$uri = parse_url($$_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (is_file('/var/www/html' . $$uri)) {
return false;
}
if (!count($$_GET)) {
if ($$_ENV['ADMINER_DEFAULT_DRIVER'] === 'mysql') {
$$_ENV['ADMINER_DEFAULT_DRIVER'] = 'server';
} else if ($$_ENV['ADMINER_DEFAULT_DRIVER'] === 'postgres') {
$$_ENV['ADMINER_DEFAULT_DRIVER'] = 'pgsql';
}
$$_POST['auth'] = [
'driver' => $$_ENV['ADMINER_DEFAULT_DRIVER'],
'server' => $$_ENV['ADMINER_DEFAULT_SERVER'],
'db' => $$_ENV['ADMINER_DEFAULT_DB'],
'username' => $$_ENV['ADMINER_DEFAULT_USERNAME'],
'password' => $$_ENV['ADMINER_DEFAULT_PASSWORD'],
];
}
include './index.php';
?>
ddev-passwordless-login.php:
content: |
<?php
/**
* Adminer plugin for enabling passwordless login in DDEV.
* By default, only the SQLite driver is supported.
*/
class DDEVPasswordlessLogin extends Adminer\Plugin {
function login($$login, $$password) {
if (Adminer\JUSH === 'sqlite' && empty($$password)) {
return true;
}
}
}
entrypoint.sh:
content: |
#!/bin/sh
set -e
if [ -n "$$ADMINER_DESIGN" ]; then
# Only create link on initial start, to ensure that explicit changes to
# adminer.css after the container was started once are preserved.
if [ ! -e .adminer-init ]; then
for css_file in adminer.css adminer-dark.css; do
if [ -f "designs/$$ADMINER_DESIGN/$$css_file" ]; then
ln -sf "designs/$$ADMINER_DESIGN/$$css_file" adminer.css
break
fi
done
fi
fi
number=1
for PLUGIN in $$ADMINER_PLUGINS; do
php plugin-loader.php "$$PLUGIN" > plugins-enabled/$$(printf "%03d" $$number)-$$PLUGIN.php
number=$$(($$number+1))
done
touch .adminer-init || true
exec "$$@"