From fa635ab1f4d1160b40fcf3220de9e4712ed12446 Mon Sep 17 00:00:00 2001 From: Milad Raeisi Date: Fri, 31 Jan 2025 18:23:05 +0400 Subject: [PATCH 1/5] Update actions --- .github/workflows/on-tag.yml | 110 +++++---------------------- .github/workflows/reusable-build.yml | 98 ++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 90 deletions(-) create mode 100644 .github/workflows/reusable-build.yml diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index b97a673e81..22773a7f8f 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -1,9 +1,4 @@ name: Docker build on tag -env: - DOCKER_CLI_EXPERIMENTAL: enabled - TAG_FMT: "^refs/tags/(((.?[0-9]+){3,4}))$" - DOCKER_BUILDKIT: 0 - COMPOSE_DOCKER_CLI_BUILD: 0 on: push: @@ -15,93 +10,28 @@ permissions: contents: read jobs: - build: + build-self-hosted: strategy: matrix: service: - frontend - backend - runs-on: [self-hosted, Linux, X64] - timeout-minutes: 120 - name: Build and push to DockerHub - steps: - # Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1 - - name: Replace the current swap file - shell: bash - run: | - sudo swapoff /mnt/swapfile - sudo rm -v /mnt/swapfile - sudo fallocate -l 13G /mnt/swapfile - sudo chmod 600 /mnt/swapfile - sudo mkswap /mnt/swapfile - sudo swapon /mnt/swapfile - - - name: Show current memory and swap status - shell: bash - run: | - sudo free -h - echo - sudo swapon --show - - - name: Mount a tmpfs over /var/lib/docker - shell: bash - run: | - if [ ! -d "/var/lib/docker" ]; then - echo "Directory '/var/lib/docker' not found" - exit 1 - fi - sudo mount -t tmpfs -o size=10G tmpfs /var/lib/docker - sudo systemctl restart docker - sudo df -h | grep docker - - - name: Set env variables - run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - - name: Show set environment variables - run: | - printf " TAG: %s\n" "$TAG" - - - name: Add SHORT_SHA env property with commit short sha - run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV - - - name: Login to Docker - run: | - docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" - - name: Checkout project - uses: actions/checkout@v4 - - - name: Init repo for Dockerization - run: docker/init.sh "$TAG" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - id: qemu - - - name: Setup Docker buildx action - uses: docker/setup-buildx-action@v3 - id: buildx - - - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} - - - name: Cache Docker layers - uses: actions/cache@v3 - id: cache - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Run Docker buildx for ${{ matrix.service }} against tag - run: | - docker buildx build \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache" \ - --platform linux/amd64,linux/arm64 \ - --tag blockcore/mempool-${{ matrix.service }}:$TAG \ - --tag blockcore/mempool-${{ matrix.service }}:latest \ - --build-context rustgbt=./rust \ - --build-context backend=./backend \ - --output "type=registry" ./${{ matrix.service }}/ \ - --build-arg commitHash=$SHORT_SHA + uses: ./.github/workflows/reusable-build.yml + with: + runner: self-hosted + service: ${{ matrix.service }} + secrets: + DOCKER_KEY: ${{ secrets.DOCKER_KEY }} + + build-github-hosted: + strategy: + matrix: + service: + - frontend + - backend + uses: ./.github/workflows/reusable-build.yml + with: + runner: ubuntu-latest + service: ${{ matrix.service }} + secrets: + DOCKER_KEY: ${{ secrets.DOCKER_KEY }} diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml new file mode 100644 index 0000000000..2d08c0f989 --- /dev/null +++ b/.github/workflows/reusable-build.yml @@ -0,0 +1,98 @@ +name: Reusable build workflow + +on: + workflow_call: + inputs: + runner: + required: true + type: string + service: + required: true + type: string + secrets: + DOCKER_KEY: + required: true + +jobs: + build: + runs-on: ${{ inputs.runner }} + timeout-minutes: 120 + name: Build and push to DockerHub + steps: + # Install dependencies for ubuntu-latest + - name: System Setup + if: inputs.runner == 'ubuntu-latest' + run: | + sudo apt-get update && sudo apt-get upgrade -y + sudo apt-get install -y docker.io + sudo systemctl start docker + sudo systemctl enable docker + + # Setup for self-hosted + - name: Setup Swap + if: inputs.runner == 'self-hosted' + shell: bash + run: | + sudo swapoff /mnt/swapfile || true + sudo rm -v /mnt/swapfile || true + sudo fallocate -l 13G /mnt/swapfile + sudo chmod 600 /mnt/swapfile + sudo mkswap /mnt/swapfile + sudo swapon /mnt/swapfile + + - name: Mount Docker tmpfs + if: inputs.runner == 'self-hosted' + shell: bash + run: | + if [ ! -d "/var/lib/docker" ]; then + echo "Directory '/var/lib/docker' not found" + exit 1 + fi + sudo mount -t tmpfs -o size=10G tmpfs /var/lib/docker + sudo systemctl restart docker + sudo df -h | grep docker + + - name: Set env variables + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + + - name: Add SHORT_SHA + run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV + + - name: Login to Docker + run: docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" + + - name: Checkout project + uses: actions/checkout@v4 + + - name: Init repo for Dockerization + run: docker/init.sh "$TAG" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + id: qemu + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + id: buildx + + - name: Cache Docker layers + uses: actions/cache@v3 + id: cache + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build and push Docker image + run: | + docker buildx build \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + --platform linux/amd64,linux/arm64 \ + --tag blockcore/mempool-${{ inputs.service }}:$TAG \ + --tag blockcore/mempool-${{ inputs.service }}:latest \ + --build-context rustgbt=./rust \ + --build-context backend=./backend \ + --output "type=registry" ./${{ inputs.service }}/ \ + --build-arg commitHash=$SHORT_SHA From ae661a66ba2a3692857370aff18d37abfa6613cb Mon Sep 17 00:00:00 2001 From: Milad Raeisi Date: Fri, 31 Jan 2025 18:41:12 +0400 Subject: [PATCH 2/5] Refactor CI workflows to enhance Docker build processes and remove reusable build configuration --- .github/workflows/ci.yml | 6 +- .github/workflows/on-tag.yml | 206 ++++++++++++++++++++++++--- .github/workflows/reusable-build.yml | 98 ------------- 3 files changed, 188 insertions(+), 122 deletions(-) delete mode 100644 .github/workflows/reusable-build.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59dc62bd14..c03d490f76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: backend: - if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')" + if: ${{ !contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/') }} strategy: matrix: node: ["20", "21"] @@ -157,7 +157,7 @@ jobs: frontend: needs: cache - if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')" + if: ${{ !contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/') }} strategy: matrix: node: ["20", "21"] @@ -333,7 +333,7 @@ jobs: # CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }} validate_docker_json: - if: "!contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/')" + if: ${{ !contains(github.event.pull_request.labels.*.name, 'ops') && !contains(github.head_ref, 'ops/') }} runs-on: "ubuntu-latest" name: Validate generated backend Docker JSON diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index 22773a7f8f..1ab7ce8056 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -1,4 +1,9 @@ name: Docker build on tag +env: + DOCKER_CLI_EXPERIMENTAL: enabled + TAG_FMT: "^refs/tags/(((.?[0-9]+){3,4}))$" + DOCKER_BUILDKIT: 0 + COMPOSE_DOCKER_CLI_BUILD: 0 on: push: @@ -10,28 +15,187 @@ permissions: contents: read jobs: - build-self-hosted: + build-selfhosted: strategy: matrix: - service: - - frontend - - backend - uses: ./.github/workflows/reusable-build.yml - with: - runner: self-hosted - service: ${{ matrix.service }} - secrets: - DOCKER_KEY: ${{ secrets.DOCKER_KEY }} - - build-github-hosted: + service: [frontend, backend] + runs-on: self-hosted + timeout-minutes: 120 + name: Build on self-hosted (${{ matrix.service }}) + steps: + # Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1 + - name: Replace the current swap file + shell: bash + run: | + sudo swapoff /mnt/swapfile + sudo rm -v /mnt/swapfile + sudo fallocate -l 13G /mnt/swapfile + sudo chmod 600 /mnt/swapfile + sudo mkswap /mnt/swapfile + sudo swapon /mnt/swapfile + + - name: Show current memory and swap status + shell: bash + run: | + sudo free -h + echo + sudo swapon --show + + - name: Mount a tmpfs over /var/lib/docker + shell: bash + run: | + if [ ! -d "/var/lib/docker" ]; then + echo "Directory '/var/lib/docker' not found" + exit 1 + fi + sudo mount -t tmpfs -o size=10G tmpfs /var/lib/docker + sudo systemctl restart docker + sudo df -h | grep docker + + - name: Set env variables + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + + - name: Show set environment variables + run: | + printf " TAG: %s\n" "$TAG" + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV + + - name: Login to Docker + run: | + docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" + - name: Checkout project + uses: actions/checkout@v4 + + - name: Init repo for Dockerization + run: docker/init.sh "$TAG" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + id: qemu + + - name: Setup Docker buildx action + uses: docker/setup-buildx-action@v3 + id: buildx + + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + + - name: Cache Docker layers + uses: actions/cache@v3 + id: cache + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Run Docker buildx for ${{ matrix.service }} against tag + run: | + docker buildx build \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + --platform linux/amd64,linux/arm64 \ + --tag blockcore/mempool-${{ matrix.service }}:$TAG \ + --tag blockcore/mempool-${{ matrix.service }}:latest \ + --build-context rustgbt=./rust \ + --build-context backend=./backend \ + --output "type=registry" ./${{ matrix.service }}/ \ + --build-arg commitHash=$SHORT_SHA + + build-ubuntu: strategy: matrix: - service: - - frontend - - backend - uses: ./.github/workflows/reusable-build.yml - with: - runner: ubuntu-latest - service: ${{ matrix.service }} - secrets: - DOCKER_KEY: ${{ secrets.DOCKER_KEY }} + service: [frontend, backend] + runs-on: ubuntu-latest + timeout-minutes: 120 + name: Build on ubuntu (${{ matrix.service }}) + steps: + - name: Install Docker + run: | + sudo apt-get update + sudo apt-get install -y docker.io + sudo systemctl start docker + sudo systemctl enable docker + + # Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1 + - name: Replace the current swap file + shell: bash + run: | + sudo swapoff /mnt/swapfile + sudo rm -v /mnt/swapfile + sudo fallocate -l 13G /mnt/swapfile + sudo chmod 600 /mnt/swapfile + sudo mkswap /mnt/swapfile + sudo swapon /mnt/swapfile + + - name: Show current memory and swap status + shell: bash + run: | + sudo free -h + echo + sudo swapon --show + + - name: Mount a tmpfs over /var/lib/docker + shell: bash + run: | + if [ ! -d "/var/lib/docker" ]; then + echo "Directory '/var/lib/docker' not found" + exit 1 + fi + sudo mount -t tmpfs -o size=10G tmpfs /var/lib/docker + sudo systemctl restart docker + sudo df -h | grep docker + + - name: Set env variables + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + + - name: Show set environment variables + run: | + printf " TAG: %s\n" "$TAG" + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV + + - name: Login to Docker + run: | + docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" + - name: Checkout project + uses: actions/checkout@v4 + + - name: Init repo for Dockerization + run: docker/init.sh "$TAG" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + id: qemu + + - name: Setup Docker buildx action + uses: docker/setup-buildx-action@v3 + id: buildx + + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + + - name: Cache Docker layers + uses: actions/cache@v3 + id: cache + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Run Docker buildx for ${{ matrix.service }} against tag + run: | + docker buildx build \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache" \ + --platform linux/amd64,linux/arm64 \ + --tag blockcore/mempool-${{ matrix.service }}:$TAG \ + --tag blockcore/mempool-${{ matrix.service }}:latest \ + --build-context rustgbt=./rust \ + --build-context backend=./backend \ + --output "type=registry" ./${{ matrix.service }}/ \ + --build-arg commitHash=$SHORT_SHA diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml deleted file mode 100644 index 2d08c0f989..0000000000 --- a/.github/workflows/reusable-build.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: Reusable build workflow - -on: - workflow_call: - inputs: - runner: - required: true - type: string - service: - required: true - type: string - secrets: - DOCKER_KEY: - required: true - -jobs: - build: - runs-on: ${{ inputs.runner }} - timeout-minutes: 120 - name: Build and push to DockerHub - steps: - # Install dependencies for ubuntu-latest - - name: System Setup - if: inputs.runner == 'ubuntu-latest' - run: | - sudo apt-get update && sudo apt-get upgrade -y - sudo apt-get install -y docker.io - sudo systemctl start docker - sudo systemctl enable docker - - # Setup for self-hosted - - name: Setup Swap - if: inputs.runner == 'self-hosted' - shell: bash - run: | - sudo swapoff /mnt/swapfile || true - sudo rm -v /mnt/swapfile || true - sudo fallocate -l 13G /mnt/swapfile - sudo chmod 600 /mnt/swapfile - sudo mkswap /mnt/swapfile - sudo swapon /mnt/swapfile - - - name: Mount Docker tmpfs - if: inputs.runner == 'self-hosted' - shell: bash - run: | - if [ ! -d "/var/lib/docker" ]; then - echo "Directory '/var/lib/docker' not found" - exit 1 - fi - sudo mount -t tmpfs -o size=10G tmpfs /var/lib/docker - sudo systemctl restart docker - sudo df -h | grep docker - - - name: Set env variables - run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - - name: Add SHORT_SHA - run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV - - - name: Login to Docker - run: docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" - - - name: Checkout project - uses: actions/checkout@v4 - - - name: Init repo for Dockerization - run: docker/init.sh "$TAG" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - id: qemu - - - name: Setup Docker buildx - uses: docker/setup-buildx-action@v3 - id: buildx - - - name: Cache Docker layers - uses: actions/cache@v3 - id: cache - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Build and push Docker image - run: | - docker buildx build \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache" \ - --platform linux/amd64,linux/arm64 \ - --tag blockcore/mempool-${{ inputs.service }}:$TAG \ - --tag blockcore/mempool-${{ inputs.service }}:latest \ - --build-context rustgbt=./rust \ - --build-context backend=./backend \ - --output "type=registry" ./${{ inputs.service }}/ \ - --build-arg commitHash=$SHORT_SHA From ace76225da5e3fd8be3fb2fdaed159525cb4979a Mon Sep 17 00:00:00 2001 From: Milad Raeisi Date: Fri, 31 Jan 2025 20:20:23 +0400 Subject: [PATCH 3/5] Update on-tag.yml --- .github/workflows/on-tag.yml | 106 ++--------------------------------- 1 file changed, 6 insertions(+), 100 deletions(-) diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index 1ab7ce8056..578b8ecfd2 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -15,110 +15,16 @@ permissions: contents: read jobs: - build-selfhosted: + build: strategy: matrix: - service: [frontend, backend] - runs-on: self-hosted - timeout-minutes: 120 - name: Build on self-hosted (${{ matrix.service }}) - steps: - # Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1 - - name: Replace the current swap file - shell: bash - run: | - sudo swapoff /mnt/swapfile - sudo rm -v /mnt/swapfile - sudo fallocate -l 13G /mnt/swapfile - sudo chmod 600 /mnt/swapfile - sudo mkswap /mnt/swapfile - sudo swapon /mnt/swapfile - - - name: Show current memory and swap status - shell: bash - run: | - sudo free -h - echo - sudo swapon --show - - - name: Mount a tmpfs over /var/lib/docker - shell: bash - run: | - if [ ! -d "/var/lib/docker" ]; then - echo "Directory '/var/lib/docker' not found" - exit 1 - fi - sudo mount -t tmpfs -o size=10G tmpfs /var/lib/docker - sudo systemctl restart docker - sudo df -h | grep docker - - - name: Set env variables - run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - - - name: Show set environment variables - run: | - printf " TAG: %s\n" "$TAG" - - - name: Add SHORT_SHA env property with commit short sha - run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV - - - name: Login to Docker - run: | - docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" - - name: Checkout project - uses: actions/checkout@v4 - - - name: Init repo for Dockerization - run: docker/init.sh "$TAG" - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - id: qemu - - - name: Setup Docker buildx action - uses: docker/setup-buildx-action@v3 - id: buildx - - - name: Available platforms - run: echo ${{ steps.buildx.outputs.platforms }} - - - name: Cache Docker layers - uses: actions/cache@v3 - id: cache - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Run Docker buildx for ${{ matrix.service }} against tag - run: | - docker buildx build \ - --cache-from "type=local,src=/tmp/.buildx-cache" \ - --cache-to "type=local,dest=/tmp/.buildx-cache" \ - --platform linux/amd64,linux/arm64 \ - --tag blockcore/mempool-${{ matrix.service }}:$TAG \ - --tag blockcore/mempool-${{ matrix.service }}:latest \ - --build-context rustgbt=./rust \ - --build-context backend=./backend \ - --output "type=registry" ./${{ matrix.service }}/ \ - --build-arg commitHash=$SHORT_SHA - - build-ubuntu: - strategy: - matrix: - service: [frontend, backend] + service: + - frontend + - backend runs-on: ubuntu-latest timeout-minutes: 120 - name: Build on ubuntu (${{ matrix.service }}) + name: Build and push to DockerHub steps: - - name: Install Docker - run: | - sudo apt-get update - sudo apt-get install -y docker.io - sudo systemctl start docker - sudo systemctl enable docker - # Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1 - name: Replace the current swap file shell: bash @@ -198,4 +104,4 @@ jobs: --build-context rustgbt=./rust \ --build-context backend=./backend \ --output "type=registry" ./${{ matrix.service }}/ \ - --build-arg commitHash=$SHORT_SHA + --build-arg commitHash=$SHORT_SHA \ No newline at end of file From 4fdcd6625c65df779e980feda555c12d73a1ec84 Mon Sep 17 00:00:00 2001 From: Milad Raeisi Date: Fri, 31 Jan 2025 20:31:31 +0400 Subject: [PATCH 4/5] Update on-tag.yml --- .github/workflows/on-tag.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index 578b8ecfd2..f0d6f1a42d 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -21,12 +21,13 @@ jobs: service: - frontend - backend - runs-on: ubuntu-latest + runs-on: ${{ github.repository_owner == 'github' && 'ubuntu-latest' || 'self-hosted' }} timeout-minutes: 120 name: Build and push to DockerHub steps: - # Workaround based on JonasAlfredsson/docker-on-tmpfs@v1.0.1 + # Only run these steps on GitHub-hosted runners - name: Replace the current swap file + if: ${{ github.repository_owner == 'github' }} shell: bash run: | sudo swapoff /mnt/swapfile @@ -37,6 +38,7 @@ jobs: sudo swapon /mnt/swapfile - name: Show current memory and swap status + if: ${{ github.repository_owner == 'github' }} shell: bash run: | sudo free -h @@ -44,6 +46,7 @@ jobs: sudo swapon --show - name: Mount a tmpfs over /var/lib/docker + if: ${{ github.repository_owner == 'github' }} shell: bash run: | if [ ! -d "/var/lib/docker" ]; then @@ -54,6 +57,7 @@ jobs: sudo systemctl restart docker sudo df -h | grep docker + # Common steps for both environments - name: Set env variables run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV From 2b7f477707aca7dfe3c7256b4119c531e218dad6 Mon Sep 17 00:00:00 2001 From: Milad Raeisi Date: Fri, 31 Jan 2025 20:39:31 +0400 Subject: [PATCH 5/5] Update on-tag.yml --- .github/workflows/on-tag.yml | 43 ++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/on-tag.yml b/.github/workflows/on-tag.yml index f0d6f1a42d..055a08c2fe 100644 --- a/.github/workflows/on-tag.yml +++ b/.github/workflows/on-tag.yml @@ -25,6 +25,15 @@ jobs: timeout-minutes: 120 name: Build and push to DockerHub steps: + - name: Validate runner + run: | + echo "Runner name: ${{ runner.name }}" + echo "Runner OS: ${{ runner.os }}" + if [ -z "${{ runner.name }}" ]; then + echo "Error: Runner not properly initialized" + exit 1 + fi + # Only run these steps on GitHub-hosted runners - name: Replace the current swap file if: ${{ github.repository_owner == 'github' }} @@ -69,8 +78,25 @@ jobs: run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV - name: Login to Docker + timeout-minutes: 5 run: | - docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" + max_attempts=3 + attempt=1 + while [ $attempt -le $max_attempts ]; do + if docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}"; then + echo "Docker login successful" + break + else + echo "Docker login attempt $attempt failed" + if [ $attempt -eq $max_attempts ]; then + echo "All Docker login attempts failed" + exit 1 + fi + sleep 10 + ((attempt++)) + fi + done + - name: Checkout project uses: actions/checkout@v4 @@ -98,7 +124,12 @@ jobs: ${{ runner.os }}-buildx- - name: Run Docker buildx for ${{ matrix.service }} against tag + timeout-minutes: 60 + continue-on-error: true + id: docker_build run: | + set -e + echo "Starting Docker build for ${{ matrix.service }}" docker buildx build \ --cache-from "type=local,src=/tmp/.buildx-cache" \ --cache-to "type=local,dest=/tmp/.buildx-cache" \ @@ -108,4 +139,12 @@ jobs: --build-context rustgbt=./rust \ --build-context backend=./backend \ --output "type=registry" ./${{ matrix.service }}/ \ - --build-arg commitHash=$SHORT_SHA \ No newline at end of file + --build-arg commitHash=$SHORT_SHA + + - name: Handle build failure + if: steps.docker_build.outcome == 'failure' + run: | + echo "Docker build failed for ${{ matrix.service }}" + echo "Cleaning Docker cache" + docker builder prune -f + exit 1 \ No newline at end of file