Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.5-arm merge to dev #3

Merged
merged 3 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Dockerfile.release
Dockerfile.release
.DS_Store
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM rainbond/cedar14
MAINTAINER ethan <ethan@goodrain.me>
FROM rainbond/cedar14:20211224
LABEL MAINTAINER ="guox <guox@goodrain.com>"

RUN echo "Asia/Shanghai" > /etc/timezone;dpkg-reconfigure -f noninteractive tzdata
ENV TZ=Asia/Shanghai

RUN set -x \
&& apt-get update \
&& apt-get -y install language-pack-zh-hans \
&& apt-get install --no-install-recommends --no-install-suggests -y ttf-dejavu apt-transport-https ca-certificates procps curl net-tools rsync \
&& apt-get install --no-install-recommends --no-install-suggests -y ttf-dejavu apt-transport-https ca-certificates procps net-tools rsync \
&& rm -rf /var/lib/apt/lists/*

ENV HOME /app
Expand Down Expand Up @@ -35,7 +34,7 @@ RUN chown rain:rain /runner/init

## install libpng16 for ubuntu14.04

RUN wget https://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.xz \
RUN wget --no-check-certificate https://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.xz \
&& tar -xf libpng-1.6.37.tar.xz \
&& cd libpng-1.6.37 && ./configure && make check && make install && ldconfig \
&& cd ../ && rm -rf libpng-1.6.37.tar.xz && rm -rf libpng-1.6.37
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
通过标准输入,文件挂载或者URL的形式将 压缩后 的应用程序(代码,运行时)传入到Runner镜像并运行。镜像的入口文件会读取Procfile中的内容并运行。

## 如何使用 Runner
云帮安装后该镜像自动在计算节点拉取,不需要人工干预。下面主要介绍手动通过runner镜像运行builder生成的压缩包的场景。
Rainbond 安装后该镜像自动在计算节点拉取,不需要人工干预。下面主要介绍手动通过runner镜像运行builder生成的压缩包的场景。


可以通过标准输入将压缩包载入到runner镜像,并运行:
- 可以通过标准输入将压缩包载入到runner镜像,并运行:

```bash
$ cat myslug.tgz | docker run -i -a stdin -a stdout goodrain.me/runner
```

- 可以通过挂载 slug 包的方式运行:

```bash
$ docker run -dti --name=runner \
-v path/to/myslug.tgz:/tmp/slug/slug.tgz \
-p 5000:5000 \
goodrain.me/runner
```

压缩包的内容会在runner容器启动后解压到 `/app` 目录,在正式启动应用程序之前,会先导入代码目录下 `.profile.d` 中的文件,这里会有应用程序所需要的环境变量。

最终,runner镜像的引导程序会读取代码目录下的`Procfile`文件,并启动应用程序。如果用户代码根目录中没有该文件,在builer构建时会根据用户在创建应用向导中的选择自动生成。
2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -xe

release_version=v5.3.3
release_version=v5.5.0
git_commit=$(git log -n 1 --pretty --format=%h)

release_desc=${release_version}-${git_commit}
Expand Down
13 changes: 11 additions & 2 deletions runner/init
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ cd $HOME
shopt -s nullglob
mkdir -p .profile.d


if [[ -s .release ]]; then
#True if FILE exists and has a size greater than zero.
if [[ -s .release ]]; then
ruby -e "require 'yaml';(YAML.load_file('.release')['config_vars'] || {}).each{|k,v| puts \"#{k}='#{v}'\"}" > .profile.d/config_vars
fi

Expand All @@ -63,6 +63,15 @@ for file in .profile.d/*; do
done
hash -r

# 导入库

source /runner/lib/common.sh
source /runner/lib/sqlvercontrol.sh

# 处理数据库表结构升级

detectSqlControl

## Inject "start" command to run processes defined in Procfile

case "$action" in
Expand Down
17 changes: 17 additions & 0 deletions runner/lib/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# make stdout colorful
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
NC='\033[0m' # No Color
info() {
echo -e "${GREEN} $@${NC}"
}

warn() {
echo -e "${YELLOW} !! $@${NC}"
}

err() {
echo -e >&2 "${RED} !! $@${NC}"
}
50 changes: 50 additions & 0 deletions runner/lib/sqlvercontrol.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#!/bin/bash
# 利用 Liquibase 进行数据库表结构的管理
# 通过检测源码目录下指定文件夹下的 changelog 文件,来决定是否准备 Liquibase 环境
# Liquibase 的运行需要 java 环境支持,指定的 connector jar 包
# 目前仅支持 Mysql 类型数据库的对接

function detectSqlControl() {
CHANGE_LOG_FILE=${CHANGE_LOG_FILE:-"rainsql/changelog.sql"}
if [ -f $HOME/${CHANGE_LOG_FILE} ]; then
info "Database version control file ${CHANGE_LOG_FILE} has been found..."
dealWithConfig
runLiquiCmd || return 0
fi
}

function dealWithConfig() {
# Checks whether a configuration file exists named liquibase.properties
# Render the template configuration file using environment variables
# Currently, only mysql is supported
LIQUIBASE_CONFIG_FILE=${LIQUIBASE_CONFIG_FILE:-"rainsql/liquibase.properties"}
if ! grep "__MYSQL_HOST__" $HOME/${LIQUIBASE_CONFIG_FILE} >/dev/null; then
info "Useing custom liquibase config file ${LIQUIBASE_CONFIG_FILE}"
elif [ ! -z $MYSQL_USER ] && [ ! -z $MYSQL_PASSWORD ] && [ ! -z $MYSQL_DATABASE ]; then
info "Rendering ${LIQUIBASE_CONFIG_FILE} using environment variables"
sed -i -e "s/__MYSQL_HOST__/${MYSQL_HOST:-127.0.0.1}/g" \
-e "s/__MYSQL_PORT__/${MYSQL_PORT:-3306}/g" \
-e "s/__MYSQL_USER__/${MYSQL_USER:-root}/g" \
-e "s/__MYSQL_PASSWORD__/${MYSQL_PASSWORD:-""}/g" \
-e "s/__MYSQL_DATABASE__/${MYSQL_DATABASE}/g" \
-e "s/changelog.sql/${CHANGE_LOG_FILE#*/}/g" ${LIQUIBASE_CONFIG_FILE}
else
warn "Whether appropriate mysql connection environment variables have been defined?"
warn "Declare \$MYSQL_USER \$MYSQL_PASSWORD \$MYSQL_HOST \$MYSQL_PORT \$MYSQL_DATABASE please."
fi
}

function runLiquiCmd() {
# Checks change sets before update
# If there is no Changeset to be executed, do not update
LIQUIBASE_TEMP_FILE=${LIQUIBASE_TEMP_FILE:-"rainsql/cmd.log"}
# run liquibase status, log to temp file
pushd ${CHANGE_LOG_FILE%/*}
liquibase status &>$HOME/${LIQUIBASE_TEMP_FILE}
grep "change sets have not been applied to" $HOME/${LIQUIBASE_TEMP_FILE} >/dev/null &&
info "Updating change sets to db..." &&
liquibase update &>$HOME/${LIQUIBASE_TEMP_FILE}
[[ $? == 0 ]] && info "Updated successfully!"
popd
}