Skip to content

feat: resources monitor, metering controller, billing controller, bil… #4

feat: resources monitor, metering controller, billing controller, bil…

feat: resources monitor, metering controller, billing controller, bil… #4

Workflow file for this run

name: Build Controllers image
on:
workflow_call:
inputs:
release:
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
push_image:
description: "Push images"
required: false
type: boolean
default: false
release_tag:
description: "Release images"
default: "dev"
required: false
type: string
push:
branches: ["main"]
paths:
- "controllers/**"
- ".github/workflows/controllers.yml"
- "!**/*.md"
- "!**/*.yaml"
pull_request:
branches: ["*"]
paths:
- "controllers/**"
- ".github/workflows/controllers.yml"
- "!**/*.md"
- "!**/*.yaml"
env:
# Common versions
GO_VERSION: "1.20"
DEFAULT_OWNER: "labring"
jobs:
resolve-modules:
runs-on: ubuntu-20.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Resolve Modules
id: set-matrix
run: bash ./scripts/resolve-modules.sh ./controllers
golangci-lint:
needs: [resolve-modules]
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Dependencies
run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Run Linter
uses: golangci/golangci-lint-action@v3
with:
version: latest
working-directory: ${{ matrix.workdir }}
args: "--out-${NO_FUTURE}format colored-line-number"
image-build:
runs-on: ubuntu-latest
strategy:
matrix:
module:
- { name: user, path: user }
- { name: terminal, path: terminal }
- { name: metering, path: metering }
- { name: infra, path: infra }
- { name: cluster, path: cluster }
- { name: imagehub, path: imagehub }
- { name: account, path: account }
- { name: app, path: app }
- { name: db-bytebase, path: db/bytebase }
- { name: db-adminer, path: db/adminer }
- { name: resources, path: resources }
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Dependencies
run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Build ${{ matrix.module.name }} amd64
working-directory: controllers/${{ matrix.module.path }}
run: |
GOARCH=amd64 make build
mv bin/manager bin/controller-${{ matrix.module.name }}-amd64
chmod +x bin/controller-${{ matrix.module.name }}-amd64
- name: Build ${{ matrix.module.name }} arm64
working-directory: controllers/${{ matrix.module.path }}
run: |
GOARCH=arm64 make build
mv bin/manager bin/controller-${{ matrix.module.name }}-arm64
chmod +x bin/controller-${{ matrix.module.name }}-arm64
- name: Expose git commit data
uses: rlespinasse/git-commit-data-action@v1
- name: Prepare
id: prepare
run: |
bash ./scripts/resolve-tag-image.sh "${{ inputs.push_image }}" "${{ inputs.release }}" "${{ inputs.release_tag }}"
echo docker_repo=ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module.name }}-controller >> $GITHUB_OUTPUT
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Login to Docker Hub
uses: docker/login-action@v2
if: ${{ (github.event_name == 'push') || (inputs.push_image == true) || (inputs.release == true) }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module.name }}-controller
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=dev,enable=true
type=raw,value=${{ steps.prepare.outputs.tag_name }},enable=true
- name: build (and publish) ${{ matrix.module.name }} main image
uses: docker/build-push-action@v4
with:
context: ./controllers/${{ matrix.module.path }}
file: ./controllers/${{ matrix.module.path }}/Dockerfile
# Push if it's a push event or if push_image is true
push: ${{ (github.event_name == 'push') || (inputs.push_image == true) || (inputs.release == true) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
save-sealos:
uses: ./.github/workflows/import-save-sealos.yml
build-cluster-image:
if: ${{ (github.event_name == 'push') || (inputs.push_image == true) || (inputs.release == true) }}
needs:
- image-build
- save-sealos
runs-on: ubuntu-latest
strategy:
matrix:
module:
- { name: user, path: user }
- { name: terminal, path: terminal }
- { name: metering, path: metering }
- { name: infra, path: infra }
- { name: cluster, path: cluster }
- { name: imagehub, path: imagehub }
- { name: account, path: account }
- { name: app, path: app }
- { name: db-bytebase, path: db/bytebase }
- { name: db-adminer, path: db/adminer }
- { name: resources, path: resources }
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Expose git commit data
uses: rlespinasse/git-commit-data-action@v1
- name: Prepare
id: prepare
run: |
bash ./scripts/resolve-tag-image.sh "${{ inputs.push_image }}" "${{ inputs.release }}" "${{ inputs.release_tag }}"
echo old_docker_repo=ghcr.io/labring/sealos-${{ matrix.module.name }}-controller >> $GITHUB_OUTPUT
echo new_docker_repo=ghcr.io/${{ github.repository_owner }}/sealos-${{ matrix.module.name }}-controller >> $GITHUB_OUTPUT
echo cluster_repo=ghcr.io/${{ github.repository_owner }}/sealos-cloud-${{ matrix.module.name }}-controller >> $GITHUB_OUTPUT
- name: Download sealos
uses: actions/download-artifact@v3
with:
name: sealos
path: /tmp/
- name: Verify sealos
run: |
sudo chmod a+x /tmp/sealos
sudo mv /tmp/sealos /usr/bin/sealos
sudo sealos version
- name: Mutate image tag in deploy files
working-directory: controllers/${{ matrix.module.path }}/deploy
run: |
OLD_DOCKER_IMAGE_NAME=${{ steps.prepare.outputs.old_docker_repo }}:dev
NEW_DOCKER_IMAGE_NAME=${{ steps.prepare.outputs.new_docker_repo }}:${{ steps.prepare.outputs.tag_name }}
sudo sed -i "s;${OLD_DOCKER_IMAGE_NAME};${NEW_DOCKER_IMAGE_NAME};" manifests/*
- name: Sealos login to ghcr.io
# if push to master, then login to ghcr.io
run: |
sudo sealos login -u ${{ github.repository_owner }} -p ${{ secrets.GH_PAT }} --debug ghcr.io
- name: Build ${{ matrix.module.name }}-controller cluster image
working-directory: controllers/${{ matrix.module.path }}/deploy
run: |
CLUSTER_IMAGE_NAME=${{ steps.prepare.outputs.cluster_repo }}:${{ steps.prepare.outputs.tag_name }}
sudo sealos build -t ${CLUSTER_IMAGE_NAME}-amd64 --platform linux/amd64 -f Kubefile
# delete old registry cache
sudo rm -rf registry
sudo sealos build -t ${CLUSTER_IMAGE_NAME}-arm64 --platform linux/arm64 -f Kubefile
- name: Manifest Cluster Images
# if push to master, then patch images to ghcr.io
run: |
CLUSTER_IMAGE_NAME=${{ steps.prepare.outputs.cluster_repo }}:${{ steps.prepare.outputs.tag_name }}
sudo sealos images
bash docker/patch/manifest-cluster-images.sh $CLUSTER_IMAGE_NAME
env:
OWNER: ${{ github.repository_owner }}
- name: Sync Images
uses: peter-evans/create-or-update-comment@v1
if: ${{ github.repository_owner == env.DEFAULT_OWNER }}
with:
issue-number: 251
repository: labring-actions/cluster-image
body: |
/imagesync ghcr.io/${{ github.repository_owner }}/sealos-cloud-${{ matrix.module.name }}-controller:${{ steps.prepare.outputs.tag_name }}
token: "${{ secrets.GH_PAT }}"