From 62a4d19a2da39070158c230fe419a3050b494a8d Mon Sep 17 00:00:00 2001 From: 0fatal <2816813070@qq.com> Date: Fri, 15 Mar 2024 15:07:58 +0800 Subject: [PATCH] add github workflows --- .github/ISSUE_TEMPLATE/bug_report.yml | 94 +++++++++++ .github/ISSUE_TEMPLATE/config.yml | 8 + .github/ISSUE_TEMPLATE/feature_request.yml | 70 ++++++++ .github/ISSUE_TEMPLATE/question.yml | 59 +++++++ .github/workflows/build-scripts-updated.yml | 26 +++ .../workflows/build-sealos-cluster-image.yml | 122 ++++++++++++++ .github/workflows/dockerize-server.yml | 127 +++++++++++++++ .github/workflows/dockerize-web.yml | 149 +++++++++++++++++ .github/workflows/release.yml | 150 ++++++++++++++++++ 9 files changed, 805 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/ISSUE_TEMPLATE/question.yml create mode 100644 .github/workflows/build-scripts-updated.yml create mode 100644 .github/workflows/build-sealos-cluster-image.yml create mode 100644 .github/workflows/dockerize-server.yml create mode 100644 .github/workflows/dockerize-web.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..ba34d88 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,94 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: Bug report +title: "[bug] bug title " +description: If something isn't working as expected. +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + For better global communication, please write in English. + (为了更好的国际化交流,请您使用英语描述问题。) + + You can use ChatGPT to translate your native language into English: + (您可以使用ChatGPT将您的母语翻译成英文。) + - [ChatGPT](https://chat.openai.com/) + + - type: checkboxes + attributes: + label: Search before asking + description: > + Please make sure to search in the [issues](https://github.com/labring/sealaf/issues?q=is%3Aissue) + first to see whether the same issue was reported already. + options: + - label: > + I had searched in the [issues](https://github.com/labring/sealaf/issues?q=is%3Aissue) and found + no similar issues. + required: true + + - type: dropdown + attributes: + label: Environment + description: Describe the environment. + options: + - Linux (self-host) + - Mac (self-host) + - Windows (self-host) + - Laf-cli + validations: + required: true + + - type: textarea + attributes: + label: What happened + description: Describe what happened. + placeholder: > + A clear and concise description of what the bug is. + validations: + required: true + + - type: textarea + attributes: + label: How to reproduce + description: > + Describe the steps to reproduce the bug here. + placeholder: > + Please make sure you provide a reproducible step-by-step case of how to reproduce the problem + as minimally and precisely as possible. + + 1. xxx + + 2. xxx + + 3. ... + validations: + required: true + + - type: checkboxes + attributes: + label: Are you willing to submit PR? + description: > + This is absolutely not required, but we are happy to guide you in the contribution process + especially if you already have a good understanding of how to implement the fix. + options: + - label: Yes I am willing to submit a PR! + + - type: markdown + attributes: + value: "Thanks for completing our form!" diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..5081aef --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Join Our Discord + url: https://discord.gg/uWZqAwwdvy + about: Join our community, we will keep you in the loop. + - name: Contact US / Business Inquiries + url: https://docs.qq.com/form/page/DS0tCWXpQc2NpR3dR + about: Please contact us. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..0e9c3d8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,70 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: Feature Request +title: "[Feature] Feature title " +description: I want to suggest a feature for this project. +labels: [ "feature" ] +body: + - type: markdown + attributes: + value: | + For better global communication, Please write in English. + (为了更好的国际化交流,请您使用英语描述您的问题。) + + You can use the following translation tool to translate, but please check the translation carefully after translation to avoid misinterpretation: + (你可以使用以下翻译工具进行翻译,但是翻译完成后请仔细检查译文,以免有错误的理解:) + - [Google Translate](https://translate.google.com/) + - [Baidu Translate](https://fanyi.baidu.com/) + - [YouDao Translate](https://fanyi.baidu.com/) + - ChatGPT + + - type: checkboxes + attributes: + label: Search before asking + description: > + Please make sure to search in the [issues](https://github.com/labring/sealaf/issues?q=is%3Aissue) + first to see whether the same issue was reported already. + options: + - label: > + I had searched in the [issues](https://github.com/labring/sealaf/issues?q=is%3Aissue) and found + no similar issues. + required: true + + - type: textarea + attributes: + label: Feature Request + description: Describe the feature. + placeholder: > + First of all: Have you checked the docs, + or GitHub issues whether someone else has already reported your issue? + Maybe the feature already exists? + validations: + required: true + + - type: checkboxes + attributes: + label: Are you willing to submit PR? + description: > + This is absolutely not required, but we are happy to guide you in the contribution process + especially if you already have a good understanding of how to implement the fix. + options: + - label: Yes I am willing to submit a PR! + + - type: markdown + attributes: + value: "Thanks for completing our form!" diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml new file mode 100644 index 0000000..a9028df --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -0,0 +1,59 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: Question +title: "[Question] Question title " +description: I have a question that isn't answered in docs or issue. +labels: [ "question" ] +body: + - type: markdown + attributes: + value: | + For better global communication, Please write in English. + (为了更好的国际化交流,请您使用英语描述您的问题。) + + You can use the following translation tool to translate, but please check the translation carefully after translation to avoid misinterpretation: + (你可以使用以下翻译工具进行翻译,但是翻译完成后请仔细检查译文,以免有错误的理解:) + - [Google Translate](https://translate.google.com/) + - [Baidu Translate](https://fanyi.baidu.com/) + - [YouDao Translate](https://fanyi.baidu.com/) + - ChatGPT + + - type: checkboxes + attributes: + label: Search before asking + description: > + Please make sure to search in the [issues](https://github.com/labring/sealaf/issues?q=is%3Aissue) + first to see whether the same issue was reported already. + options: + - label: > + I had searched in the [issues](https://github.com/labring/sealaf/issues?q=is%3Aissue) and found + no similar issues. + required: true + + - type: textarea + attributes: + label: Question + description: Describe your question. + placeholder: > + Describe your question here :D + validations: + required: true + + - type: markdown + attributes: + value: "Thanks for completing our form!" diff --git a/.github/workflows/build-scripts-updated.yml b/.github/workflows/build-scripts-updated.yml new file mode 100644 index 0000000..acdbf32 --- /dev/null +++ b/.github/workflows/build-scripts-updated.yml @@ -0,0 +1,26 @@ +name: build-scripts-updated + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "build/**" + - ".github/workflows/build-scripts-updated.yml" + - ".github/workflows/build-sealos-cluster-image.yml" + - "!**/*.md" + +concurrency: + group: build-scripts-updated-${{ github.ref }} + cancel-in-progress: true + +jobs: + trigger-workflow-build-cluster-image: + runs-on: ubuntu-latest + steps: + - name: trigger cluster image workflow + uses: peter-evans/repository-dispatch@v2 + with: + event-type: build-scripts-updated + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}' diff --git a/.github/workflows/build-sealos-cluster-image.yml b/.github/workflows/build-sealos-cluster-image.yml new file mode 100644 index 0000000..ee5cfcb --- /dev/null +++ b/.github/workflows/build-sealos-cluster-image.yml @@ -0,0 +1,122 @@ +name: build-sealos-cluster-image + +on: + repository_dispatch: + types: [docker_build_success, build-scripts-updated] + workflow_dispatch: + +env: + # Common versions + GO_VERSION: "1.19" + +concurrency: + group: build-sealos-cluster-image-${{ github.ref }} + cancel-in-progress: true + +jobs: + build_cluster_image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.client_payload.ref }} + + - name: Prepare + id: prepare + run: | + IMAGE=sealaf + TAG=${{ github.event.client_payload.version }} + echo "tag=${TAG}" >> $GITHUB_ENV + echo "image=${IMAGE}" >> $GITHUB_ENV + + - name: Remove builtin docker + run: | + sudo apt-get remove -y moby-engine moby-cli moby-buildx moby-compose + + - name: Install sealos + run: | + echo "deb [trusted=yes] https://apt.fury.io/labring/ /" | sudo tee /etc/apt/sources.list.d/labring.list + sudo apt update + sudo apt install sealos=4.1.4 + sudo sealos version + + - name: Install buildah + run: | + sudo apt remove buildah -y || true + arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) + sudo echo "download buildah in https://github.com/labring/cluster-image/releases/download/depend/buildah.linux.${arch}" + sudo wget -qO "buildah" "https://github.com/labring/cluster-image/releases/download/depend/buildah.linux.${arch}" + sudo chmod a+x buildah + sudo mv buildah /usr/bin + + - name: Login GHCR.io + run: | + echo "run: buildah login -u ${{ github.repository_owner }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io" + sudo buildah login -u ${{ github.repository_owner }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io + + - name: Build cluster image + env: + IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.image }} + VERSION: ${{ env.tag }} + working-directory: build + run: | + echo $IMAGE:$VERSION + sudo sealos build -t $IMAGE:$VERSION-arm64 --platform linux/arm64 -f Kubefile . + sudo rm -rf registry + sudo sealos build -t $IMAGE:$VERSION-amd64 --platform linux/amd64 -f Kubefile . + sudo sealos images + + - name: Push cluster image to ghcr.io + env: + IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.image }} + VERSION: ${{ env.tag }} + run: | + sudo buildah images + sudo buildah push $IMAGE:$VERSION-amd64 + sudo buildah push $IMAGE:$VERSION-arm64 + sudo buildah manifest create $IMAGE:$VERSION + sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-amd64 + sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-arm64 + sudo buildah manifest push --all $IMAGE:$VERSION docker://$IMAGE:$VERSION + + - name: Push cluster image to docker.io + env: + GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ env.image }} + IMAGE: docker.io/${{ secrets.DOCKER_USERNAME }}/${{ env.image }} + VERSION: ${{ env.tag }} + run: | + sudo buildah login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker.io + sudo buildah tag $GHCR_IMAGE:$VERSION-amd64 $IMAGE:$VERSION-amd64 + sudo buildah tag $GHCR_IMAGE:$VERSION-arm64 $IMAGE:$VERSION-arm64 + sudo buildah push $IMAGE:$VERSION-amd64 + sudo buildah push $IMAGE:$VERSION-arm64 + sudo buildah manifest create $IMAGE:$VERSION + sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-amd64 + sudo buildah manifest add $IMAGE:$VERSION docker://$IMAGE:$VERSION-arm64 + sudo buildah manifest push --all $IMAGE:$VERSION docker://$IMAGE:$VERSION + + - name: Renew issue and Sync Images + uses: labring/gh-rebot@v0.0.6 + with: + version: v0.0.8-rc1 + env: + GH_TOKEN: "${{ secrets.GH_PAT }}" + SEALOS_TYPE: "issue_renew" + SEALOS_ISSUE_TITLE: "【DaylyReport】 Auto build for sealaf" + SEALOS_ISSUE_BODYFILE: "build/README.md" + SEALOS_ISSUE_LABEL: "dayly-report" + SEALOS_ISSUE_TYPE: "day" + 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"}' diff --git a/.github/workflows/dockerize-server.yml b/.github/workflows/dockerize-server.yml new file mode 100644 index 0000000..43c8796 --- /dev/null +++ b/.github/workflows/dockerize-server.yml @@ -0,0 +1,127 @@ +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] + 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 + +jobs: + dockerize-server: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: server/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('server/package-lock.json') }} + + - name: Use Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Install Package + working-directory: server + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci && npm rebuild --arch=arm64 sharp + + - name: Build server + working-directory: server + run: npm run build + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ github.repository_owner }}/sealaf-server + docker.io/${{ secrets.DOCKER_USERNAME }}/sealaf-server + # https://github.com/docker/metadata-action#typesemver + tags: | + type=ref,event=pr + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') && github.event_name != 'pull_request_target' }} + type=sha,format=short,enable=${{ github.ref == format('refs/heads/{0}', 'main') && github.event_name != 'pull_request_target' }} + type=raw,value={{branch}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') && !startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request_target' }} + + - 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 + id: docker-build + uses: docker/build-push-action@v3 + with: + context: ./server + file: ./server/Dockerfile + push: true + 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_target' + uses: mshick/add-pr-comment@v2 + with: + message-id: "dockerize-server" + message: | + **:boom: sealaf server image built successfully for pr ${{ github.event.pull_request.number }}** + ``` + ${{ steps.meta.outputs.tags }} + ``` + digest: `${{ steps.docker-build.outputs.digest }}` + + trigger-workflow-build-cluster-image: + needs: [dockerize-server] + if: github.ref == format('refs/heads/{0}', 'main') && github.event_name != 'pull_request_target' + runs-on: ubuntu-latest + steps: + - name: trigger cluster image workflow + uses: peter-evans/repository-dispatch@v2 + with: + event-type: docker_build_success + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}' diff --git a/.github/workflows/dockerize-web.yml b/.github/workflows/dockerize-web.yml new file mode 100644 index 0000000..4eafb15 --- /dev/null +++ b/.github/workflows/dockerize-web.yml @@ -0,0 +1,149 @@ +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 + paths: + - "web/**" + - ".github/workflows/dockerize-web.yml" + - "!**/*.md" + - "!web/package-lock.json" + +# permissions: +# pull-requests: write +# packages: write +# contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + dockerize-web: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v3 + with: + path: web/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('web/package-lock.json') }} + + - name: Use Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Install Package + working-directory: web + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm ci + + - name: Build web + working-directory: web + # env: + # VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }} + # VITE_GITHUB_SHA: ${{ github.sha }} + run: npm run build + + # - name: Create Sentry release + # uses: getsentry/action-release@v1 + # if: ${{ !github.event.repository.fork }} + # env: + # SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + # SENTRY_ORG: ${{ secrets.SENTRY_ORG }} + # SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} + # with: + # sourcemaps: dist/assets + # url_prefix: "~/assets/" + # version: ${{ format('sealaf@{0}', github.sha) }} + # working_directory: web + # ignore_missing: true + # ignore_empty: true + + - run: | + rm -rf web/dist/assets/*.map + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ github.repository_owner }}/sealaf-web + docker.io/${{ secrets.DOCKER_USERNAME }}/sealaf-web + # https://github.com/docker/metadata-action#typesemver + tags: | + type=ref,event=pr + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') && github.event_name != 'pull_request_target' }} + type=sha,format=short,enable=${{ github.ref == format('refs/heads/{0}', 'main') && github.event_name != 'pull_request_target' }} + type=raw,value={{branch}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') && !startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request_target' }} + + - 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 + id: docker-build + uses: docker/build-push-action@v3 + with: + context: ./web + file: ./web/Dockerfile + push: true + 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_target' + uses: mshick/add-pr-comment@v2 + with: + message-id: "dockerize-web" + message: | + **:boom: sealaf web image built successfully for pr ${{ github.event.pull_request.number }}** + ``` + ${{ steps.meta.outputs.tags }} + ``` + digest: `${{ steps.docker-build.outputs.digest }}` + + trigger-workflow-build-cluster-image: + needs: [dockerize-web] + runs-on: ubuntu-latest + if: github.ref == format('refs/heads/{0}', 'main') && github.event_name != 'pull_request_target' + steps: + - name: trigger cluster image workflow + uses: peter-evans/repository-dispatch@v2 + with: + event-type: docker_build_success + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "latest"}' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5924482 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,150 @@ +name: release + +on: + workflow_dispatch: + push: + tags: + - v*.*.* + +env: + # Common versions + GO_VERSION: "1.19" + +jobs: + dockerize-server: + 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: server + run: npm cache clean --force && npm install + + - name: Build Packages + working-directory: server + run: npm run build + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ github.repository_owner }}/sealaf-server + docker.io/${{ secrets.DOCKER_USERNAME }}/sealaf-server + # https://github.com/docker/metadata-action#typesemver + tags: | + type=semver,pattern={{version}} + 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: ./server + file: ./server/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64, linux/arm64 + + dockerize-web: + 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: web + run: npm cache clean --force && npm install + + - name: Build web + working-directory: web + run: npm run build + + - run: | + rm -rf web/dist/assets/*.map + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ github.repository_owner }}/sealaf-web + docker.io/${{ secrets.DOCKER_USERNAME }}/sealaf-web + # https://github.com/docker/metadata-action#typesemver + tags: | + type=semver,pattern={{version}} + 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: ./web + file: ./web/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64, linux/arm64 + + trigger-workflow-build-cluster-image: + needs: [dockerize-server, dockerize-web] + runs-on: ubuntu-latest + steps: + - name: Set env + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Trigger cluster image workflow + uses: peter-evans/repository-dispatch@v2 + with: + event-type: docker_build_success + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "version": "${{ env.RELEASE_VERSION }}"}'