-
Notifications
You must be signed in to change notification settings - Fork 17
149 lines (131 loc) · 5.02 KB
/
docker-image.yml
File metadata and controls
149 lines (131 loc) · 5.02 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Docker image CI
on:
pull_request:
branches: [ "master", "develop" ]
workflow_dispatch:
env:
BASE_IMAGE_REPO: ghcr.io/psal-postech/torchsim_base
# PR: head commit; otherwise workflow_dispatch uses the branch SHA
SOURCE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
jobs:
ensure-base:
runs-on: ubuntu-latest
outputs:
base_image: ${{ steps.pin.outputs.base_image }}
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ env.SOURCE_SHA }}
submodules: recursive
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: PyTorch base image from manifest
run: |
PYTORCH_IMAGE=$(python3 -c "import json; from pathlib import Path; v=json.loads(Path('thirdparty/github-releases.json').read_text()).get('pytorch_image'); print(v or '')")
if [ -z "$PYTORCH_IMAGE" ]; then echo "thirdparty/github-releases.json: pytorch_image is required" >&2; exit 1; fi
echo "PYTORCH_IMAGE=$PYTORCH_IMAGE" >> "$GITHUB_ENV"
- name: Thirdparty pin
id: pin
run: |
PIN="$(bash scripts/ci/thirdparty_base_pin.sh)"
echo "pin=${PIN}" >> "$GITHUB_OUTPUT"
echo "base_image=${BASE_IMAGE_REPO}:thirdparty-${PIN}" >> "$GITHUB_OUTPUT"
echo "BASE_IMAGE=${BASE_IMAGE_REPO}:thirdparty-${PIN}" >> "$GITHUB_ENV"
- name: Check base image exists
id: exists
run: |
if docker manifest inspect "${BASE_IMAGE}" > /dev/null 2>&1; then
echo "ok=true" >> "$GITHUB_OUTPUT"
else
echo "ok=false" >> "$GITHUB_OUTPUT"
fi
- name: Resolve GitHub release asset IDs
if: steps.exists.outputs.ok != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bash scripts/ci/thirdparty_github_asset_env.sh >> "$GITHUB_ENV"
- name: Build and push base image (missing pin)
if: steps.exists.outputs.ok != 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile.base
push: true
build-args: |
PYTORCH_IMAGE=${{ env.PYTORCH_IMAGE }}
GEM5_ASSET_ID=${{ env.GEM5_ASSET_ID }}
LLVM_ASSET_ID=${{ env.LLVM_ASSET_ID }}
SPIKE_ASSET_ID=${{ env.SPIKE_ASSET_ID }}
tags: ${{ env.BASE_IMAGE }}
build-and-test:
needs: ensure-base
runs-on: self-hosted
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ env.SOURCE_SHA }}
submodules: recursive
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
no-cache: true
build-args: |
BASE_IMAGE=${{ needs.ensure-base.outputs.base_image }}
tags: ghcr.io/psal-postech/torchsim-test:${{ env.SOURCE_SHA }}
# Do not use GITHUB_SHA here: on pull_request it is the merge commit, while the image tag uses SOURCE_SHA (PR head).
- name: Wait for GHCR propagation
env:
IMAGE_SHA: ${{ env.SOURCE_SHA }}
run: |
IMG="ghcr.io/psal-postech/torchsim-test:${IMAGE_SHA}"
echo "Verifying tag matches push: ${IMAGE_SHA}"
for i in $(seq 1 30); do
echo "Checking if image exists in GHCR (attempt $i)..."
if docker buildx imagetools inspect "$IMG" > /dev/null 2>&1; then
echo "Image is now available in GHCR."
exit 0
fi
if [ "$i" -eq 1 ]; then
echo "buildx imagetools inspect failed; stderr (first attempt):"
docker buildx imagetools inspect "$IMG" 2>&1 || true
fi
echo "Image not yet available, retrying in 20 seconds..."
sleep 20
done
echo "Image did not become available in GHCR within expected time."
exit 1
test-pytorchsim-wrapper1:
needs: build-and-test
uses: ./.github/workflows/pytorchsim_test.yml
with:
image_name: ghcr.io/psal-postech/torchsim-test:${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
vector_lane: 128
spad_size: 128
test-pytorchsim-wrapper2:
needs: build-and-test
uses: ./.github/workflows/pytorchsim_test.yml
with:
image_name: ghcr.io/psal-postech/torchsim-test:${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
vector_lane: 32
spad_size: 32