Skip to content

Commit 10778b3

Browse files
committed
Added docker image for Ubuntu 16.04
1 parent a5514a5 commit 10778b3

File tree

5 files changed

+120
-2
lines changed

5 files changed

+120
-2
lines changed

docker/build_all.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
FILES=*
3+
4+
for f in $FILES
5+
do
6+
if [[ -d "$f" ]]
7+
then
8+
docker build "$f" -t "php-crud-api:$f"
9+
fi
10+
done

docker/run_all.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
FILES=*
3+
4+
for f in $FILES
5+
do
6+
if [[ -d "$f" ]]
7+
then
8+
docker rm "php-crud-api_$f" > /dev/null 2>&1
9+
docker run -ti --name "php-crud-api_$f" "php-crud-api:$f"
10+
fi
11+
done

docker/ubuntu16/Dockerfile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM ubuntu:16.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
# install: php / mysql / postgres / sqlite / tools / mssql deps
6+
RUN apt-get update && apt-get -y install \
7+
php-cli php-xml \
8+
mysql-server mysql-client php-mysql \
9+
postgresql php-pgsql \
10+
postgresql-9.5-postgis-2.2 \
11+
sqlite php-sqlite3 \
12+
git wget \
13+
curl apt-transport-https debconf-utils sudo
14+
15+
# adding custom MS repository
16+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
17+
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
18+
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list > /etc/apt/sources.list.d/mssql-server-2017.list
19+
20+
# install SQL Server and tools
21+
RUN apt-get update && apt-get -y install mssql-server
22+
RUN ACCEPT_EULA=Y MSSQL_PID=Express MSSQL_SA_PASSWORD=sapwd123! /opt/mssql/bin/mssql-conf setup || true
23+
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools
24+
25+
# install pdo_sqlsrv
26+
RUN apt-get -y install php-pear build-essential unixodbc-dev php-dev
27+
RUN pecl install pdo_sqlsrv
28+
RUN echo extension=pdo_sqlsrv.so > /etc/php/7.0/mods-available/pdo_sqlsrv.ini
29+
RUN phpenmod pdo_sqlsrv
30+
31+
# install locales
32+
RUN apt-get -y install locales
33+
RUN locale-gen en_US.UTF-8
34+
RUN update-locale LANG=en_US.UTF-8
35+
36+
# install run script
37+
ADD run.sh /usr/sbin/docker-run
38+
CMD docker-run

docker/ubuntu16/run.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
echo "- Starting MySQL 5.7"
4+
# make sure mysql can create socket and lock
5+
mkdir /var/run/mysqld && chmod 777 /var/run/mysqld
6+
# run mysql server
7+
nohup mysqld > /root/mysql.log 2>&1 &
8+
# wait for mysql to become available
9+
while ! mysqladmin ping -hlocalhost >/dev/null 2>&1; do
10+
sleep 1
11+
done
12+
# create database and user on mysql
13+
mysql -u root >/dev/null << 'EOF'
14+
CREATE DATABASE `php-crud-api` CHARACTER SET utf8 COLLATE utf8_general_ci;
15+
CREATE USER 'php-crud-api'@'localhost' IDENTIFIED BY 'php-crud-api';
16+
GRANT ALL PRIVILEGES ON `php-crud-api`.* TO 'php-crud-api'@'localhost' WITH GRANT OPTION;
17+
FLUSH PRIVILEGES;
18+
EOF
19+
20+
echo "- Starting PostgreSQL 9.5"
21+
# run postgres server
22+
nohup su - -c "/usr/lib/postgresql/9.5/bin/postgres -D /etc/postgresql/9.5/main" postgres > /root/postgres.log 2>&1 &
23+
# wait for postgres to become available
24+
until su - -c "psql -U postgres -c '\q'" postgres >/dev/null 2>&1; do
25+
sleep 1;
26+
done
27+
# create database and user on postgres
28+
su - -c "psql -U postgres >/dev/null" postgres << 'EOF'
29+
CREATE USER "php-crud-api" WITH PASSWORD 'php-crud-api';
30+
CREATE DATABASE "php-crud-api";
31+
GRANT ALL PRIVILEGES ON DATABASE "php-crud-api" to "php-crud-api";
32+
\c "php-crud-api";
33+
CREATE EXTENSION IF NOT EXISTS postgis;
34+
\q
35+
EOF
36+
37+
echo "- Starting SQLServer 2017"
38+
# run sqlserver server
39+
nohup /opt/mssql/bin/sqlservr --accept-eula > /root/mysql.log 2>&1 &
40+
# create database and user on postgres
41+
/opt/mssql-tools/bin/sqlcmd -l 10 -S localhost -U SA -P sapwd123! >/dev/null << 'EOF'
42+
CREATE DATABASE [php-crud-api]
43+
GO
44+
CREATE LOGIN [php-crud-api] WITH PASSWORD=N'php-crud-api', DEFAULT_DATABASE=[php-crud-api], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
45+
GO
46+
USE [php-crud-api]
47+
GO
48+
CREATE USER [php-crud-api] FOR LOGIN [php-crud-api] WITH DEFAULT_SCHEMA=[dbo]
49+
exec sp_addrolemember 'db_owner', 'php-crud-api';
50+
GO
51+
exit
52+
EOF
53+
54+
echo "- Cloning PHP-CRUD-API"
55+
# install software
56+
git clone --quiet https://github.com/mevdschee/php-crud-api2.git
57+
58+
echo "- Running all tests"
59+
# run the tests
60+
cd php-crud-api2
61+
php test.php

tests/fixtures/create_sqlsrv.sql

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
USE [master]
2-
GO
31
CREATE DATABASE [php-crud-api]
42
GO
53
CREATE LOGIN [php-crud-api] WITH PASSWORD=N'php-crud-api', DEFAULT_DATABASE=[php-crud-api], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF

0 commit comments

Comments
 (0)