From 978cec359ee18fd108894fcbcf945a95f2b49335 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Mon, 27 Jan 2025 01:07:10 +0800 Subject: [PATCH] feat: add docker CI workflow for development - Create new workflow for building and pushing Docker images on push to 'dev' branch. - Rename existing docker.yml to docker-main.yml and update image tag from 'latest' to 'main'. This commit enhances the CI process by integrating Docker builds for continuous delivery on the development branch, ensuring a clear versioning strategy with updated tagging for production readiness. --- .github/workflows/docker-dev.yml | 48 +++++++++++++++++++ .../workflows/{docker.yml => docker-main.yml} | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-dev.yml rename .github/workflows/{docker.yml => docker-main.yml} (97%) diff --git a/.github/workflows/docker-dev.yml b/.github/workflows/docker-dev.yml new file mode 100644 index 0000000..33d0838 --- /dev/null +++ b/.github/workflows/docker-dev.yml @@ -0,0 +1,48 @@ +name: Docker + +on: + push: + branches: + - dev + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: docker.io + IMAGE_NAME: ${{ github.event.repository.name }} + +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: ${{github.actor}} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: | + ${{ env.REGISTRY }}/${{github.actor}}/${{ github.event.repository.name }}:dev \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker-main.yml similarity index 97% rename from .github/workflows/docker.yml rename to .github/workflows/docker-main.yml index 2e395dc..4146b84 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker-main.yml @@ -47,5 +47,5 @@ jobs: context: . push: ${{ github.event_name != 'pull_request' }} tags: | - ${{ env.REGISTRY }}/${{github.actor}}/${{ github.event.repository.name }}:latest + ${{ env.REGISTRY }}/${{github.actor}}/${{ github.event.repository.name }}:main ${{ env.REGISTRY }}/${{github.actor}}/${{ github.event.repository.name }}:${{ steps.get_version.outputs.VERSION }} \ No newline at end of file