|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | name: Build container |
16 | | -on: |
17 | | - workflow_call: |
18 | | - inputs: |
19 | | - repo_name: |
20 | | - description: "The name of the repo to build container" |
21 | | - required: true |
22 | | - type: string |
23 | | - runner_name: |
24 | | - description: "Name of the runner" |
25 | | - required: true |
26 | | - type: string |
27 | | - environment_name: |
28 | | - description: "GitHub environment to use for this build" |
29 | | - required: true |
30 | | - type: string |
31 | 16 |
|
32 | | -jobs: |
33 | | - docker-build: |
34 | | - runs-on: ${{ inputs.runner_name }} |
35 | | - environment: ${{ inputs.environment_name }} |
36 | | - steps: |
37 | | - - name: Checkout |
38 | | - uses: actions/checkout@v4 |
| 17 | +inputs: |
| 18 | + repo_name: |
| 19 | + description: "The name of the repo to build container" |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + azure-client-id: |
| 23 | + description: "Azure Client ID" |
| 24 | + required: true |
| 25 | + azure-tenant-id: |
| 26 | + description: "Azure Tenant ID" |
| 27 | + required: true |
| 28 | + azure-subscription-id: |
| 29 | + description: "Azure Subscription ID" |
| 30 | + required: true |
| 31 | + has-azure-credentials: |
| 32 | + description: "Has Azure credentials" |
| 33 | + required: false |
| 34 | + default: "false" |
| 35 | + PAT: |
| 36 | + description: "GitHub Personal Access Token" |
| 37 | + required: true |
39 | 38 |
|
40 | | - - name: Setup python |
41 | | - uses: actions/setup-python@v5 |
42 | | - with: |
43 | | - python-version: 3.12 |
| 39 | +runs: |
| 40 | + using: "composite" |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
44 | 44 |
|
45 | | - - name: Get PR info |
46 | | - id: get-pr-info |
47 | | - if: startsWith(github.ref, 'refs/heads/pull-request/') |
48 | | - uses: nv-gha-runners/get-pr-info@main |
| 45 | + - name: Setup python |
| 46 | + uses: actions/setup-python@v5 |
| 47 | + with: |
| 48 | + python-version: 3.12 |
49 | 49 |
|
50 | | - - name: Install Azure CLI |
51 | | - shell: bash |
52 | | - run: | |
53 | | - echo "::group::Install Azure CLI" |
54 | | - # Create systemd override for proper dependencies |
55 | | - curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash |
56 | | - echo "::endgroup::" |
| 50 | + - name: Get PR info |
| 51 | + id: get-pr-info |
| 52 | + if: startsWith(github.ref, 'refs/heads/pull-request/') |
| 53 | + uses: nv-gha-runners/get-pr-info@main |
57 | 54 |
|
58 | | - - name: Azure Login |
59 | | - uses: azure/login@v2 |
60 | | - with: |
61 | | - client-id: ${{ secrets.AZURE_CLIENT_ID }} |
62 | | - tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
63 | | - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 55 | + - name: Install Azure CLI |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + echo "::group::Install Azure CLI" |
| 59 | + # Create systemd override for proper dependencies |
| 60 | + curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash |
| 61 | + echo "::endgroup::" |
64 | 62 |
|
65 | | - - name: Azure ACR Login |
66 | | - shell: bash |
67 | | - run: | |
68 | | - az acr login --name nemoci |
| 63 | + - name: Azure Login |
| 64 | + uses: azure/login@v2 |
| 65 | + with: |
| 66 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 67 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 68 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
69 | 69 |
|
70 | | - - name: Install GH CLI |
71 | | - shell: bash |
72 | | - run: | |
73 | | - apt-get update |
74 | | - apt-get install -y gh |
| 70 | + - name: Azure ACR Login |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + az acr login --name nemoci |
75 | 74 |
|
76 | | - - name: Get last merged PR |
77 | | - id: cache_from |
78 | | - env: |
79 | | - GH_TOKEN: ${{ github.token }} |
80 | | - REPO_NAME: ${{ inputs.repo_name }} |
81 | | - run: | |
82 | | - LAST_PRS=$(gh api graphql -f query=' |
83 | | - query { |
84 | | - repository(owner: "NVIDIA-NeMo", name: "$REPO_NAME") { |
85 | | - pullRequests(states: MERGED, first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) { |
86 | | - nodes { |
87 | | - number |
88 | | - } |
| 75 | + - name: Install GH CLI |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + apt-get update |
| 79 | + apt-get install -y gh |
| 80 | +
|
| 81 | + - name: Get last merged PR |
| 82 | + id: cache_from |
| 83 | + env: |
| 84 | + GH_TOKEN: ${{ github.token }} |
| 85 | + REPO_NAME: ${{ inputs.repo_name }} |
| 86 | + run: | |
| 87 | + LAST_PRS=$(gh api graphql -f query=' |
| 88 | + query { |
| 89 | + repository(owner: "NVIDIA-NeMo", name: "$REPO_NAME") { |
| 90 | + pullRequests(states: MERGED, first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) { |
| 91 | + nodes { |
| 92 | + number |
89 | 93 | } |
90 | 94 | } |
91 | | - }' | jq -r '.data.repository.pullRequests.nodes[].number' | while read -r number; do |
92 | | - echo "type=registry,ref=${{ env.container-registry }}/$REPO_NAME:$number-buildcache,mode=max" |
93 | | - done) |
| 95 | + } |
| 96 | + }' | jq -r '.data.repository.pullRequests.nodes[].number' | while read -r number; do |
| 97 | + echo "type=registry,ref=${{ env.container-registry }}/$REPO_NAME:$number-buildcache,mode=max" |
| 98 | + done) |
94 | 99 |
|
95 | | - echo "LAST_PRS<<EOF" | tee -a $GITHUB_OUTPUT |
96 | | - echo "$LAST_PRS" | tee -a $GITHUB_OUTPUT |
97 | | - echo "EOF" | tee -a $GITHUB_OUTPUT |
| 100 | + echo "LAST_PRS<<EOF" | tee -a $GITHUB_OUTPUT |
| 101 | + echo "$LAST_PRS" | tee -a $GITHUB_OUTPUT |
| 102 | + echo "EOF" | tee -a $GITHUB_OUTPUT |
98 | 103 |
|
99 | | - - name: Set up Docker Buildx |
100 | | - uses: docker/setup-buildx-action@v3 |
| 104 | + - name: Set up Docker Buildx |
| 105 | + uses: docker/setup-buildx-action@v3 |
101 | 106 |
|
102 | | - - name: Build and push |
103 | | - uses: docker/build-push-action@v5 |
104 | | - env: |
105 | | - REPO_NAME: ${{ inputs.repo_name }} |
106 | | - with: |
107 | | - file: ./docker/Dockerfile.ci |
108 | | - push: true |
109 | | - context: . |
110 | | - build-args: | |
111 | | - BASE_IMAGE=pytorch |
112 | | - cache-from: | |
113 | | - type=registry,ref=${{ env.container-registry }}/$REPO_NAME:${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').number || 0 }}-buildcache,mode=max |
114 | | - type=registry,ref=${{ env.container-registry }}/$REPO_NAME:main-buildcache,mode=max |
115 | | - ${{ steps.cache_from.outputs.LAST_PRS }} |
116 | | - cache-to: | |
117 | | - type=registry,ref=${{ env.container-registry }}/$REPO_NAME:${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').number || 0 }}-buildcache,mode=max |
118 | | - no-cache: false |
119 | | - tags: | |
120 | | - ${{ env.container-registry }}/$REPO_NAME:${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').number || 0 }} |
121 | | - ${{ env.container-registry }}/$REPO_NAME:${{ github.sha }} |
122 | | - secrets: | |
123 | | - GH_TOKEN=${{ secrets.PAT }} |
| 107 | + - name: Build and push |
| 108 | + uses: docker/build-push-action@v5 |
| 109 | + env: |
| 110 | + REPO_NAME: ${{ inputs.repo_name }} |
| 111 | + with: |
| 112 | + file: ./docker/Dockerfile.ci |
| 113 | + push: true |
| 114 | + context: . |
| 115 | + build-args: | |
| 116 | + BASE_IMAGE=pytorch |
| 117 | + cache-from: | |
| 118 | + type=registry,ref=${{ env.container-registry }}/$REPO_NAME:${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').number || 0 }}-buildcache,mode=max |
| 119 | + type=registry,ref=${{ env.container-registry }}/$REPO_NAME:main-buildcache,mode=max |
| 120 | + ${{ steps.cache_from.outputs.LAST_PRS }} |
| 121 | + cache-to: | |
| 122 | + type=registry,ref=${{ env.container-registry }}/$REPO_NAME:${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').number || 0 }}-buildcache,mode=max |
| 123 | + no-cache: false |
| 124 | + tags: | |
| 125 | + ${{ env.container-registry }}/$REPO_NAME:${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').number || 0 }} |
| 126 | + ${{ env.container-registry }}/$REPO_NAME:${{ github.sha }} |
| 127 | + secrets: | |
| 128 | + GH_TOKEN=${{ secrets.PAT }} |
0 commit comments