Repository navigation
127 lines (114 loc) · 5.45 KB
/
Copy pathbuild-base.yml
File metadata and controls
127 lines (114 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: build-and-cache-docker-image
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'
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
run: |
echo "Before freeing up disk space"
echo "=============================================================================="
df -hT
echo "=============================================================================="
- name: "Optimize Disk Space"
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
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 -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.cross-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 }} \
-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"