Skip to content

Commit

Permalink
feat(scaffold): provide build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
taccisum committed Jul 25, 2019
1 parent 31fcc0d commit 6f5c1fd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 27 deletions.
27 changes: 26 additions & 1 deletion generators/app/templates/README.tmpl.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ${artifactId}

## 如何运行
## 如何使用

### 本地开发

Expand All @@ -9,6 +9,31 @@
**swagger地址**http://127.0.0.1:8080/swagger-ui.html
**swagger json**http://127.0.0.1:8080/v2/api-docs

### 构建

#### jar包

```bash
$ mvn clean package -DskipTests
```

#### 镜像

```bash
$ PROJECT_HOME=$PWD \
APP_NAME=${artifactId} \
VERSION=1.0.0 \
sh build.sh
```

或者

```bash
$ PROJECT_HOME=$PWD \
IMAGE_NAME=${artifactId}:v1.0.0 \
sh build.sh
```

### 部署

#### 进程启动
Expand Down
34 changes: 34 additions & 0 deletions generators/app/templates/build.tmpl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

img_mvn="maven:3.3.3-jdk-8" # docker image of maven
m2_cache=~/.m2 # the local maven cache dir

h2 '准备构建项目'

if which mvn ; then
info '使用本地maven构建项目'
mvn clean package -DskipTests
else
info '使用maven镜像['$img_mvn']构建项目'
docker run --rm \
-v $m2_cache:/root/.m2 \
-v $PROJECT_HOME:/usr/src/mymaven \
-w /usr/src/mymaven \
$img_mvn mvn clean package -DskipTests
fi
if [ $? -eq 0 ];then
success '项目构建成功'
else
error '项目构建失败'
exit 1
fi

h2 '准备构建Docker镜像'

sudo mv $PROJECT_HOME/$APP_NAME-provider/target/$APP_NAME-*.jar $PROJECT_HOME/$APP_NAME-provider/target/app.jar

if [ -z $IMAGE_NAME ];then
docker build --rm -t $IMAGE_NAME .
else
docker build --rm -t $APP_NAME:v$VERSION .
fi
33 changes: 7 additions & 26 deletions generators/app/templates/start-code.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,21 @@ done

#----------------- 启动逻辑 start -----------------#
project_name='${artifactId}'
version='1.0.0'

img_mvn="maven:3.3.3-jdk-8" # docker image of maven
m2_cache=~/.m2 # the local maven cache dir
proj_home=$PWD # the project root dir
img_output=$project_name # output image tag
img_output=$project_name:v$version # output image tag
container_name=$img_output # container name

h1 '准备启动应用'$project_name'(基于Docker)'

if [ ! -z $build ];then
h2 '准备构建项目'
PROJECT_HOME=$proj_home \
IMAGE_NAME=$img_output \
APP_NAME=$project_name \
VERSION=$version \
sh build.sh

if which mvn ; then
info '使用本地maven构建项目'
mvn clean package -DskipTests
else
info '使用maven镜像['$img_mvn']构建项目'
docker run --rm \
-v $m2_cache:/root/.m2 \
-v $proj_home:/usr/src/mymaven \
-w /usr/src/mymaven \
$img_mvn mvn clean package -DskipTests
fi
if [ $? -eq 0 ];then
success '项目构建成功'
else
error '项目构建失败'
exit 1
fi

h2 '准备构建Docker镜像'

sudo mv $proj_home/$project_name-provider/target/$project_name-*.jar $proj_home/$project_name-provider/target/app.jar
docker build --rm -t $img_output .
if [ $? -eq 0 ];then
success '镜像构建成功'
else
Expand Down

0 comments on commit 6f5c1fd

Please sign in to comment.