Skip to content

Commit 886303f

Browse files
committed
add files
1 parent 436e571 commit 886303f

11 files changed

+264
-2
lines changed

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM newnius/php:7.3
2+
3+
MAINTAINER Newnius <[email protected]>
4+
5+
RUN curl -L https://github.com/newnius/QuickAuth/archive/v2.0.1.tar.gz > /tmp/quickauth.tar.gz \
6+
&& tar -C /tmp -xzvf /tmp/quickauth.tar.gz \
7+
&& mv /tmp/QuickAuth-2.0.1/.htaccess /var/www/html \
8+
&& mv /tmp/QuickAuth-2.0.1/* /var/www/html \
9+
&& rm -rf /tmp/*
10+
11+
ADD config/config.js /var/www/html/static/
12+
13+
ADD config/config.inc.php /var/www/html/
14+
15+
ADD bootstrap.sh /etc/
16+
17+
CMD /etc/bootstrap.sh

README.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
1-
# QuickAuth
2-
Deploy a OAuth system quickly
1+
# QuickAuth quick deploy
2+
3+
Deploy the [QuickAuth](https://github.com/newnius/QuickAuth) user management system quickly.
4+
5+
## Requirements
6+
7+
- `docker` install (version >= 17.03)
8+
- Permission to run docker commands
9+
- A docker swarm created and this is the **only** node, or the storage may encounter failure
10+
- One overlay network named `swarm-net`
11+
- The directory `/data` exists and able to read/write
12+
13+
If you haven't meet the requirements, refer to this script `install_requirements.sh` to setup that.
14+
15+
## Steps to deploy
16+
17+
#### Clone this repo
18+
19+
```bash
20+
git clone https://github.com/QuickDeploy/QuickAuth.git
21+
```
22+
23+
#### Start the services
24+
25+
```bash
26+
bash QuickAuth/install.sh
27+
```
28+
29+
#### Setup the database
30+
31+
visit `http://127.0.0.1/install.php` to init the system, and you will see four `Success`
32+
33+
#### Setup th SendGrid api keys
34+
35+
Visit [SendGrid](https://app.sendgrid.com/) to signup for an account and apply for your own API keys.
36+
37+
#### Run on your own servers
38+
39+
Modify the config files `/data/qa/web/config/config.js` and `/data/qa/web/config/config.inc.php`
40+
41+
Properties to be updated are `BASE_URL`, `SENDGRID_API_KEY`, `EMAIL_FROM`
42+
43+
That's all!
44+
45+
## Advanced users
46+
47+
Feel free to post issues.

bootstrap.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
if [[ -d /config/ ]]; then
4+
if [[ ! -f /config/config.js ]]; then
5+
cp /var/www/html/static/config.js /config/config.js
6+
fi
7+
8+
if [[ ! -f /config/config.inc.php ]]; then
9+
cp /var/www/html/config.inc.php /config/config.inc.php
10+
fi
11+
fi
12+
13+
if [[ -f /config/config.js ]]; then
14+
rm /var/www/html/static/config.js
15+
ln -s /config/config.js /var/www/html/static/config.js
16+
fi
17+
18+
if [[ -f /config/config.inc.php ]]; then
19+
rm /var/www/html/config.inc.php
20+
ln -s /config/config.inc.php /var/www/html/config.inc.php
21+
fi
22+
23+
apache2-foreground

config/config.inc.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/* Mysql */
4+
/* It is not recommended to use `root` in production environment */
5+
define('DB_HOST', 'qa-mysql');
6+
define('DB_PORT', 3306);
7+
define('DB_NAME', 'quickauth');
8+
define('DB_USER', 'root');
9+
define('DB_PASSWORD', '123456');
10+
define('DB_SHOW_ERROR', false);
11+
12+
/* Redis */
13+
/* Make sure that your Redis only listens to Intranet */
14+
define('REDIS_SCHEME', 'tcp');
15+
define('REDIS_HOST', 'qa-redis');
16+
define('REDIS_PORT', 6379);
17+
define('REDIS_SHOW_ERROR', false);
18+
19+
/* Site */
20+
define('BASE_URL', 'http://127.0.0.1'); //make absolute url for SEO and avoid hijack, no '/' at the end
21+
define('FORCE_VERIFY', false); //if set, unverified user will be refused to login (Warn: leave this switch as it is not finished)
22+
//define('ALLOW_REGISTRATION', true);
23+
//define('ALLOW_CUSTOM_UID', true);
24+
define('FEEDBACK_EMAIL', '[email protected]');
25+
define('ALLOW_REGISTER', true);
26+
27+
/* OAuth */
28+
define('ENABLE_OAUTH', true);
29+
define('OAUTH_CODE_TIMEOUT', 300); // 5 min
30+
define('OAUTH_TOKEN_TIMEOUT', 604800); // 7 day
31+
32+
/* Session */
33+
define('ENABLE_MULTIPLE_LOGIN', true);
34+
define('BIND_SESSION_WITH_IP', false);
35+
define('SESSION_TIME_OUT', 1800);// 30 minutes 30*60=1800
36+
define('ENABLE_COOKIE', true);
37+
38+
/* Rate Limit */
39+
define('ENABLE_RATE_LIMIT', true);
40+
define('RATE_LIMIT_KEY_PREFIX', 'rl');
41+
42+
/* Email */
43+
define('ENABLE_EMAIL_ANTISPAM', true);
44+
//define('MAXIMUM_EMAIL_PER_IP', 8);
45+
define('MAXIMUM_EMAIL_PER_EMAIL', 5);//last 24 hours
46+
define('SENDGRID_API_KEY', '');
47+
define('EMAIL_FROM', '[email protected]');

config/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
window.config = {
2+
'BASE_URL': 'http://127.0.0.1' /* No '/' at the end */
3+
4+
};

install.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
4+
5+
if [[ ! -d /data ]]; then
6+
echo "Make sure dir /data exists and this user has read/write access !"
7+
exit 1;
8+
fi
9+
10+
mkdir -p /data/qa/redis
11+
mkdir -p /data/qa/mysql/data
12+
mkdir -p /data/qa/web/config
13+
mkdir -p /data/qa/web/logs
14+
15+
docker pull redis:5
16+
docker pull mysql:5.7
17+
docker pull quickdeploy/quickauth:v2.0
18+
19+
bash "${DIR}/swarm_start_redis.sh"
20+
21+
bash "${DIR}/swarm_start_mysql.sh"
22+
23+
bash "${DIR}/swarm_start_web.sh"
24+
25+
echo "Please wait until services started"
26+
27+
echo "Use 'docker service ps qa-' to see the status"
28+
29+
echo "After started, visit http://127.0.0.1/install.php to setup the system"

install_requirements.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# install latest docker
4+
curl -fsSL https://get.docker.com | sh
5+
6+
sudo usermod -aG docker $USER
7+
8+
# enable auto start
9+
sudo systemctl start docker
10+
11+
sudo systemctl enable docker
12+
13+
# create docker swarm
14+
15+
sudo docker swarm init --listen-addr 127.0.0.1
16+
17+
# create overlay network named `swarm-net`
18+
sudo docker network create --driver overlay swarm-net
19+
20+
# create directory for storing data
21+
sudo mkdir /data
22+
23+
sudo chown $USER:$USER /data
24+
25+
26+
# re-login to take effect
27+
28+
echo 're-login to take effect'
29+
30+
exit

swarm_start_mysql.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/bash
2+
3+
docker service create \
4+
--name qa-mysql \
5+
--hostname qa-mysql \
6+
--network swarm-net \
7+
--replicas 1 \
8+
--endpoint-mode dnsrr \
9+
--mount type=bind,source=/data/qa/mysql/data,target=/var/lib/mysql \
10+
-e MYSQL_ROOT_PASSWORD=123456 \
11+
-e MYSQL_DATABASE=quickauth \
12+
mysql:5.7

swarm_start_redis.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/bash
2+
3+
docker service create \
4+
--name qa-redis \
5+
--hostname qa-redis \
6+
--network swarm-net \
7+
--replicas 1 \
8+
--endpoint-mode dnsrr \
9+
--mount type=bind,source=/etc/localtime,target=/etc/localtime \
10+
--mount type=bind,source=/data/qa/redis,target=/data \
11+
redis:5 redis-server --appendonly yes

swarm_start_web.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/bash
2+
3+
docker service create \
4+
--name qa-web \
5+
--hostname qa-web \
6+
--network swarm-net \
7+
--replicas 1 \
8+
--publish mode=host,published=80,target=80 \
9+
--mount type=bind,source=/etc/localtime,target=/etc/localtime \
10+
--mount type=bind,source=/data/qa/web/config,target=/config \
11+
--mount type=bind,source=/data/qa/web/logs,target=/var/log/apache2 \
12+
quickdeploy/quickauth:v2.0

uninstall.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
echo 'Warning !'
4+
5+
echo 'It is dangerous to run this script as it would erase all the data'
6+
7+
echo 'Do not run this script unless you absolutely know what will happen'
8+
9+
echo 'You may press Ctrl+C now to abort this script'
10+
11+
echo ''
12+
13+
echo '+Sleep 10'
14+
15+
sleep 10
16+
17+
18+
19+
docker service rm qa-web
20+
21+
docker service rm qa-mysql
22+
23+
docker service rm qa-redis
24+
25+
26+
rm -rf /data/qa/
27+
28+
docker rmi redis:5
29+
docker rmi mysql:5.7
30+
docker rmi quickdeploy/quickauth:v2.0
31+
32+
echo "All data & services removed !"

0 commit comments

Comments
 (0)