1+ # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ name : ' Build Container'
16+ description : ' Build container for validation without publishing'
17+
18+ inputs :
19+ safe_ref_name :
20+ description : ' Safe reference name for container tags'
21+ required : true
22+ nvcr_container_repo :
23+ description : ' Container registry URL'
24+ required : true
25+ container_org :
26+ description : ' Container organization/namespace'
27+ required : true
28+ make_command :
29+ description : ' Make command to run for building (should use docker-build, not docker-publish)'
30+ required : true
31+
32+ runs :
33+ using : ' composite'
34+ steps :
35+ - name : Set up Docker Buildx
36+ uses : docker/setup-buildx-action@v3
37+ with :
38+ driver-opts : network=host
39+
40+ - name : Cache Docker layers
41+ uses : actions/cache@v4
42+ with :
43+ path : /tmp/.buildx-cache
44+ key : ${{ runner.os }}-buildx-pr-${{ github.event.pull_request.head.sha || github.sha }}
45+ restore-keys : |
46+ ${{ runner.os }}-buildx-pr-
47+ ${{ runner.os }}-buildx-
48+
49+ - name : Log in to GitHub Container Registry
50+ uses : docker/login-action@v3
51+ with :
52+ registry : ghcr.io
53+ username : ${{ github.actor }}
54+ password : ${{ github.token }}
55+
56+ - name : Build container (validation only)
57+ shell : bash
58+ env :
59+ SAFE_REF_NAME : ${{ inputs.safe_ref_name }}
60+ NVCR_CONTAINER_REPO : ${{ inputs.nvcr_container_repo }}
61+ NGC_ORG : ${{ inputs.container_org }}
62+ PLATFORMS : ' linux/amd64' # Only amd64 for faster PR validation
63+ DOCKER_BUILDKIT : 1
64+ BUILDX_CACHE_FROM : type=local,src=/tmp/.buildx-cache
65+ BUILDX_CACHE_TO : type=local,dest=/tmp/.buildx-cache-new,mode=max
66+ run : |
67+ echo "Building container for validation..."
68+ ${{ inputs.make_command }}
69+
70+ # Clean up built images to save space
71+ docker image prune -f
72+
73+ # Move cache to prevent it from growing indefinitely
74+ if [ -d "/tmp/.buildx-cache-new" ]; then
75+ rm -rf /tmp/.buildx-cache
76+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
77+ fi
0 commit comments