build: update Docker workflow for versioning
- Add checkout step to retrieve full git history - Introduce a step to get the current version of the project - Modify login step to use the actor's username instead of a constant - Update the tags to use dynamic versioning in Docker image push These changes improve the Docker workflow by ensuring that the correct version tag is used when building and pushing Docker images. The modified steps enhance traceability and allow the workflow to handle versioning accurately based on current git tags, addressing the need for specific version control in the images produced.
This commit is contained in:
parent
48f3da8913
commit
c9aef3ddfe
16
.github/workflows/docker.yml
vendored
16
.github/workflows/docker.yml
vendored
@ -14,13 +14,23 @@ jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # 获取完整的 git history 以便生成正确的 tag
|
||||
-
|
||||
name: Get Version
|
||||
id: get_version
|
||||
run: |
|
||||
echo "VERSION=$(git describe --dirty --always --tags --abbrev=7)" >> $GITHUB_OUTPUT
|
||||
-
|
||||
name: Login to ${{ env.REGISTRY }}
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
username: ${{github.actor}}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
-
|
||||
name: Set up QEMU
|
||||
@ -34,4 +44,6 @@ jobs:
|
||||
with:
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ env.REGISTRY }}/${{ secrets.DOCKER_HUB_USER }}/${{ github.event.repository.name }}:latest
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{github.actor}}/${{ github.event.repository.name }}:latest
|
||||
${{ env.REGISTRY }}/${{github.actor}}/${{ github.event.repository.name }}:${{ steps.get_version.outputs.VERSION }}
|
||||
|
Loading…
Reference in New Issue
Block a user