Browse Source

Add manual & auto release action (#36)

* feat: update dockerfile

* feat: add docker build action

* feat:add manual release action
master
vran 3 years ago
committed by GitHub
parent
commit
47d642152d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 0
      .github/workflows/auto-checkstyle.yml
  2. 32
      .github/workflows/auto-docker-latest.yml
  3. 55
      .github/workflows/manual-release.yml
  4. 2
      Dockerfile
  5. 20
      README/build.md
  6. 29
      README/deploy.md
  7. 6
      api/src/main/resources/application.properties
  8. 9
      local.Dockerfile

0
.github/workflows/check.yml → .github/workflows/auto-checkstyle.yml

32
.github/workflows/release.yml → .github/workflows/auto-docker-latest.yml

@ -1,12 +1,12 @@
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java#publishing-using-gradle
name: release
name: docker image latest push
on:
push:
tags:
- 'v*'
branches:
- 'master'
jobs:
release:
@ -21,19 +21,25 @@ jobs:
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: add permission to gradle
- name: Gradle Permission Grant
run: chmod +x ./gradlew
- name: build with gradle
- name: Gradle Build
run: ./gradlew api:build -x checkstyleMain -x checkstyleTest
- name: release jar
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
files: api/build/libs/databasir.jar
draft: true
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Image Release
uses: docker/build-push-action@v2
with:
context: .
file: ./local.Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/databasir:latest

55
.github/workflows/manual-release.yml

@ -0,0 +1,55 @@
name: release
on:
workflow_dispatch:
inputs:
tag:
required: true
description: 'release tag version'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Gradle Permission Grant
run: chmod +x ./gradlew
- name: Gradle Build
run: ./gradlew api:build -x checkstyleMain -x checkstyleTest
- name: Application Jar Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
tag_name: ${{ github.event.inputs.tag }}
files: api/build/libs/databasir.jar
draft: true
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker Image Release
uses: docker/build-push-action@v2
with:
context: .
file: ./local.Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/databasir:${{ github.event.inputs.tag }}

2
Dockerfile

@ -11,4 +11,4 @@ EXPOSE 8080
#-Ddatabasir.datasource.username=${databasir.datasource.username}
#-Ddatabasir.datasource.password=${databasir.datasource.password}
#-Ddatabasir.datasource.url=${databasir.datasource.url}
ENTRYPOINT ["sh", "-c","java ${JAVA_OPTS} -jar /app/databasir.jar"]
ENTRYPOINT ["sh", "-c","java -Ddatabasir.db.url=${DATABASIR_DB_URL} -Ddatabasir.db.username=${DATABASIR_DB_USERNAME} -Ddatabasir.db.password=${DATABASIR_DB_PASSWORD} -jar /app/databasir.jar"]

20
README/build.md

@ -7,8 +7,6 @@ Databasir 采用了前后端分离的模式进行开发和部署,项目仓库
- 后端应用: https://github.com/vran-dev/databasir
- 前端应用: https://github.com/vran-dev/databasir-frontend
## 后端
**一、环境要求**
@ -17,22 +15,18 @@ Databasir 采用了前后端分离的模式进行开发和部署,项目仓库
2. Mysql
3. Intellij IDEA
**二、主要框架**
1. Gradle:构建工具
2. Spring-boot:核心框架
1. Web
2. Security
1. Web
2. Security
3. Quartz:定时任务调度
4. JOOQ:ORM 框架
5. Lombok:代码生成
6. Mapstruct:代码生成
7. Flyway:数据库脚本管理
**三、项目结构**
项目结构采用了分层结构
@ -49,8 +43,6 @@ Databasir 采用了前后端分离的模式进行开发和部署,项目仓库
项目数据库脚本放在 dao/src/main/resources/db/migration 目录下
**四、项目启动**
1、通过 Java Main 方法启动
@ -78,8 +70,6 @@ spring.flyway.locations=classpath:db/migration
启动完成后,可以通过 http://localhost:8080 访问
2、通过 Gradle 启动
与 Java 启动模式一样,首先需要准备配置文件
@ -89,14 +79,12 @@ spring.flyway.locations=classpath:db/migration
```properties
server.port=8080
logging.level.org.jooq=INFO
# 必须:数据库配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/databasir
spring.jooq.sql-dialect=mysql
# 可选:flyway 配置
spring.flyway.enabled=true
spring.flyway.baseline-on-migrate=true
@ -111,8 +99,6 @@ spring.flyway.locations=classpath:db/migration
启动完成后,可以通过 http://localhost:8080 访问
## 前端
一、依赖
@ -122,8 +108,6 @@ spring.flyway.locations=classpath:db/migration
3. element-plus
4. axios
二、运行
```shell

29
README/deploy.md

@ -23,14 +23,14 @@ Databasir 采用了前后端分离的模式进行开发和部署,项目仓库
3. 在 Databasir.jar 所在目录创建 config 目录,并在目录下创建 `application.properties` 配置,配置中配置 MYSQL 的用户名、密码和连接
```properties
# 端口号,默认8080
# 端口号,默认 8080
server.port=8080
# 数据库用户名
databasir.datasource.username=root
databasir.db.username=root
# 数据库密码
databasir.datasource.password=123456
databasir.db.password=123456
# 数据库地址
databasir.datasource.url=127.0.0.1:3306
databasir.db.url=127.0.0.1:3306
```
4. 通过 java -jar Databasir.jar 启动应用即可
@ -44,8 +44,6 @@ databasir.datasource.url=127.0.0.1:3306
通过该账号登录应用既可以进行管理
### Docker 部署
目前镜像没有上传到 DockerHub,需要用户自己在本地手动构建
@ -59,13 +57,28 @@ git clone https://github.com/vran-dev/databasir.git
2. 构建镜像
```shell
docker build -t databasir:v1 .
docker build -f Dockerfile -t databasir:v1 .
```
如果你本地有 Java 环境的话我建议通过 gradle 先编译项目再构建镜像,这样会更快
```shell
# 先编译项目
./gradlw api:build
# 再构建镜像
docker build -f local.Dockerfile -t databasir:v1 .
```
3. 启动项目
通过 Docker 启动项目也需要通过环境变量来配置数据库信息
- DATABASIR_DB_URL 数据库地址
- DATABASIR_DB_USERNAME 数据库用户
- DATABASIR_DB_PASSWORD 数据库密码
```shell
docker run -e JAVA_OPTS="-Ddatabasir.datasource.url=127.0.0.1:3306 -Ddatabasir.datasource.username=root -Ddatabasir.datasource.password=123456" -p 8080:8080 -d databasir:v1
docker run --name databasir-demo -e DATABASIR_DB_URL=local_default:3306 -e DATABASIR_DB_USERNAME=root -e DATABASIR_DB_PASSWORD=123456 databasir:v1
```
## Docker Compose 本地部署

6
api/src/main/resources/application.properties

@ -1,9 +1,9 @@
server.port=8080
# datasource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=${databasir.datasource.username}
spring.datasource.password=${databasir.datasource.password}
spring.datasource.url=jdbc:mysql://${databasir.datasource.url}/${databasir.datasource.database-name:databasir}
spring.datasource.username=${databasir.db.username}
spring.datasource.password=${databasir.db.password}
spring.datasource.url=jdbc:mysql://${databasir.db.url}/${databasir.db.name:databasir}
# jooq
spring.jooq.sql-dialect=mysql
# flyway

9
local.Dockerfile

@ -0,0 +1,9 @@
FROM openjdk:11.0.13-jre
WORKDIR /app
ADD api/build/libs/databasir.jar /app/databasir.jar
EXPOSE 8080
#-Ddatabasir.datasource.username=${databasir.datasource.username}
#-Ddatabasir.datasource.password=${databasir.datasource.password}
#-Ddatabasir.datasource.url=${databasir.datasource.url}
ENTRYPOINT ["sh", "-c","java -Ddatabasir.db.url=${DATABASIR_DB_URL} -Ddatabasir.db.username=${DATABASIR_DB_USERNAME} -Ddatabasir.db.password=${DATABASIR_DB_PASSWORD} -jar /app/databasir.jar"]
Loading…
Cancel
Save