GPT5 - Refactor build-docker-image workflow: streamline buildx setup, switch to inline build command, and improve cleanup process.
All checks were successful
Build and Push Server Docker Image / build-server (push) Successful in 10m11s

This commit is contained in:
2025-09-03 19:46:11 +03:30
parent eda54928f2
commit 776c463c0c

View File

@@ -8,19 +8,16 @@ on:
jobs: jobs:
build-server: build-server:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
services:
docker:
image: docker:dind
options: --privileged --security-opt seccomp=unconfined
steps: steps:
# 1. Check out the repo
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# 2. Set up Docker Buildx (recommended for advanced caching) - name: Set up Docker Buildx (ephemeral)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: network=host
buildkitd-flags: --debug
# 3. Log in to your container registry
- name: Log in to registry - name: Log in to registry
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
@@ -28,22 +25,22 @@ jobs:
username: ${{ secrets.REGISTRY_USERNAME }} username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.REGISTRY_PASSWORD }}
# 4. Lowercase the repository name
- name: Set lowercase repo name - name: Set lowercase repo name
run: echo "REPO_NAME_LOWER=$(echo '${{ github.event.repository.name }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV run: echo "REPO_NAME_LOWER=$(echo '${{ github.event.repository.name }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
# 5. Build & push the server image, using remote cache - name: Build and push (no local cache)
- name: Build and push server image run: |
uses: docker/build-push-action@v4 docker buildx build \
with: --pull \
context: VirtualDDNSRouter.Server --no-cache \
file: VirtualDDNSRouter.Server/Dockerfile --file VirtualDDNSRouter.Server/Dockerfile \
push: true --tag ${{ secrets.REGISTRY_URL }}/${{ github.repository_owner }}/${{ env.REPO_NAME_LOWER }}:latest-server \
tags: ${{ secrets.REGISTRY_URL }}/${{ github.repository_owner }}/${{ env.REPO_NAME_LOWER }}:latest-server --cache-from type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ github.repository_owner }}/${{ env.REPO_NAME_LOWER }}:buildcache \
cache-from: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ github.repository_owner }}/${{ env.REPO_NAME_LOWER }}:buildcache --cache-to type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ github.repository_owner }}/${{ env.REPO_NAME_LOWER }}:buildcache,mode=max \
cache-to: type=registry,ref=${{ secrets.REGISTRY_URL }}/${{ github.repository_owner }}/${{ env.REPO_NAME_LOWER }}:buildcache,mode=max --push \
VirtualDDNSRouter.Server
- name: Clean up Docker in dind
run: docker builder prune -af
- name: Remove builder to delete all cache
run: |
BUILDER=$(docker buildx ls | awk '/\*/ {print $1}')
docker buildx rm "$BUILDER" || true