Skip to content

Commit

Permalink
Merge pull request #17 from MetrodataTeam/releases/v1
Browse files Browse the repository at this point in the history
增加actions
  • Loading branch information
hexiong0802 authored Mar 20, 2024
2 parents 1849f26 + f7490de commit 251d4d3
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 0 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Docker Build CI

on:
workflow_call:
inputs:
BASE_IMAGE:
required: true
type: string
MDTDB_VERSION:
required: true
type: string
PG_HINT_PLAN_VERSION:
required: true
type: string
PGAUDIT_VERSION:
required: true
type: string
VERSION_PREFIX:
required: true
type: string
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
NEXUS:
required: true
env:
REGISTRY_IMAGE: metrodatatech/mdtdb

jobs:
build:
#environment: test
#if: github.event.review.state == 'APPROVED'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
# - linux/arm/v6
# - linux/arm/v7
- linux/arm64
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
if [[ ${{ matrix.platform }} == "linux/arm64" ]]; then
echo "IS_ARM=true" >> $GITHUB_ENV
else
echo "IS_ARM=false" >> $GITHUB_ENV
fi
-
name: Checkout
uses: actions/checkout@v4
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: ./postgres/public/
#file: ./postgres/public/Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
build-args: |
BASE_IMAGE=${{ inputs.BASE_IMAGE }}
MDTDB_VERSION=${{ inputs.MDTDB_VERSION }}
IS_ARM=${{ env.IS_ARM }}
PG_HINT_PLAN_VERSION=${{ inputs.PG_HINT_PLAN_VERSION }}
PGAUDIT_VERSION=${{ inputs.PGAUDIT_VERSION }}
NEXUS=${{ secrets.NEXUS }}
-
name: Export digest
run: |
mkdir -p /tmp/digests${{inputs.VERSION_PREFIX}}
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests${{inputs.VERSION_PREFIX}}/${digest#sha256:}"
-
name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{inputs.VERSION_PREFIX}}-${{ env.PLATFORM_PAIR }}
path: /tmp/digests${{inputs.VERSION_PREFIX}}/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
-
name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests${{inputs.VERSION_PREFIX}}
pattern: digests-${{inputs.VERSION_PREFIX}}-*
merge-multiple: true
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Create manifest list and push
working-directory: /tmp/digests${{inputs.VERSION_PREFIX}}
run: |
VERSION=${{inputs.VERSION_PREFIX}}.${{ inputs.MDTDB_VERSION }}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
docker buildx imagetools create $(jq -cr --arg version "$VERSION" '.tags | map((split(":")[0] + ":\($version)-" + split(":")[1])) | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
-
name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{env.VERSION}}-${{ steps.meta.outputs.version }}
64 changes: 64 additions & 0 deletions .github/workflows/trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Call a reusable workflow

on:
workflow_dispatch:
push:
branches:
- 'master'
- 'releases/**'
tags:
- 'v*'


jobs:
call-workflow-16:
uses: ./.github/workflows/docker-build.yml
with:
BASE_IMAGE: postgres:16.2
MDTDB_VERSION: "18.4"
PG_HINT_PLAN_VERSION: REL16_1_6_0
PGAUDIT_VERSION: "16.0"
VERSION_PREFIX: "16"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
NEXUS: ${{ secrets.NEXUS }}

call-workflow-15:
uses: ./.github/workflows/docker-build.yml
with:
BASE_IMAGE: postgres:15.6
MDTDB_VERSION: "18.4"
PG_HINT_PLAN_VERSION: REL15_1_5_1
PGAUDIT_VERSION: "1.7.0"
VERSION_PREFIX: "15"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
NEXUS: ${{ secrets.NEXUS }}

call-workflow-14:
uses: ./.github/workflows/docker-build.yml
with:
BASE_IMAGE: postgres:14.11
MDTDB_VERSION: "18.4"
PG_HINT_PLAN_VERSION: REL14_1_4_2
PGAUDIT_VERSION: "1.6.2"
VERSION_PREFIX: "14"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
NEXUS: ${{ secrets.NEXUS }}

call-workflow-13:
uses: ./.github/workflows/docker-build.yml
with:
BASE_IMAGE: postgres:13.14
MDTDB_VERSION: "18.4"
PG_HINT_PLAN_VERSION: REL13_1_3_9
PGAUDIT_VERSION: "1.5.2"
VERSION_PREFIX: "13"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
NEXUS: ${{ secrets.NEXUS }}

0 comments on commit 251d4d3

Please sign in to comment.