再次修复镜像构建版本问题导致的修改密码无效 #1
This file contains hidden or 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: Docker Build | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*.*.*' ] # 匹配版本标签 | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # 获取完整的git历史用于版本计算 | |
| # 获取版本信息 | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| # 从tag获取版本 | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| else | |
| # 从package.json获取版本 | |
| VERSION=$(node -p "require('./package.json').version") | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # 设置 QEMU 和 Docker Buildx | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| driver-opts: | | |
| image=moby/buildkit:latest | |
| # 登录到 GitHub Container Registry | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # 提取元数据 | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=raw,value=${{ steps.get_version.outputs.version }} | |
| type=sha,format=short | |
| # 构建和推送 | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha,scope=${{ github.workflow }} | |
| cache-to: type=gha,mode=max,scope=${{ github.workflow }} | |
| build-args: | | |
| BUILDKIT_INLINE_CACHE=1 | |
| VERSION=${{ steps.get_version.outputs.version }} | |
| # 启用 BuildKit 内联缓存 | |
| outputs: type=docker,dest=/tmp/image.tar | |
| # 输出版本信息 | |
| - name: Print version info | |
| run: | | |
| echo "构建版本: ${{ steps.get_version.outputs.version }}" | |
| echo "镜像标签:" | |
| echo "${{ steps.meta.outputs.tags }}" | tr '\n' '\n ' | |