feat(Docker): Adding a working Dockerfile and compose to prototype

This commit is contained in:
Josepablo Cruz
2026-04-01 14:03:20 -06:00
parent 4fcd3f01a5
commit bd3fddbbc2
13 changed files with 723 additions and 51 deletions

View File

@@ -7,14 +7,18 @@ ARG VCS_REF
RUN apk add --no-cache mariadb mysql-client mariadb-server-utils pwgen && \
rm -f /var/cache/apk/*
RUN mkdir /schemas
COPY schemas /schemas
ADD scripts/run.sh /scripts/run.sh
RUN mkdir /schemas && mkdir /scripts
RUN mkdir /docker-entrypoint-initdb.d && \
mkdir /scripts/pre-exec.d && \
mkdir /scripts/pre-init.d && \
chmod -R 755 /scripts
mkdir /scripts/pre-init.d
#
# Populate content here
#
ADD scripts/run.sh /scripts/run.sh
# COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
RUN chmod -R 755 /scripts
EXPOSE 3306

View File

@@ -1,10 +1,6 @@
# ETAv2SQL
# MySQL Databse schema
![etaviaporte](./Models/assets/Modelv2.0.0.png)
# Docker
# Docker Container to deploy MySQL with schema and content init
## Build Docker image
@@ -20,3 +16,27 @@ docker logs -f eta-db
```
Container will generate automatically a SQL root password
### Environment Variables
You can setup a database name and grant access to it with user/password using the following env vars
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
```{.sh}
docker run --name eta-db -e MYSQL_DATABASE=u947463964_etaviaporte -e MYSQL_USER=etaapi -e MYSQL_PASSWORD="secret_password" -d -p3306:3306 eta/eta-db
```
### Schemas and SQL scripts
You can add schemas and sql scripts to the container to setup the database on startup by mounting a directory with sql scripts on `/docker-entrypoint-initdb.d`
```{.sh}
docker run --name eta-db -e MYSQL_DATABASE=u947463964_etaviaporte -e MYSQL_USER=etaapi -e MYSQL_PASSWORD="secret_password" -v ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d -d -p3306:3306 eta/eta-db
```
### Known Issues
- When loading a script, errors my araise when using `"` instead of `'` and when comments appear at the end of a command

View File

@@ -70,13 +70,14 @@ EOF
fi
fi
/usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile
/usr/bin/mariadbd --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile
rm -f $tfile
for f in /docker-entrypoint-initdb.d/*; do
echo
case "$f" in
*.sql) echo "$0: running $f"; /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | /usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*.sql) echo "$0: running $f"; /usr/bin/mariadbd --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | /usr/bin/mariadbd --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < "$f"; echo ;;
*) echo "$0: ignoring or entrypoint initdb empty $f" ;;
esac
echo
@@ -86,7 +87,7 @@ EOF
echo 'MySQL init process done. Ready for start up.'
echo
echo "exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0" "$@"
echo "exec /usr/bin/mariadbd --user=mysql --console --skip-name-resolve --skip-networking=0" "$@"
# Saving plain password
echo $MYSQL_ROOT_PASSWORD > /schemas/password.txt
@@ -101,4 +102,4 @@ do
fi
done
exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0 $@
exec /usr/bin/mariadbd --user=mysql --console --skip-name-resolve --skip-networking=0 $@