Skip to content

Commit

Permalink
refactor: add reusable workflows to build, test and release oceanbase-ce
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe committed Aug 21, 2024
1 parent 1e8e0d3 commit 67cb821
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 269 deletions.
97 changes: 17 additions & 80 deletions .github/workflows/release-lts-oceanbase-ce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,26 @@ env:
tagName: ${{ github.ref_name }}

jobs:
release-lts-oceanbase-ce:
set-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_version_vars.outputs.version }}
steps:
- name: Free disk space on Ubuntu runner
uses: kfir4444/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true

- name: Checkout repository
uses: actions/checkout@v4

- name: Set Version variables
id: set_version_vars
run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*\.\d*-\d{18})' --only-matching)" >> $GITHUB_OUTPUT

- name: Set LTS tag variables
id: set_lts_tag_vars
run: echo "lts_tag=$(echo $tagName | grep -P '(\d*\.\d*\.\d*)' --only-matching)" >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to Quay io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_PASSWORD }}

- name: Log in to Ghcr io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build pre image
uses: docker/build-push-action@v6
with:
context: ./oceanbase-ce
platforms: linux/amd64
file: ./oceanbase-ce/Dockerfile.pre
push: false
load: true
tags: oceanbase-ce-pre
build-args: |
VERSION=${{ steps.set_version_vars.outputs.version }}
- name: Copy storage files
run: |
mkdir -p ./oceanbase-ce/share
docker run -v ./oceanbase-ce/share:/root/share oceanbase-ce-pre
- name: Build and push observer w/o cache
uses: docker/build-push-action@v6
with:
context: ./oceanbase-ce
platforms: linux/amd64,linux/arm64
file: ./oceanbase-ce/Dockerfile
push: true
tags: |
${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:${{ steps.set_version_vars.outputs.version }}
quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${{ steps.set_version_vars.outputs.version }}
ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ steps.set_version_vars.outputs.version }}
${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:${{ steps.set_lts_tag_vars.outputs.lts_tag }}-lts
quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${{ steps.set_lts_tag_vars.outputs.lts_tag }}-lts
ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ steps.set_lts_tag_vars.outputs.lts_tag }}-lts
${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:latest
quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:latest
ghcr.io/${{ github.repository_owner }}/oceanbase-ce:latest
build-args: |
VERSION=${{ steps.set_version_vars.outputs.version }}
build-and-test:
uses: ./.github/workflows/reusable-build-and-test-oceanbase-ce.yml
needs: set-version
with:
cache_key: release-lts-oceanbase-ce
version: ${{ needs.set-version.outputs.version }}

release:
uses: ./.github/workflows/reusable-release-oceanbase-ce.yml
needs: build-and-test
with:
cache_key: release-lts-oceanbase-ce
version: ${{ needs.set-version.outputs.version }}
lts: true
87 changes: 17 additions & 70 deletions .github/workflows/release-oceanbase-ce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,26 @@ env:
tagName: ${{ github.ref_name }}

jobs:
release-oceanbase-ce:
set-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_version_vars.outputs.version }}
steps:
- name: Free disk space on Ubuntu runner
uses: kfir4444/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true

- name: Checkout repository
uses: actions/checkout@v4

- name: Set Version variables
id: set_version_vars
run: echo "version=$(echo $tagName | grep -P '(\d*\.\d*\.\d*\.\d*-\d{18})' --only-matching)" >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to Quay io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_PASSWORD }}

- name: Log in to Ghcr io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build pre image
uses: docker/build-push-action@v6
with:
context: ./oceanbase-ce
platforms: linux/amd64
file: ./oceanbase-ce/Dockerfile.pre
push: false
load: true
tags: oceanbase-ce-pre
build-args: |
VERSION=${{ steps.set_version_vars.outputs.version }}
- name: Copy storage files
run: |
mkdir -p ./oceanbase-ce/share
docker run -v ./oceanbase-ce/share:/root/share oceanbase-ce-pre
- name: Build and push observer w/o cache
uses: docker/build-push-action@v6
with:
context: ./oceanbase-ce
platforms: linux/amd64,linux/arm64
file: ./oceanbase-ce/Dockerfile
push: true
tags: |
${{ vars.DOCKER_PUSH_BASE }}/oceanbase-ce:${{ steps.set_version_vars.outputs.version }}
quay.io/${{ vars.QUAY_IO_PUSH_BASE }}/oceanbase-ce:${{ steps.set_version_vars.outputs.version }}
ghcr.io/${{ github.repository_owner }}/oceanbase-ce:${{ steps.set_version_vars.outputs.version }}
build-args: |
VERSION=${{ steps.set_version_vars.outputs.version }}
build-and-test:
uses: ./.github/workflows/reusable-build-and-test-oceanbase-ce.yml
needs: set-version
with:
cache_key: release-oceanbase-ce
version: ${{ needs.set-version.outputs.version }}

release:
uses: ./.github/workflows/reusable-release-oceanbase-ce.yml
needs: build-and-test
with:
cache_key: release-oceanbase-ce
version: ${{ needs.set-version.outputs.version }}
lts: false
45 changes: 45 additions & 0 deletions .github/workflows/reusable-build-and-test-oceanbase-ce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: build and test oceanbase-ce

on:
workflow_call:
inputs:
cache_key:
required: true
type: string
version:
required: true
type: string

jobs:
build:
uses: ./.github/workflows/reusable-build-oceanbase-ce.yml
with:
cache_key: ${{ inputs.cache_key }}
version: ${{ inputs.version }}

test-slim:
needs: build
uses: ./.github/workflows/reusable-test-oceanbase-ce.yml
with:
cache_key: ${{ inputs.cache_key }}
mode: slim
port: 1234
test_password: 123456
init_sql: "USE test;
CREATE TABLE user(id INT(10) PRIMARY KEY, name VARCHAR(20));
INSERT INTO user VALUES (1, 'tom'), (2, 'jerry');"

test-mini:
needs: build
uses: ./.github/workflows/reusable-test-oceanbase-ce.yml
with:
cache_key: ${{ inputs.cache_key }}
cluster_name: github-action
mode: mini
port: 1234
sys_password: 1234567
test_tenant: mini
test_password: 7654321
init_sql: "USE test;
CREATE TABLE user(id INT(10) PRIMARY KEY, name VARCHAR(20));
INSERT INTO user VALUES (1, 'tom'), (2, 'jerry');"
49 changes: 49 additions & 0 deletions .github/workflows/reusable-build-oblogproxy-ce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: build oblogproxy-ce image

on:
workflow_call:
inputs:
cache_key:
required: true
type: string
version:
required: false
type: string

jobs:
build-oblogproxy-ce-image:
runs-on: ubuntu-latest
steps:
- name: Free disk space on Ubuntu runner
uses: kfir4444/free-disk-space@main
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true

- name: Print environment variables
run: printenv

- name: Check out repository code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build oblogproxy-ce image
run: |
cd oblogproxy-ce
docker buildx build --build-arg VERSION=${{ inputs.version }} --platform linux/amd64 -t oblogproxy-ce-amd64 --load --output type=docker,dest=./oblogproxy-ce-amd64.tar .
docker buildx build --build-arg VERSION=${{ inputs.version }} --platform linux/arm64 -t oblogproxy-ce-arm64 --load --output type=docker,dest=./oblogproxy-ce-arm64.tar .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.cache_key }}
path: oblogproxy-ce/oblogproxy-ce-**.tar
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ on:
cache_key:
required: true
type: string
image_file:
required: true
type: string
version:
required: true
type: string

jobs:
build-oceanbase-ce:
build-oceanbase-ce-image:
runs-on: ubuntu-latest
steps:
- name: Free disk space on Ubuntu runner
Expand Down Expand Up @@ -57,22 +54,13 @@ jobs:
docker run -v ./oceanbase-ce/share:/root/share oceanbase-ce-pre
- name: Build observer image
uses: docker/build-push-action@v6
with:
context: ./oceanbase-ce
platforms: linux/amd64
file: ./oceanbase-ce/Dockerfile
push: false
load: true
tags: oceanbase-ce
build-args: |
VERSION=${{ inputs.version }}
- name: Export Docker image
run: docker save -o ${{ inputs.image_file }} oceanbase-ce
run: |
cd oceanbase-ce
docker buildx build --build-arg VERSION=${{ inputs.version }} --platform linux/amd64 -t oceanbase-ce-amd64 --load --output type=docker,dest=./oceanbase-ce-amd64.tar .
docker buildx build --build-arg VERSION=${{ inputs.version }} --platform linux/arm64 -t oceanbase-ce-arm64 --load --output type=docker,dest=./oceanbase-ce-arm64.tar .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.cache_key }}
path: ${{ inputs.image_file }}
path: oceanbase-ce/oceanbase-ce-**.tar
Loading

0 comments on commit 67cb821

Please sign in to comment.