Skip to content

Commit

Permalink
First import
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Dec 14, 2019
1 parent f1f3cef commit 65603fa
Show file tree
Hide file tree
Showing 14 changed files with 401 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changlog
=========

0.1.0 (2019-12-14)
---------------------

* Initial Release.
79 changes: 79 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FROM centos:7

RUN rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
rpm -i https://centos7.iuscommunity.org/ius-release.rpm && \
rpm -i https://rpm.nodesource.com/pub_8.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm && \
yum install -y curl && \
curl https://www.apache.org/dist/bigtop/stable/repos/centos7/bigtop.repo \
> /etc/yum.repos.d/bigtop.repo && \
yum install -y sudo \
gcc \
gcc-c++ \
git \
java \
redis \
zookeeper \
mariadb101u-server \
nginx \
nodejs \
libsass-devel \
python \
python-devel\
python-pip \
supervisor

RUN pip install -U pip virtualenv && \
sudo -u mysql /usr/libexec/mysql-prepare-db-dir
ENV SUPERVISOR 1

WORKDIR /srv/huskar_api/
RUN git clone https://github.com/huskar-org/huskar.git . && \
git checkout v0.242.4 && \
rm -rf .git

WORKDIR /srv/huskar_api/
RUN virtualenv /opt/huskar_api && \
/opt/huskar_api/bin/pip install -r requirements.txt

WORKDIR /srv/huskar_console/
RUN git clone https://github.com/huskar-org/huskar-console.git . && \
git checkout v0.174.2 && \
rm -rf .git

WORKDIR /srv/huskar_console/
ENV HUSKAR_API_URL http://127.0.0.1/api
ENV HUSKAR_FEATURE_LIST createapp,stateswitch,infrarawurl
ENV HUSKAR_EZONE_LIST global,alta1,altb1
ENV HUSKAR_IDC_LIST alta,altb
ENV HUSKAR_ROUTE_EZONE_CLUSTER_LIST alta1:alta1-test,altb1:altb1-test
RUN npm install && \
NODE_ENV=production npm run build && \
rm -rf ./node_modules/

WORKDIR /srv/
ENV GEVENT_RESOLVER block
ENV HUSKAR_API_APP_NAME huskar.api
ENV HUSKAR_API_ADMIN_FRONTEND_NAME huskar.console
ENV HUSKAR_API_TESTING 1
ENV HUSKAR_API_SECRET_KEY all-in-one
ENV HUSKAR_API_EZONE alta1
ENV HUSKAR_API_CLUSTER alta1-test
ENV HUSKAR_API_DB_URL mysql+pymysql://root@localhost/huskar_api?charset=utf8mb4
ENV DATABASE_DEFAULT_URL mysql://root@localhost/huskar_api?charset=utf8mb4
ENV HUSKAR_API_REDIS_URL redis://localhost:6379/0
ENV REDIS_DEFAULT_URL redis://localhost:6379/0
ENV HUSKAR_API_ZK_SERVERS 127.0.0.1:2181

COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/conf.d /etc/nginx/conf.d
COPY supervisord.d /etc/supervisord.d
COPY scripts/entrypoint_api.sh /opt/huskar_api/bin/entrypoint.sh
COPY scripts/init-cfg.py /opt/huskar_api/bin/init-cfg.py
RUN chmod +x /opt/huskar_api/bin/entrypoint.sh
COPY scripts/entrypoint_console.sh /opt/huskar_console/bin/entrypoint.sh
RUN chmod +x /opt/huskar_console/bin/entrypoint.sh
RUN mkdir -p /var/log/huskar_api

EXPOSE 80

CMD ["supervisord", "--nodaemon"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TAG ?= huskarorg/huskar-all-in-one:latest

build:
docker build -t $(TAG) .
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# huskar-all-in-one

An all-in-one Docker image for Huskar Demo.


## Usage

```
docker run -d --name huskar-all-in-one -p 8080:80 huskarorg/huskar-all-in-one:latest
or
docker run -d --name huskar-all-in-one -p 8080:80 dockerhub.azk8s.cn/huskarorg/huskar-all-in-one:latest
```

Visit http://127.0.0.1:8080 .

P.S. You can login the console with username `huskar` and password `test` .


## Build

```
TAG=huskarorg/huskar-all-in-one:v0.1.0 make
```
34 changes: 34 additions & 0 deletions nginx/conf.d/huskar_console.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
map $http_user_agent $upstream_port {
default 81;
~(Mozilla|MSIE|iPhone|Android) 5000;
}

server {
listen 80 default_server;

root /srv/huskar_console/dist;
access_log /var/log/nginx/huskar_console.log main;

location /api/ {
client_max_body_size 0;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Scheme $scheme;
proxy_pass http://127.0.0.1:$upstream_port;
}

location ~* \.(js|css|png|map|woff|eot|svg|tff)$ {
expires max;
break;
}

location / {
expires -1;
rewrite / /index.html;
break;
}
}
39 changes: 39 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

include /etc/nginx/conf.d/*.conf;

server {
listen 80;
server_name _;
root /usr/share/nginx/html;

include /etc/nginx/default.d/*.conf;
location / {
}

}
}
57 changes: 57 additions & 0 deletions scripts/entrypoint_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

cd /srv/huskar_api

start() {
echo "=> Initializing configuration"
/opt/huskar_api/bin/python /opt/huskar_api/bin/init-cfg.py

echo "=> Ready"
exec /opt/huskar_api/bin/gunicorn \
-c config/gunicorn_config.py huskar_api.wsgi:app
}

echo "=> Checking database"
if [ -n "$(echo 'show databases' | mysql -uroot | grep huskar_api || true)" ]
then
start
fi

echo "=> Flushing database"
/usr/bin/redis-cli FLUSHALL
/usr/bin/mysql -uroot <<- DONE
CREATE DATABASE huskar_api CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
DONE
/usr/bin/mysql -uroot huskar_api < database/mysql.sql

echo "=> Importing application list"
/usr/bin/mysql -uroot huskar_api <<- DONE
INSERT INTO user (id, username, password, is_active, huskar_admin, is_app)
VALUES (1, 'huskar', '90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809',
1, 1, 0);
INSERT INTO team (id, team_name, team_desc, status)
VALUES (1, 'huskar', 'huskar', 0),
(2, 'dal', 'dal', 0),
(3, 'redis', 'redis', 0),
(4, 'amqp', 'amqp', 0),
(5, 'es', 'es', 0),
(6, 'mongo', 'mongo', 0),
(7, 'oss', 'oss', 0),
(8, 'kafka', 'kafka', 0);
INSERT INTO application (application_name, team_id, status)
VALUES ('huskar.api', '1', 0),
('huskar.console', '1', 0),
('dal.huskar_api', '2', 0),
('dal.demo', '2', 0),
('redis.huskar_api', '3', 0),
('redis.demo', '3', 0),
('amqp.demo', '4', 0),
('es.demo', '5', 0),
('mongo.demo', '6', 0),
('oss.demo', '7', 0),
('kafka.demo', '8', 0);
DONE

start
12 changes: 12 additions & 0 deletions scripts/entrypoint_console.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

result=""
until [[ $result -eq 200 ]] ; do
sleep 1
result=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:5000/api/health_check)
done

echo "=> Huskar API is ready, starting nginx..."
exec /usr/sbin/nginx -g 'daemon off;'
76 changes: 76 additions & 0 deletions scripts/init-cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-

import json
import os

from kazoo.client import KazooClient

client = KazooClient()
client.start()

ZK_PREFIX = '/huskar/config/huskar.api'
INFRA_APP_ID_LIST = [
'dal.huskar_api',
'dal.demo',
'redis.huskar_api',
'redis.demo',
'amqp.demo',
'es.demo',
'mongo.demo',
'oss.demo',
'kafka.demo',
]
EZONE = os.environ.get('HUSKAR_API_EZONE', 'alta1')
EZONE_LIST = os.environ.get('HUSKAR_EZONE_LIST', '').split(',')
EZONE_LIST = [x for x in EZONE_LIST if x != 'global']
IDC_LIST = os.environ.get('HUSKAR_IDC_LIST', '').split(',')
IDC_LIST = [x for x in IDC_LIST if x not in EZONE_LIST]


client.ensure_path(ZK_PREFIX + '/overall/ROUTE_IDC_LIST')
client.ensure_path(ZK_PREFIX + '/overall/ROUTE_EZONE_LIST')
client.set(ZK_PREFIX + '/overall/ROUTE_IDC_LIST', json.dumps(IDC_LIST))
client.set(ZK_PREFIX + '/overall/ROUTE_EZONE_LIST', json.dumps(EZONE_LIST))

client.ensure_path(ZK_PREFIX + '/overall/ROUTE_EZONE_DEFAULT_HIJACK_MODE')
for ezone in EZONE_LIST:
client.set(ZK_PREFIX + '/overall/ROUTE_EZONE_DEFAULT_HIJACK_MODE',
json.dumps({x: 'S' for x in EZONE_LIST}))

client.ensure_path(ZK_PREFIX + '/overall/FX_DATABASE_SETTINGS')
client.set(ZK_PREFIX + '/overall/FX_DATABASE_SETTINGS', json.dumps({
'idcs': {
EZONE: {
'default': {
'master': os.environ['DATABASE_DEFAULT_URL'],
'slave': os.environ['DATABASE_DEFAULT_URL'],
},
},
},
}))
client.ensure_path(ZK_PREFIX + '/overall/FX_REDIS_SETTINGS')
client.set(ZK_PREFIX + '/overall/FX_REDIS_SETTINGS', json.dumps({
'idcs': {
EZONE: {
'default': {
'url': os.environ['REDIS_DEFAULT_URL'],
},
},
},
}))

for app_id in INFRA_APP_ID_LIST:
for ezone in EZONE_LIST:
path = '/huskar/service/%s/overall.%s/192.168.0.1_5000' % (
app_id, ezone)
client.ensure_path(path)
client.set(path, json.dumps({
'ip': '192.168.0.1',
'port': {
'main': 5000,
},
'meta': {
'host': 'example.com',
},
'state': 'up',
}))
13 changes: 13 additions & 0 deletions supervisord.d/huskar_api.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[program:huskar_api]
command=/opt/huskar_api/bin/entrypoint.sh
autorestart=true
startretries=3
stopsignal=TERM
directory=/srv/huskar_api
user=root
group=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
redirect_stderr=true
stopasgroup=true
killasgroup=true
13 changes: 13 additions & 0 deletions supervisord.d/huskar_console.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[program:huskar_console]
command=/opt/huskar_console/bin/entrypoint.sh
autorestart=true
startretries=3
stopsignal=TERM
directory=/var/lib/nginx
user=root
group=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
redirect_stderr=true
stopasgroup=true
killasgroup=true
14 changes: 14 additions & 0 deletions supervisord.d/mariadb.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:mariadb]
command=/usr/libexec/mysqld --basedir=/usr
autorestart=true
startretries=3
stopsignal=TERM
directory=/var/lib/mysql
user=mysql
group=mysql
stdout_logfile=/var/log/mariadb/supervisor.log
stdout_logfile_maxbytes=3MB
stdout_logfile_backups=5
redirect_stderr=true
stopasgroup=true
killasgroup=true
14 changes: 14 additions & 0 deletions supervisord.d/redis.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[program:redis]
command=/usr/bin/redis-server /etc/redis.conf --daemonize no
autorestart=true
startretries=3
stopsignal=TERM
directory=/var/lib/redis
user=redis
group=redis
stdout_logfile=/var/log/redis/supervisor.log
stdout_logfile_maxbytes=3MB
stdout_logfile_backups=5
redirect_stderr=true
stopasgroup=true
killasgroup=true
Loading

0 comments on commit 65603fa

Please sign in to comment.