Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
codyfinegan committed Jul 2, 2024
2 parents fc40ef4 + a0696eb commit 345c289
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Although this project started as a development environment for Totara Learn it c
* [Apache](https://httpd.apache.org/) as a webserver
* [PHP](http://php.net/) 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 to test for different versions
* [PostgreSQL](https://www.postgresql.org/) (9.3, 9.6, 10, 11, 12, 13, 14, 15, 16),
* [MariaDB](https://mariadb.org/) (10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.11),
* [MariaDB](https://mariadb.org/) (10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.11, 11.4),
* [MySQL](https://www.mysql.com/) (5.7, 8.0, 8.4),
* Microsoft SQL Server ([2017](https://www.microsoft.com/en-us/sql-server/sql-server-2017), [2019](https://www.microsoft.com/en-us/sql-server/sql-server-2019))
* Microsoft SQL Server ([2017](https://www.microsoft.com/en-us/sql-server/sql-server-2017), [2019](https://www.microsoft.com/en-us/sql-server/sql-server-2019), [2022](https://www.microsoft.com/en-us/sql-server/sql-server-2022))
* [NodeJS](https://nodejs.org/) for building, developing and testing frontend code
* A [PHPUnit](https://phpunit.de/) and [Behat](http://behat.org/en/latest/) setup to run tests (including [Selenium](https://www.seleniumhq.org/))
* A [mailcatcher](https://mailcatcher.me/) instance to view sent emails
Expand Down
17 changes: 12 additions & 5 deletions bin/tdb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,14 @@ elif [ "$db_type" == 'mysqli' ]; then
# MariaDB #
##########################################
elif [ "$db_type" == 'mariadb' ]; then
db_sql_cmd="$db_command mysql -u\"$db_user\" -p\"$db_password\""
if [[ "$db_host" == 'mariadb1104' ]]; then
db_maria_cmd="mariadb"
db_maria_backup_cmd="mariadb-dump"
else
db_maria_cmd="mysql"
db_maria_backup_cmd="mysqldump"
fi
db_sql_cmd="$db_command $db_maria_cmd -u\"$db_user\" -p\"$db_password\""

# Create mariadb database
if [ "$action" == 'create' ]; then
Expand All @@ -348,14 +355,14 @@ elif [ "$db_type" == 'mariadb' ]; then

# Backup mariadb database
elif [ "$action" == 'backup' ]; then
eval "$db_command mysqldump -u\"$db_user\" -p\"$db_password\" $db_name" > "$backup_file_local" || exit
eval "$db_command $db_maria_backup_cmd -u\"$db_user\" -p\"$db_password\" $db_name" > "$backup_file_local" || exit

# Restore mariadb database
elif [ "$action" == 'restore' ]; then
eval "$db_sql_cmd -e \"DROP DATABASE IF EXISTS $db_name\""
eval "$db_sql_cmd -e \"CREATE DATABASE $db_name DEFAULT CHARACTER SET $character_set COLLATE $collation\""
docker cp "$backup_file_local" "$db_container":"$backup_file_remote"
$db_command sh -c "mysql -u\"$db_user\" -p\"$db_password\" $db_name < $backup_file_remote" >> /dev/null
$db_command sh -c "$db_maria_cmd -u\"$db_user\" -p\"$db_password\" $db_name < $backup_file_remote" >> /dev/null
if [ "${PIPESTATUS[0]}" == '1' ]; then
$db_command sh -c "rm $backup_file_remote"
echo -e "\x1B[31mThere was an error while restoring $db_host database '$db_name' from file '$backup_file_local'\x1B[0m"
Expand All @@ -365,7 +372,7 @@ elif [ "$db_type" == 'mariadb' ]; then

# Start mariadb shell
elif [ "$action" == 'shell' ]; then
docker exec -it "$db_container" sh -c "mysql -u\"$db_user\" -p\"$db_password\" -A $db_name"
docker exec -it "$db_container" sh -c "$db_maria_cmd -u\"$db_user\" -p\"$db_password\" -A $db_name"

# Handle unimplemented action
else
Expand All @@ -381,7 +388,7 @@ elif [ "$db_type" == 'mssql' ]; then
if [[ "$php_container_name" == 'php-5.6' || "$php_container_name" == 'php-7.0' || "$php_container_name" == 'php-7.1' || "$php_container_name" == 'php-7.2' ]]; then
sqlcmd="/opt/mssql-tools/bin/sqlcmd"
else
sqlcmd="/opt/mssql-tools18/bin/sqlcmd -C"
sqlcmd="/opt/mssql-tools18/bin/sqlcmd -No -C"
fi

# Handles executing sql commands.
Expand Down
5 changes: 5 additions & 0 deletions compose/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ services:
context: ./mssql
dockerfile: 2019/Dockerfile

mssql2022:
build:
context: ./mssql
dockerfile: 2022/Dockerfile

php-5.3:
build: ./php/php53

Expand Down
17 changes: 17 additions & 0 deletions compose/mariadb.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
services:

mariadb1104:
image: mariadb:11.4
container_name: totara_mariadb1104
ports:
- "3316:3306"
environment:
TZ: ${TIME_ZONE}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PW}
volumes:
- mariadb1104-data:/var/lib/mysql
- ./mariadb:/etc/mysql/conf.d
depends_on:
- nginx
networks:
- totara

mariadb1011:
image: mariadb:10.11
container_name: totara_mariadb1011
Expand Down Expand Up @@ -130,6 +146,7 @@ services:

volumes:
mariadb-data:
mariadb1104-data:
mariadb1011-data:
mariadb108-data:
mariadb107-data:
Expand Down
20 changes: 20 additions & 0 deletions compose/mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ services:
networks:
- totara

mssql2022:
image: totara/docker-dev-mssql2022
# Mssql does not support multiple architectures
platform: linux/amd64
container_name: totara_mssql2022
ports:
- "1420:1433"
environment:
TZ: ${TIME_ZONE}
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: ${MSSQL_SA_PW}
MSSQL_PID: Developer
volumes:
- mssql2022-data:/var/opt/mssql
depends_on:
- nginx
networks:
- totara

volumes:
mssql-data:
mssql2019-data:
mssql2022-data:
40 changes: 40 additions & 0 deletions mssql/2022/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# mssql-agent-fts-ha-tools
# Maintainers: Microsoft Corporation (twright-msft on GitHub)
# GitRepo: https://github.com/Microsoft/mssql-docker

FROM --platform=linux/amd64 ubuntu:22.04

# Install Server FTS & HA
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -y \
gnupg && \
apt-get install -y \
curl \
locales \
apt-transport-https && \
curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc && \
curl -fsSL https://packages.microsoft.com/config/ubuntu/22.04/mssql-server-2022.list | tee /etc/apt/sources.list.d/mssql-server-2022.list && \
curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | tee /etc/apt/sources.list.d/mssql-release.list && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
ACCEPT_EULA=Y apt-get install -y \
mssql-server \
mssql-server-ha \
mssql-server-fts \
mssql-tools18 \
unixodbc-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists

# Copy the config across
RUN mkdir -p /usr/config
COPY 2022/custom /usr/config

RUN chmod +x /usr/config/entrypoint.sh
RUN chmod +x /usr/config/setup.sh

WORKDIR /usr/config

# Run SQL Server process
ENTRYPOINT ["./entrypoint.sh"]
7 changes: 7 additions & 0 deletions mssql/2022/custom/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# Start the script to create the DB and import the data, start the app
/usr/config/setup.sh &

# Start the server
/opt/mssql/bin/sqlservr
13 changes: 13 additions & 0 deletions mssql/2022/custom/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# The SQL server won't start by this time, so let's gently wait for it, if it won't start in 120 sec, let's fail anyway.
timeout=$(($(date +%s) + 120))
until /opt/mssql-tools18/bin/sqlcmd -No -H localhost -U sa -P "$MSSQL_SA_PASSWORD" -Q "select 'hello'" || [[ $(date +%s) -gt $timeout ]]; do
echo 'SQL server is not ready yet, sleeping for 2 seconds...'
sleep 2
done

echo "Running initial SQL statements"

# run the setup script to run initial sql statements
/opt/mssql-tools18/bin/sqlcmd -No -S localhost -U SA -P "$MSSQL_SA_PASSWORD" -d master -i /usr/config/setup.sql
5 changes: 5 additions & 0 deletions mssql/2022/custom/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;

EXEC sp_configure 'clr strict security', 0;
RECONFIGURE;

0 comments on commit 345c289

Please sign in to comment.