Skip to content

⚡️ 优化docker打包 #40

⚡️ 优化docker打包

⚡️ 优化docker打包 #40

Workflow file for this run

name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
release:
name: Release Docker image
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
id-token: write
issues: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
- name: Extract version from package.json
id: get_version
run: |
echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Set Git user info
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Delete existing tag if it exists
run: |
if git ls-remote --tags origin | grep "refs/tags/v${{ env.VERSION }}"; then
git push origin --delete "v${{ env.VERSION }}"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push new tag
run: |
git tag -a "v${{ env.VERSION }}" -m "Release version ${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
- name: Build and push Docker image
id: build_push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ env.VERSION }}
ghcr.io/${{ github.repository }}:latest
platforms: linux/amd64,linux/arm64