Skip to content

Commit dbb25da

Browse files
committed
refactor: use fenv for better .env content support
1 parent dd8f063 commit dbb25da

5 files changed

+11
-17
lines changed

docker/tmpl.Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ RUN adduser -h ${USER_HOME_DIR} -s /sbin/nologin -u 1000 -D ${USER_NAME} && \
2828
apk add --virtual build_deps $BUILD_DEPS && \
2929
\
3030
cp /usr/bin/envsubst /usr/local/bin/envsubst && \
31-
apk del build_deps
31+
apk del build_deps && \
32+
wget --quiet -O /tmp/fenv.tar.gz "https://github.com/joseluisq/fenv/releases/download/v1.0.0/fenv_1.0.0_linux_$arch.tar.gz"; \
33+
tar xzvf /tmp/fenv.tar.gz -C /usr/local/bin fenv; \
34+
rm -f /tmp/fenv.tar.gz; \
35+
chmod +x /usr/local/bin/fenv
3236

3337
COPY ./__mysqldump.sh /usr/local/bin/__mysqldump.sh
3438
COPY ./mysql_exporter /usr/local/bin/mysql_exporter

mysql_exporter

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ set -e
44

55
FILE_ENV=$1
66

7-
if [ -z "$FILE_ENV" ]; then
7+
if [[ -z "$FILE_ENV" ]]; then
88
__mysqldump.sh
99
exit 0
1010
fi
1111

12-
if [ -f $FILE_ENV ]; then
13-
export $(cat $FILE_ENV | xargs)
14-
15-
__mysqldump.sh
12+
if [[ -f $FILE_ENV ]]; then
13+
fenv -f $FILE_ENV __mysqldump.sh
1614
else
1715
echo "file \`$FILE_ENV\` was not found"
1816
exit 1

mysql_exporter.env

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
## MySQL Export template settings
22
## ------------------------------
3-
## Note:
4-
## .env files loading doesn't support comments,
5-
## so they should be removed before
63

74
# Connection settings (optional)
85
DB_PROTOCOL=tcp

mysql_importer

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ set -e
44

55
FILE_ENV=$1
66

7-
if [ -z "$FILE_ENV" ]; then
7+
if [[ -z "$FILE_ENV" ]]; then
88
__mysqlimport.sh
99
exit 0
1010
fi
1111

12-
if [ -f $FILE_ENV ]; then
13-
export $(cat $FILE_ENV | xargs)
14-
15-
__mysqlimport.sh
12+
if [[ -f $FILE_ENV ]]; then
13+
fenv -f $FILE_ENV __mysqlimport.sh
1614
else
1715
echo "file \`$FILE_ENV\` was not found"
1816
exit 1

mysql_importer.env

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
## MySQL Import template settings
22
## ------------------------------
3-
## Note:
4-
## .env files loading doesn't support comments,
5-
## so they should be removed before
63

74
# Connection settings (optional)
85
DB_PROTOCOL=tcp

0 commit comments

Comments
 (0)