Skip to content

Commit

Permalink
refactor: modify project structure and add github workflow (#25)
Browse files Browse the repository at this point in the history
* modify project structure and add github workflow for java example

* modify group name

* move yml to workflows dir

* fix image name

* update java example

* update java docs

* update golang example

* modify example file name

* remove assert

* update python example

* update ci config

* remove branch filter

* update readme
  • Loading branch information
whhe authored Apr 3, 2024
1 parent 977c03a commit 4396ca3
Show file tree
Hide file tree
Showing 62 changed files with 431 additions and 580 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI
on:
push:
paths-ignore:
- 'docs/**'
- '**.md'
- '.*'
pull_request:
paths-ignore:
- 'docs/**'
- '**.md'
- '.*'
concurrency:
group: ${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
golang:
runs-on: ubuntu-latest
strategy:
matrix:
module: [ "go-sql-driver" ]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Set Go env
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Start docker container
timeout-minutes: 5
run: |
docker run --name oceanbase-ce --network host -e MODE=slim -e FASTBOOT=true -d oceanbase/oceanbase-ce
eval 'while ! docker logs oceanbase-ce | grep -q "boot success!"; do echo "booting..."; sleep 10; done'
echo "boot success!"
- name: Run example for ${{ matrix.module }}
run: |
cd ob-example-golang/${{ matrix.module }}
sh run.sh
java:
runs-on: ubuntu-latest
strategy:
matrix:
module: [ "mysql-connector-java", "oceanbase-client" ]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Set JDK
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'zulu'
cache: 'maven'
- name: Start docker container
timeout-minutes: 5
run: |
docker run --name oceanbase-ce --network host -e MODE=slim -e FASTBOOT=true -d oceanbase/oceanbase-ce
eval 'while ! docker logs oceanbase-ce | grep -q "boot success!"; do echo "booting..."; sleep 10; done'
echo "boot success!"
- name: Run example for ${{ matrix.module }}
run: |
cd ob-example-java/${{ matrix.module }}
sh run.sh
python:
runs-on: ubuntu-latest
strategy:
matrix:
module: [ "pymysql" ]
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Start docker container
timeout-minutes: 5
run: |
docker run --name oceanbase-ce --network host -e MODE=slim -e FASTBOOT=true -d oceanbase/oceanbase-ce
eval 'while ! docker logs oceanbase-ce | grep -q "boot success!"; do echo "booting..."; sleep 10; done'
echo "boot success!"
- name: Run example for ${{ matrix.module }}
run: |
cd ob-example-python/${{ matrix.module }}
sh run.sh
12 changes: 0 additions & 12 deletions .gitpod.yml

This file was deleted.

64 changes: 5 additions & 59 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,22 @@

## 介绍

本仓库提供了 OceanBase 的示例项目。 它包含以下目录:
本仓库提供了 OceanBase 的示例项目,按照编程语言进行分组,每个分组下面有一个或多个工具的使用示例,示例目录以工具名称命名。

- [`examples`](examples):该目录包含所有示例项目。
- [`tests`](tests):该目录包含用于测试的资源。
- [`tools`](tools):该目录包含脚本和其他工具。

### 示例项目

示例项目按照如下类型进行分类:

- [`application`](application): 应用程序框架如网络服务框架。
- [`connection-pool`](connection-pool): 数据库连接池。
- [`data-integration`](data-integration): 数据集成框架。
- [`driver`](driver): 数据库驱动。
- [`middleware`](middleware): 中间件。
- [`orm`](orm): ORM(对象关系映射)框架。

在这些类型目录下,项目文件夹一般以 `{编程语言}-{组件名称}` 的格式命名。 目前,本仓库包含以下组件的示例:

#### [数据库驱动](examples/driver)

- (golang) [go-sql-driver](examples/driver/golang-go-sql-driver)
- (java) [mysql-connector-java](examples/driver/java-mysql-connector-java)
- (java) [oceanbase-client](examples/driver/java-oceanbase-client)
- (python3) [pymysql](examples/driver/python3-pymysql)

## 快速开始

本仓库基于 Gitpod 建立了快速在线体验平台, 点击下面按钮一键体验(建议使用 Chrome 浏览器)

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/oceanbase/ob-example)

需要注意的是,创建 Gitpod 工作区时需要选择大规格,否则可能会因为磁盘空间不足而部署失败。

打开新创建的 Gitpod 工作区后,Gitpod 会自动部署一个 OceanBase 本地实例,请耐心等待,直到终端界面显示如下表示部署成功的信息,之后您就可以在工作区使用该 OceanBase 实例了。

![Boot Success](tools/gitpod/boot.png)

### 体验示例项目

您可以按下面步骤进行操作,在 Gitpod 上体验示例项目:

```bash
// 进入目录
cd xxxx
// 执行示例代码
sh run.sh
```

这里以 python3-pymysql 为例,注意 Gitpod 环境的工作空间默认为 `/workspace/ob-example`

```bash
cd /workspace/ob-example/examples/driver/python3-pymysql
sh run.sh
```
本仓库使用 [oceanbase-ce](https://hub.docker.com/r/oceanbase/oceanbase-ce) 镜像在 GitHub 工作流中启动 OceanBase 数据库实例进行持续集成,用户也可以将所需工具对应的示例代码复制到本地,修改其中的连接信息后进行使用。

## 贡献

我们欢迎任何人来贡献,感谢所有的[贡献者](https://github.com/oceanbase/ob-example/graphs/contributors)

在这个仓库中,同类型的示例项目放在同一个目录下,项目目录的命名格式为 `{编程语言}-{组件名称}`

在您提交 Pull Request 前,我们建议您先在 Gitpod 上创建一个 [workspace](https://gitpod.io/workspaces/),以对您的 fork 分支进行测试和验证。
如果您想增加 OceanBase 的使用示例,请确保将新增的示例代码放置在对应的编程语言目录下,并以工具名称命名该新增模块。

最终,在新增的目录中,应当至少包含以下几个文件:
在一个示例中,请确保包含以下内容

- 代码文件
- `run.sh` 运行代码的脚本
- `README.md` 组件用法的介绍文档

## 参考信息

关于更多 OceanBase 的细节请参考 [社区官网](https://open.oceanbase.com).
关于更多 OceanBase 的细节请参考 [社区官网](https://open.oceanbase.com)
62 changes: 4 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,17 @@ English | [简体中文](README-CN.md)

## Introduction

This repository provides the example projects for OceanBase. It contains the following directories:
This repository provides the example projects for OceanBase, which are grouped by programming language. The example directory is named after the component name.

- [`examples`](examples): the directory contains all the example projects.
- [`tests`](tests): the directory contains resources for testing.
- [`tools`](tools): the directory contains scripts and other tools.

### Examples

The example projects for OceanBase are classified by type as below:

- [`application`](examples/application): example projects for application frameworks such as the web service frameworks.
- [`connection-pool`](examples/connection-pool): example projects for connection pool tools.
- [`data-integration`](examples/data-integration): example projects for data integration tools.
- [`driver`](examples/driver): example projects for database drivers.
- [`middleware`](examples/middleware): example projects for middlewares.
- [`orm`](examples/orm): example projects for ORM (Object Relational Mapping) frameworks.

The project directories under these types are named in format `{programming language}-{component name}`. For now, the repository contains examples for the following components:

#### [Driver](examples/driver)

- (golang) [go-sql-driver](examples/driver/golang-go-sql-driver)
- (java) [mysql-connector-java](examples/driver/java-mysql-connector-java)
- (java) [oceanbase-client](examples/driver/java-oceanbase-client)
- (python3) [pymysql](examples/driver/python3-pymysql)

## Quick Start

This repo builds an online platform for fast use based on Gitpod, click the following button to have a try.

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/oceanbase/ob-example)

Note that it is necessary to choose a large-class workspace for OceanBase, otherwise the database may fail to deploy due to insufficient disk space.

Open the newly created workspace, Gitpod will Automatically deploy a standalone OceanBase server. Please wait until the following information about successful deployment appears on the terminal, after that you can try it with our examples.

![Boot Success](tools/gitpod/boot.png)

### Try with Example Code

You can try the example on Gitpod following the steps below:

```bash
// enter the working directory
cd xxxx
// execute the sample code
sh run.sh
```

Here we use python3-pymysql as an example, note that the workspace in Gitpod is set to `/workspace/ob-example`:

```bash
cd /workspace/ob-example/examples/driver/python3-pymysql
sh run.sh
```
This repository uses the [oceanbase-ce](https://hub.docker.com/r/oceanbase/oceanbase-ce) image to start the OceanBase database instance in the GitHub workflow for continuous integration. Users can also copy the example code to local environment and use it after changing the connection info.

## Contribution

We welcome contributions from anyone, thanks to all [contributors](https://github.com/oceanbase/ob-example/graphs/contributors)!

In this repository, the example projects in the same type are placed in the same directory, and the project directories are named in format `{programming language}-{component name}`.

Before you submit a Pull Request, we recommend that you first create a [workspace](https://gitpod.io/workspaces) on Gitpod to test and verify your fork branch.
If you want to add a new module, please make sure to place it in the directory of corresponding programming language and name it after the component name.

Finally, in the newly added directory, there should be at least the following files:
In the module, make sure to include the following files:

- code files
- `run.sh` script to run code
Expand Down
3 changes: 0 additions & 3 deletions examples/driver/golang-go-sql-driver/run.sh

This file was deleted.

83 changes: 0 additions & 83 deletions examples/driver/java-mysql-connector-java/README-CN.md

This file was deleted.

Loading

0 comments on commit 4396ca3

Please sign in to comment.