Skip to content

Commit e9b5f3f

Browse files
author
yang.guo
authored
Merge pull request #236 from FlowCI/develop
Develop
2 parents d523293 + 8404f69 commit e9b5f3f

File tree

124 files changed

+3075
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3075
-449
lines changed

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Flow Platform Dockerfile
3+
# Image Name: flowci/flow-platform
4+
#
5+
# https://github.com/FlowCI/flow-platform
6+
#
7+
FROM flowci/flow-platform-base:latest
8+
9+
# setup flow.ci default environments
10+
ENV FLOW_PLATFORM_DIR=/etc/flow.ci
11+
ENV FLOW_PLATFORM_CONFIG_DIR=/etc/flow.ci/config
12+
ENV FLOW_PLATFORM_SOURCE_CODE=/flow-platform
13+
ENV MVN_CACHE=/root/.m2
14+
15+
# setup mysql config
16+
ADD ./docker/mysqld.cnf /etc/mysql/conf.d/mysqld.cnf
17+
VOLUME /var/lib/mysql
18+
19+
# config tomcat
20+
COPY ./docker/tomcat-users.xml $CATALINA_HOME/conf
21+
22+
# copy code
23+
COPY . $FLOW_PLATFORM_SOURCE_CODE
24+
25+
# mvn build and set wars to tomcat and delete no use thing
26+
RUN cd $FLOW_PLATFORM_SOURCE_CODE \
27+
&& rm -rf $FLOW_PLATFORM_SOURCE_CODE/dist \
28+
&& mvn clean install -DskipTests=true \
29+
&& mkdir -p $FLOW_PLATFORM_CONFIG_DIR \
30+
&& cd $FLOW_PLATFORM_SOURCE_CODE \
31+
&& mv ./dist/flow-control-center-*.war $CATALINA_HOME/webapps/flow-control-center.war \
32+
&& mv ./dist/flow-api-*.war $CATALINA_HOME/webapps/flow-api.war \
33+
&& rm -rf $FLOW_PLATFORM_SOURCE_CODE \
34+
&& rm -rf $MVN_CACHE
35+
36+
# setup flow.ci default configuration
37+
COPY ./docker/app-cc.properties $FLOW_PLATFORM_CONFIG_DIR
38+
COPY ./docker/app-api.properties $FLOW_PLATFORM_CONFIG_DIR
39+
40+
# wait for mysql
41+
COPY ./docker/flow.ci.backend.cmd.sh $FLOW_PLATFORM_DIR
42+
COPY ./schema/migration $FLOW_PLATFORM_DIR/migration
43+
44+
WORKDIR $FLOW_PLATFORM_DIR
45+
46+
CMD bash ./flow.ci.backend.cmd.sh catalina.sh run

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,38 @@ flow-platform
99

1010

1111
## Getting Start
12+
13+
### Start with docker
14+
15+
首先 Docker pull flowci/flow-platform , 把对应的镜像拉下来
1216

17+
> 环境变量的设置:
18+
>
19+
> - `FLOW_API_DOMAIN`:部署的后端 API 域名地址 `必填`
20+
> - `FLOW_WEB_DOMAIN`:部署的前端 Web 页面的域名地址 `必填`
21+
> - `FLOW_SYS_EMAIL`:flowci 系统管理员账号 `必填`
22+
> - `FLOW_SYS_USERNAME`:flowci 系统管理员的用户名 `必填`
23+
> - `FLOW_SYS_PASSWORD`:flowci 系统管理员密码 `必填`
24+
> - `MYSQL_PASSWORD`:flowci MYSQL 数据库的密码 `必填`
25+
> - `MYSQL_HOST`:flowci MYSQL 数据库的 `HOST` `必填`
26+
> - `PORT`:外网访问的 API 端口,默认:8080 `选填`
27+
> - `MYSQL 的存储路径`: `~/flow-ci/db` `选填`
28+
29+
```
30+
docker run -it \
31+
-e MYSQL_HOST=127.0.0.1 \
32+
-e MYSQL_PASSWORD=123456 \
33+
34+
-e FLOW_SYS_USERNAME=admin \
35+
-e FLOW_SYS_PASSWORD=123456 \
36+
-e FLOW_API_DOMAIN=127.0.0.1 \
37+
-e FLOW_WEB_DOMAIN=127.0.0.1 \
38+
-p 8080:8080 \
39+
-v ~/flow-ci/data:/var/lib/mysql \
40+
flowci/flow-platform
41+
42+
```
43+
1344
### Build by maven
1445

1546
Using standard maven `mvn clean install -DskipTests=true` to generate packages

config/app-api.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ hibernate.show_sql = false
1313
hibernate.hbm2ddl.auto = validate
1414

1515
### api settings ###
16-
api.workspace = ${HOME}/flow-api-data
17-
api.git.cache = ${HOME}/flow-api-data/git-cache
18-
api.git.workspace = ${HOME}/flow-api-data/git-repos
16+
api.workspace = ${HOME}/flow-ci/workspace
17+
api.git.cache = ${HOME}/flow-ci/git-cache
18+
api.git.workspace = ${HOME}/flow-ci/git-repos
1919
api.zone.default = default
2020

2121
### expiration duration of token, it's in millisecond ###

config/app-cc.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ hibernate.show_sql = false
1313
hibernate.hbm2ddl.auto = validate
1414

1515
### control center configuration
16-
cc.workspace = ${HOME}/flow-api/cc
16+
cc.workspace = ${HOME}/flow-ci/flow-control-center
1717

1818
### zookeeper config ###
1919
zk.server.embedded = true

docker/app-api.properties

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## for flow api local env ##
2+
3+
### JDBC config ###
4+
jdbc.url = jdbc:mysql://${MYSQL_HOST}:3306/flow_api_db?useSSL=false&createDatabaseIfNotExist=true
5+
jdbc.username = ${MYSQL_USER}
6+
jdbc.password = ${MYSQL_PASSWORD}
7+
jdbc.pool.size = 100
8+
jdbc.commit.auto = true
9+
jdbc.connection.timeout = 20000
10+
11+
### Hibernate config ###
12+
hibernate.show_sql = false
13+
hibernate.hbm2ddl.auto = validate
14+
15+
### api settings ###
16+
api.workspace = ${HOME}/flow-ci/workspace
17+
api.git.cache = ${HOME}/flow-ci/git-cache
18+
api.git.workspace = ${HOME}/flow-ci/git-repos
19+
api.zone.default = default
20+
21+
### expiration duration of token, it's in millisecond ###
22+
### 86400000 = 1000 * 60 * 60 * 24 = 1 day (will expiration after one day) ###
23+
api.user.expire = 86400000
24+
25+
### domain ###
26+
domain.api = http://${FLOW_API_DOMAIN}:${PORT}/flow-api
27+
domain.web = http://${FLOW_WEB_DOMAIN}
28+
domain.cc = http://127.0.0.1:8080/flow-control-center
29+
30+
system.email = ${FLOW_SYS_EMAIL}
31+
system.username = ${FLOW_SYS_USERNAME}
32+
system.password = ${FLOW_SYS_PASSWORD}
33+
34+
## plugin repos url
35+
plugins.repository = https://raw.githubusercontent.com/flowci/plugins/master/repository.json
36+
37+
task.job.toggle.execution_timeout = true
38+
## 6s expire job
39+
task.job.toggle.execution_create_session_duration = 1800
40+
## 1h expire job
41+
task.job.toggle.execution_running_duration = 3600
42+
43+

docker/app-cc.properties

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## for flow control center local env ##
2+
3+
### jdbc config ###
4+
jdbc.url = jdbc:mysql://${MYSQL_HOST}:3306/flow_cc_db?useSSL=false&createDatabaseIfNotExist=true
5+
jdbc.username = ${MYSQL_USER}
6+
jdbc.password = ${MYSQL_PASSWORD}
7+
jdbc.pool.size = 100
8+
jdbc.commit.auto = false
9+
jdbc.connection.timeout = 20000
10+
11+
### hibernate config ###
12+
hibernate.show_sql = false
13+
hibernate.hbm2ddl.auto = validate
14+
15+
### control center configuration
16+
cc.workspace = ${HOME}/flow-ci/flow-control-center
17+
18+
### zookeeper config ###
19+
zk.server.embedded = true
20+
zk.host = ${FLOW_API_DOMAIN}:2181
21+
zk.timeout = 30
22+
zk.node.root = flow-agents
23+
24+
# zone names and cloud provider config, ex: a=xxx;b=xxx;c=xxx
25+
zk.node.zone = default
26+
zone.default.agent_session_timeout = 600
27+
zone.default.default_cmd_timeout = 600
28+
29+
### rabbitmq config ###
30+
mq.host = amqp://localhost:5672
31+
mq.management.host = http://localhost:15672
32+
33+
#### cmd queue settings ###
34+
queue.cmd.retry.enable = false
35+
queue.cmd.rabbit.enable = false
36+
queue.cmd.rabbit.name = flow-cmd-queue-default
37+
queue.cmd.idle_agent.timeout = 30
38+
queue.cmd.idle_agent.period = 5
39+
40+
### agent report url config ###
41+
agent.config.ws = ws://${FLOW_API_DOMAIN}:${PORT}/flow-api
42+
agent.config.cc = http://${FLOW_API_DOMAIN}:${PORT}/flow-control-center
43+
44+
### task toggles ###
45+
task.zone.toggle.keep_idle_agent = false
46+
task.agent.toggle.session_timeout = true
47+
task.cmd.toggle.execution_timeout = true
48+
task.instance.mos.toggle.clean = true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# FlowPlatform Base Dockerfile
3+
# Image Name: flowci/flow-platform-base
4+
#
5+
# https://github.com/FlowCI/flow-platform
6+
#
7+
FROM flowci/flow.ci.tomcat:latest
8+
9+
ENV MAVEN_VERSION 3.3.9
10+
11+
# install git
12+
RUN apt-get update \
13+
&& apt-get install -y --no-install-recommends apt-utils \
14+
&& apt-get -y install git \
15+
&& git config --global user.email "[email protected]" \
16+
&& git config --global user.name "flowci"
17+
18+
# install open jdk
19+
RUN apt-get -y install openjdk-8-jdk \
20+
&& apt-get -y install procps \
21+
&& apt-get -y install vim
22+
23+
# install maven
24+
RUN curl -fsSL http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz | tar xzf - -C /usr/share \
25+
&& mv /usr/share/apache-maven-$MAVEN_VERSION /usr/share/maven \
26+
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
27+
28+
# install mysql
29+
RUN apt-get install -y mysql-server

docker/flow.ci.backend.cmd.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
set +e
3+
4+
cmd="$@"
5+
6+
# if mysql user is null, set default user root
7+
if [[ ! -n $MYSQL_USER ]]; then
8+
# set default mysql user name root
9+
export MYSQL_USER=root
10+
fi
11+
12+
# set mysql host, default 127.0.0.1
13+
if [[ ! -n $MYSQL_HOST ]]; then
14+
export $MYSQL_HOST=127.0.0.1
15+
fi
16+
17+
# set default port, default is 8080
18+
if [[ ! -n $PORT ]]; then
19+
export PORT=8080
20+
fi
21+
22+
# PASSWORD NOT NULL
23+
if [[ ! -n $MYSQL_PASSWORD ]]; then
24+
echo "Please Set MYSQL_PASSWORD"
25+
exit;
26+
fi
27+
28+
# update db user
29+
read -r -d '' rootCreate <<-EOSQL || true
30+
use mysql;
31+
update user set password=PASSWORD('${MYSQL_PASSWORD}') where User='root';
32+
update user set plugin='mysql_native_password';
33+
EOSQL
34+
35+
# detect mysql init or not
36+
DATA_DIRECTORY=/var/lib/mysql
37+
if [ "`ls -A $DATA_DIRECTORY`" = "" ]; then
38+
# init mysql data
39+
mysql_install_db
40+
fi
41+
42+
# Start Mysql
43+
service mysql start
44+
45+
if [[ ${#MYSQL_HOST} -eq 0 ]];then
46+
echo "Please enter env MYSQL_HOST"
47+
exit;
48+
fi
49+
50+
mysql --host=$MYSQL_HOST --user=$MYSQL_USER -e 'select version();' &> /dev/null;
51+
isMysqlInit=$?
52+
if [[ ${isMysqlInit} -eq 0 ]];then
53+
# mysql is init
54+
mysql --host=$MYSQL_HOST --user=$MYSQL_USER -e "${rootCreate}"
55+
fi
56+
57+
# First: waiting mysql up to do next cmd
58+
# start monitor mysql start up or not every one second
59+
until mysql --host=$MYSQL_HOST --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e 'select version();' &> /dev/null; do
60+
>&2 echo "mysql is unavailable - retry 1s"
61+
sleep 1
62+
done
63+
64+
>&2 echo "mysql is up"
65+
66+
# Second: Create database
67+
mysql --host=$MYSQL_HOST --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e 'Create Database If Not Exists flow_api_db Character Set UTF8;'
68+
mysql --host=$MYSQL_HOST --user=$MYSQL_USER --password=$MYSQL_PASSWORD -e 'Create Database If Not Exists flow_cc_db Character Set UTF8;'
69+
70+
# Third running migration to update table structure
71+
MIGRATION_PATH=./migration
72+
73+
# use flyway control database structure update
74+
echo "running migration"
75+
76+
# run migration to flow_api_db
77+
/flyway/flyway -user=$MYSQL_USER -password=$MYSQL_PASSWORD -ignoreMissingMigrations=true -baselineOnMigrate=true -baselineVersion=1.0 -locations=filesystem:$MIGRATION_PATH/api -url=jdbc:mysql://$MYSQL_HOST:3306/flow_api_db migrate
78+
79+
# run migration to flow_cc_db
80+
/flyway/flyway -user=$MYSQL_USER -password=$MYSQL_PASSWORD -ignoreMissingMigrations=true -baselineOnMigrate=true -baselineVersion=1.0 -locations=filesystem:$MIGRATION_PATH/cc -url=jdbc:mysql://$MYSQL_HOST:3306/flow_cc_db migrate
81+
echo "finish migration"
82+
83+
84+
# Four: everything ready, to run tomcat
85+
exec $cmd

docker/mysqld.cnf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[mysqld]
2+
pid-file = /var/run/mysqld/mysqld.pid
3+
socket = /var/run/mysqld/mysqld.sock
4+
datadir = /var/lib/mysql
5+
log-error = /var/log/mysql/error.log
6+
# Disabling symbolic-links is recommended to prevent assorted security risks
7+
symbolic-links=0
8+
character_set_server=utf8
9+
collation_server=utf8_general_ci
10+
default-time_zone = '+8:00'
11+
max_connections=2000
12+

docker/tomcat-users.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<tomcat-users xmlns="http://tomcat.apache.org/xml"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
21+
version="1.0">
22+
23+
<role rolename="tomcat" />
24+
<role rolename="manager-gui" />
25+
<role rolename="manager-script" />
26+
<role rolename="admin-gui" />
27+
<user username="tomcat" password="tomcat" roles="tomcat,manager-gui,admin-gui,manager-script" />
28+
29+
</tomcat-users>

0 commit comments

Comments
 (0)