Merge pull request #325 from linqiqi077/main #272
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build image | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*' | |
env: | |
REGISTRY: docker.io | |
BASE_IMAGE_NAME: kubeagi/ops-console-base | |
DIST_IMAGE_NAME: kubeagi/ops-console-dist | |
IMAGE_NAME: kubeagi/ops-console | |
DOCKER_USER: kubeagi | |
jobs: | |
image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
submodules: true | |
- uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
filters: | | |
package: | |
- 'package.json' | |
- 'pnpm-lock.yaml' | |
- '.npmrc' | |
- '.pnpmfile.cjs' | |
- 'packages/**/package.json' | |
- 'patches/*.patch' | |
- name: Set Variable | |
id: set-env | |
run: | | |
TAG=$(git describe --tags --abbrev=0 --match 'v*' 2> /dev/null) || true | |
if [ -z "$TAG" ]; then | |
echo "No tag found, use v0.1.0 as default" | |
TAG=v0.1.0 | |
fi | |
echo "TAG=${TAG}" >> $GITHUB_OUTPUT | |
echo "DATE=$(TZ=Asia/Shanghai date +'%Y%m%d')" >> $GITHUB_OUTPUT | |
- name: Show Variable | |
run: echo "varibables ${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}" | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
buildkitd-flags: --debug | |
config-inline: | | |
[worker.oci] | |
max-parallelism = 1 | |
- name: Login to the dockerhub Registry | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- uses: benjlevesque/[email protected] | |
name: Get short commit sha | |
id: short-sha | |
- name: setting token to npmrc | |
run: | | |
echo '//dev-npm.k8s.com.cn/:_authToken="${{ secrets.NPMTOKEN }}"' > /tmp/npmrc | |
- name: Build and push base image | |
id: base-buid-push | |
if: steps.changes.outputs.package == 'true' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: base.dockerfile | |
platforms: linux/amd64 | |
tags: | | |
${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:main | |
push: true | |
secret-files: | | |
"npmrc=/tmp/npmrc" | |
- name: Build dist | |
id: dist-build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: build.dockerfile | |
platforms: linux/amd64 | |
tags: | | |
${{ env.REGISTRY }}/${{ env.DIST_IMAGE_NAME }}:main | |
push: true | |
- name: Build and push image | |
id: build-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }} | |
${{ steps.meta.outputs.tags }} | |
push: true | |
build-args: | | |
BUILD_ID=${{ env.SEMREV_LABEL }} | |
BUILD_DATE=${{ env.BUILD_DATE }} |