diff --git a/.env b/.env new file mode 100644 index 00000000..0314325d --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +# Set COMPOSE_PROFILES to one of the following: postgres, mysql, mssql +COMPOSE_PROFILES=mssql \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7b0c5531..aef65ecc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,5 @@ +# You can easily switch between different databases by changing the value of COMPOSE_PROFILES in the .env file. services: - test: - image: debian:stable-slim - volumes: - - .:/var/www - depends_on: - - db - environment: - DATABASE_URL: ${DB:-postgres}://root:secret@db/sqlpage web: build: { context: "." } ports: @@ -14,17 +7,25 @@ services: volumes: - .:/var/www depends_on: - - db + - ${COMPOSE_PROFILES-postgres} environment: - DATABASE_URL: ${DB:-postgres}://root:secret@db/sqlpage - db: # The DB environment variable can be set to "mariadb" or "postgres" to test the code with different databases - ports: - - "5432:5432" - - "3306:3306" - image: ${DB:-postgres} + DATABASE_URL: ${COMPOSE_PROFILES-postgres}://root:secret@${COMPOSE_PROFILES:-postgres}/sqlpage + postgres: + profiles: ["postgres"] + ports: ["5432:5432"] + image: postgres environment: POSTGRES_USER: root POSTGRES_DB: sqlpage POSTGRES_PASSWORD: secret + mysql: + profiles: ["mysql"] + ports: ["3306:3306"] + image: mysql + environment: MYSQL_ROOT_PASSWORD: secret - MYSQL_DATABASE: sqlpage \ No newline at end of file + MYSQL_DATABASE: sqlpage + mssql: + profiles: ["mssql"] + ports: ["1433:1433"] + build: { context: "mssql" } \ No newline at end of file diff --git a/mssql/Dockerfile b/mssql/Dockerfile new file mode 100644 index 00000000..99cace2f --- /dev/null +++ b/mssql/Dockerfile @@ -0,0 +1,24 @@ +ARG VERSION=2019-latest +FROM mcr.microsoft.com/mssql/server:${VERSION} + +# Create a config directory +RUN mkdir -p /usr/config +WORKDIR /usr/config + +# Bundle config source +COPY entrypoint.sh /usr/config/entrypoint.sh +COPY configure-db.sh /usr/config/configure-db.sh +COPY setup.sql /usr/config/setup.sql + +# Grant permissions for to our scripts to be executable +USER root +RUN chmod +x /usr/config/entrypoint.sh +RUN chmod +x /usr/config/configure-db.sh +RUN chown 10001 /usr/config/entrypoint.sh +RUN chown 10001 /usr/config/configure-db.sh +USER 10001 + +ENV SA_PASSWORD="Password123!" +ENV ACCEPT_EULA="Y" + +ENTRYPOINT ["/usr/config/entrypoint.sh"] diff --git a/mssql/configure-db.sh b/mssql/configure-db.sh new file mode 100644 index 00000000..5d00db98 --- /dev/null +++ b/mssql/configure-db.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Wait 15 seconds for SQL Server to start up +sleep 15 + +# Run the setup script to create the DB and the schema in the DB +/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P "$SA_PASSWORD" -d master -i setup.sql diff --git a/mssql/entrypoint.sh b/mssql/entrypoint.sh new file mode 100644 index 00000000..c4b5e45c --- /dev/null +++ b/mssql/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Start the script to create the DB and user +/usr/config/configure-db.sh & + +# Start SQL Server +/opt/mssql/bin/sqlservr diff --git a/mssql/setup.sql b/mssql/setup.sql new file mode 100644 index 00000000..d278da3d --- /dev/null +++ b/mssql/setup.sql @@ -0,0 +1,11 @@ +IF DB_ID('sqlpage') IS NULL + BEGIN + CREATE DATABASE sqlpage; + END; +GO + +USE sqlpage; +GO + +CREATE USER root WITH PASSWORD = 'secret'; +GO \ No newline at end of file