Skip to content

Commit

Permalink
chore(build): update github workflows to build images for pr events (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Nov 22, 2023
1 parent 2046b4b commit 4a0e4b4
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 98 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-sealos-cluster-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ jobs:
SEALOS_ISSUE_REPO: "labring-actions/cluster-image"
SEALOS_COMMENT_BODY: "/imagesync ghcr.io/${{ github.repository_owner }}/${{ env.image }}:${{ env.tag }}"

trigger-workflow-e2e:
needs: [build_cluster_image]
runs-on: ubuntu-latest
steps:
- name: trigger cluster image workflow
uses: peter-evans/repository-dispatch@v2
with:
event-type: cluster_image_build_success
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}'
# trigger-workflow-e2e:
# needs: [build_cluster_image]
# runs-on: ubuntu-latest
# steps:
# - name: trigger cluster image workflow
# uses: peter-evans/repository-dispatch@v2
# with:
# event-type: cluster_image_build_success
# client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}'
6 changes: 3 additions & 3 deletions .github/workflows/doc-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name: Laf Doc Preview
# todo: When the requirements are mature enough, refactor using TypeScript, create a generic GitHub Action, and make it available to users.

on:
pull_request:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened, closed]
paths:
- "docs/**"
- ".github/workflows/doc-preview.yml"

permissions:
pull-requests: write
# permissions:
# pull-requests: write

env:
LAF_CI_DOCS_PREVIEW_PAT: ${{ secrets.LAF_CI_DOCS_PREVIEW_PAT }}
Expand Down
32 changes: 29 additions & 3 deletions .github/workflows/dockerize-runtime-exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: dockerize-runtime-exporter

on:
workflow_dispatch:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened]
paths:
- "services/runtime-exporter/**"
- ".github/workflows/dockerize-runtime-exporter.yml"
- "!**/*.md"
- "!services/runtime-exporter/package-lock.json"
push:
branches:
- main
Expand All @@ -10,7 +18,11 @@ on:
- ".github/workflows/dockerize-runtime-exporter.yml"
- "!**/*.md"
- "!services/runtime-exporter/package-lock.json"

# permissions:
# pull-requests: write
# packages: write
# contents: read

concurrency:
group: dockerize-runtime-exporter-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -33,8 +45,10 @@ jobs:
docker.io/${{ secrets.DOCKER_USERNAME }}/runtime-exporter
# https://github.com/docker/metadata-action#typesemver
tags: |
type=raw,value=latest,enable=true
type=sha,enable=true,format=short
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=sha,format=short,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value={{branch}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') && !startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -65,9 +79,21 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64

- name: Comment docker image tags to PR
if: github.event_name == 'pull_request'
uses: mshick/add-pr-comment@v2
with:
message-id: 'dockerize-runtime-exporter'
message: |
**:boom: laf runtime exporter image built successfully for pr ${{ github.event.pull_request.number }}**
```
${{ steps.meta.outputs.tags }}
```
trigger-workflow-build-cluster-image:
needs: [dockerize-runtime-exporter]
runs-on: ubuntu-latest
if: github.ref == format('refs/heads/{0}', 'main')
steps:
- name: trigger cluster image workflow
uses: peter-evans/repository-dispatch@v2
Expand Down
116 changes: 39 additions & 77 deletions .github/workflows/dockerize-runtime-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ name: dockerize-runtime-nodejs

on:
workflow_dispatch:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened]
paths:
- "runtimes/nodejs/**"
- ".github/workflows/dockerize-runtime-nodejs.yml"
- "!**/*.md"
- "!runtimes/nodejs/package-lock.json"
push:
tags:
- v*.*.*
branches:
- main
branches: [main]
paths:
- "runtimes/nodejs/**"
- ".github/workflows/dockerize-runtime-nodejs.yml"
- "!**/*.md"
- "!runtimes/nodejs/package-lock.json"

# permissions:
# pull-requests: write
# packages: write
# contents: read

concurrency:
group: dockerize-runtime-nodejs-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -29,7 +41,7 @@ jobs:
- name: Use Node
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x

- name: Install Package
working-directory: runtimes/nodejs
Expand All @@ -49,8 +61,10 @@ jobs:
# https://github.com/docker/metadata-action#typesemver
tags: |
type=semver,pattern={{version}}
type=raw,value=latest,enable=true
type=sha,enable=true,format=short
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=sha,format=short,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value={{branch}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') && !startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -81,76 +95,24 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64

dockerize-init-image:
needs: [dockerize-main-image]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Package
working-directory: runtimes/nodejs
run: npm cache clean --force && npm install

- name: Build Packages
working-directory: runtimes/nodejs
run: npm run build

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository_owner }}/runtime-node-init
docker.io/${{ secrets.DOCKER_USERNAME }}/runtime-node-init
# https://github.com/docker/metadata-action#typesemver
tags: |
type=semver,pattern={{version}}
type=raw,value=latest,enable=true
type=sha,enable=true,format=short
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to Github Container Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: ./runtimes/nodejs
file: ./runtimes/nodejs/Dockerfile.init
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64

trigger-workflow-e2e:
needs: [dockerize-main-image, dockerize-init-image]
runs-on: ubuntu-latest
steps:
- name: trigger cluster image workflow
uses: peter-evans/repository-dispatch@v2
- name: Comment docker image tags to PR
if: github.event_name == 'pull_request'
uses: mshick/add-pr-comment@v2
with:
event-type: dockerize-runtime-success
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}'
message-id: 'dockerize-runtime-nodejs'
message: |
**:boom: laf nodejs runtime image built successfully for pr ${{ github.event.pull_request.number }}**
```
${{ steps.meta.outputs.tags }}
```
# trigger-workflow-e2e:
# needs: [dockerize-main-image]
# runs-on: ubuntu-latest
# steps:
# - name: trigger cluster image workflow
# uses: peter-evans/repository-dispatch@v2
# with:
# event-type: dockerize-runtime-success
# client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}'
34 changes: 30 additions & 4 deletions .github/workflows/dockerize-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@ name: dockerize-server

on:
workflow_dispatch:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened]
paths:
- 'server/**'
- '.github/workflows/dockerize-server.yml'
- '!**/*.md'
- '!server/package-lock.json'
push:
branches:
- main
branches: [main]
paths:
- 'server/**'
- '.github/workflows/dockerize-server.yml'
- '!**/*.md'
- '!server/package-lock.json'

# permissions:
# pull-requests: write
# packages: write
# contents: read

concurrency:
group: dockerize-server-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -54,8 +66,10 @@ jobs:
docker.io/${{ secrets.DOCKER_USERNAME }}/laf-server
# https://github.com/docker/metadata-action#typesemver
tags: |
type=raw,value=latest,enable=true
type=sha,enable=true,format=short
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=sha,format=short,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value={{branch}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') && !startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -85,9 +99,21 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64

- name: Comment docker image tags to PR
if: github.event_name == 'pull_request'
uses: mshick/add-pr-comment@v2
with:
message-id: 'dockerize-server'
message: |
**:boom: laf server image built successfully for pr ${{ github.event.pull_request.number }}**
```
${{ steps.meta.outputs.tags }}
```
trigger-workflow-build-cluster-image:
needs: [dockerize-server]
if: github.ref == format('refs/heads/{0}', 'main')
runs-on: ubuntu-latest
steps:
- name: trigger cluster image workflow
Expand Down
31 changes: 29 additions & 2 deletions .github/workflows/dockerize-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: dockerize-web

on:
workflow_dispatch:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened]
paths:
- 'web/**'
- '.github/workflows/dockerize-web.yml'
- '!**/*.md'
- '!web/package-lock.json'
push:
branches:
- main
Expand All @@ -11,6 +19,11 @@ on:
- '!**/*.md'
- '!web/package-lock.json'

# permissions:
# pull-requests: write
# packages: write
# contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -74,8 +87,10 @@ jobs:
docker.io/${{ secrets.DOCKER_USERNAME }}/laf-web
# https://github.com/docker/metadata-action#typesemver
tags: |
type=raw,value=latest,enable=true
type=sha,enable=true,format=short
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=sha,format=short,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value={{branch}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') && !startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down Expand Up @@ -106,9 +121,21 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64

- name: Comment docker image tags to PR
if: github.event_name == 'pull_request'
uses: mshick/add-pr-comment@v2
with:
message-id: 'dockerize-web'
message: |
**:boom: laf web image built successfully for pr ${{ github.event.pull_request.number }}**
```
${{ steps.meta.outputs.tags }}
```
trigger-workflow-build-cluster-image:
needs: [dockerize-web]
runs-on: ubuntu-latest
if: github.ref == format('refs/heads/{0}', 'main')
steps:
- name: trigger cluster image workflow
uses: peter-evans/repository-dispatch@v2
Expand Down

0 comments on commit 4a0e4b4

Please sign in to comment.