build-without-cache #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-without-cache | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| targets: | |
| description: 'Targets to build' | |
| required: true | |
| default: 'all' | |
| tool_chain_version: | |
| description: 'Tool chain version' | |
| required: false | |
| default: 'stable' | |
| remark: | |
| description: 'remark' | |
| required: false | |
| default: '-beta' | |
| is_free_disk_space: | |
| description: 'is_free_disk_space' | |
| required: false | |
| default: 'false' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-22.04 | |
| continue-on-error: true | |
| steps: | |
| - name: Check Server Performance | |
| run: | | |
| echo "--------------------------CPU info--------------------------" | |
| echo "CPU Physical: $(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)" | |
| echo "CPU: $(nproc)" | |
| echo -e "cpu info:$(cat /proc/cpuinfo | grep -m1 name | awk -F: '{print $2}')\n" | |
| echo "--------------------------mem info--------------------------" | |
| echo "memory:" | |
| echo -e "$(sudo lshw -short -C memory | grep GiB)\n" | |
| echo "--------------------------disk info--------------------------" | |
| echo "disk: $(ls /dev/sd* | grep -v [1-9] | wc -l)" && df -hT | |
| - name: Before freeing up disk space | |
| if: ${{ github.event.inputs.is_free_disk_space == 'true' }} | |
| run: | | |
| echo "Before freeing up disk space" | |
| echo "==============================================================================" | |
| df -hT | |
| echo "==============================================================================" | |
| - name: "Optimize Disk Space" | |
| if: ${{ github.event.inputs.is_free_disk_space == 'true' }} | |
| run: | | |
| sudo rm -rf /usr/share/dotnet /etc/apt/sources.list.d /usr/local/lib/android $AGENT_TOOLSDIRECTORY | |
| sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mongodb* moby* || true | |
| sudo -E apt-get -y update | |
| sudo -E apt-get -y install $(curl -fsSL is.gd/depends_ubuntu_2204) | |
| sudo -E systemctl daemon-reload | |
| sudo -E apt-get -y autoremove --purge | |
| sudo -E apt-get -y clean | |
| - name: Free up disk space complete | |
| if: ${{ github.event.inputs.is_free_disk_space == 'true' }} | |
| run: | | |
| echo "Free up disk space complete" | |
| echo "==============================================================================" | |
| df -hT | |
| echo "==============================================================================" | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up docker buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ secrets.GHCR_USERNAME }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| - name: Chmod +x for script | |
| run: chmod -R +x script/ | |
| - name: Pre build rust base | |
| run: | | |
| docker build --build-arg TOOLCHAIN_VERSION=${{ github.event.inputs.tool_chain_version }} -t rust-base:latest -f Dockerfiles/Dockerfile.base . | |
| - name: Parse and Find Dockerfiles for Targets | |
| id: set_targets | |
| run: | | |
| TARGETS="${{ github.event.inputs.targets }}" | |
| if [[ "$TARGETS" == "all" ]]; then | |
| # Find all Dockerfile paths and extract the architecture part (e.g., aarch64-apple-darwin) | |
| TARGETS=$(find Dockerfiles -type f -name 'Dockerfile.*' | grep -v 'Dockerfile.base' | sed -E 's|.*/Dockerfile\.||' | paste -sd ',') | |
| fi | |
| TARGETS_JSON=$(echo "[\"${TARGETS//,/\",\"}\"]") | |
| echo "TARGETS_JSON=${TARGETS_JSON}" >> $GITHUB_ENV | |
| - name: Build and Push | |
| run: | | |
| echo "Starting build All targets" | |
| echo "==============================================================================" | |
| TARGETS=$(echo $TARGETS_JSON | jq -r '.[]') | |
| for TARGET in $TARGETS; do | |
| echo "building for $TARGET" | |
| IMAGE_NAME=$TARGET:${{ github.event.inputs.tool_chain_version }}${{ github.event.inputs.remark }} | |
| DOCKERFILE=$(find Dockerfiles/*/*/*$TARGET -name 'Dockerfile.*') | |
| # build the docker image | |
| docker build \ | |
| --label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \ | |
| --build-arg TOOLCHAIN_VERSION=${{ github.event.inputs.tool_chain_version }} \ | |
| --cache-from ghcr.io/${{ secrets.GHCR_USERNAME }}/$IMAGE_NAME | |
| -t $IMAGE_NAME \ | |
| -f $DOCKERFILE . || echo "$TARGET build failed, continuing..." | |
| echo "$TARGET has been built" | |
| done | |
| echo "==============================================================================" | |
| echo "All targets have been built" | |
| echo "==============================================================================" | |
| echo "Starting push to docker hub and ghcr" | |
| echo "==============================================================================" | |
| for TARGET in $TARGETS; do | |
| IMAGE_NAME=$TARGET:${{ github.event.inputs.tool_chain_version }}${{ github.event.inputs.remark }} | |
| docker tag $IMAGE_NAME ghcr.io/${{ secrets.GHCR_USERNAME }}/$IMAGE_NAME | |
| docker push ghcr.io/${{ secrets.GHCR_USERNAME }}/$IMAGE_NAME | |
| docker tag $IMAGE_NAME ${{ secrets.DOCKERHUB_USERNAME }}/$IMAGE_NAME | |
| docker push ${{ secrets.DOCKERHUB_USERNAME }}/$IMAGE_NAME | |
| done | |
| echo "==============================================================================" | |
| echo "All targets have been pushed to docker hub and ghcr" | |