Skip to content

Commit 899578f

Browse files
author
Changming Sun
committed
test
1 parent 373b9e2 commit 899578f

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Build Docker Image'
2+
description: 'Builds a Docker image and optionally pushes it to Azure Container Registry.'
3+
inputs:
4+
Dockerfile:
5+
description: 'Path to the Dockerfile.'
6+
required: true
7+
DockerBuildArgs:
8+
description: 'Arguments to pass to docker build.'
9+
required: false
10+
default: ''
11+
Repository:
12+
description: 'The image repository name.'
13+
required: true
14+
15+
runs:
16+
using: 'node20'
17+
main: 'index.js'
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// index.js (or main.js - see package.json "main" field)
2+
3+
const core = require('@actions/core');
4+
const exec = require('@actions/exec');
5+
const github = require('@actions/github');
6+
7+
async function run() {
8+
try {
9+
// Get inputs
10+
const dockerfile = core.getInput('Dockerfile', { required: true });
11+
const dockerBuildArgs = core.getInput('DockerBuildArgs'); // Defaults to "" if not provided.
12+
const repository = core.getInput('Repository', { required: true });
13+
14+
const context = dockerfile.substring(0, dockerfile.lastIndexOf('/')) || '.'; // Extract directory of Dockerfile. or .
15+
core.info(`Dockerfile context directory: ${context}`);
16+
17+
// Determine if we should use the cache. Avoid cache if it's a PR from a fork.
18+
const isPullRequest = github.context.eventName === 'pull_request';
19+
const isFork = isPullRequest && github.context.payload.pull_request.head.repo.fork;
20+
const useCache = !isFork;
21+
22+
let azLoginRan = false;
23+
24+
if (useCache) {
25+
// Log in to Azure
26+
try {
27+
await exec.exec('az', ['login', '--identity']);
28+
azLoginRan = true;
29+
await exec.exec('az', ['acr', 'login', '-n', 'onnxruntimebuildcache']);
30+
} catch (error) {
31+
core.setFailed(`Azure login or ACR login failed: ${error.message}`);
32+
return; // Exit if login fails. Critical error.
33+
}
34+
}
35+
36+
37+
// Build arguments for get_docker_image.py
38+
let scriptArgs = [
39+
'tools/ci_build/get_docker_image.py',
40+
'--dockerfile', dockerfile,
41+
'--context', context,
42+
'--docker-build-args', dockerBuildArgs,
43+
'--repository', repository,
44+
];
45+
46+
if (useCache) {
47+
scriptArgs.push('--container-registry', 'onnxruntimebuildcache');
48+
scriptArgs.push('--use_imagecache');
49+
}
50+
51+
52+
// Execute the Python script.
53+
try {
54+
await exec.exec('python3', scriptArgs);
55+
} catch (error) {
56+
core.setFailed(`Docker build failed: ${error.message}`);
57+
return; // Exit if docker build failed.
58+
}
59+
60+
// Logout from Azure ACR (if we logged in)
61+
if (azLoginRan) {
62+
try {
63+
await exec.exec('az', ['acr', 'logout', '-n', 'onnxruntimebuildcache']);
64+
} catch (error) {
65+
core.warning(`Azure ACR logout failed: ${error.message}`); // Warning, not critical.
66+
}
67+
}
68+
69+
core.info('Docker build completed successfully.');
70+
71+
} catch (error) {
72+
core.setFailed(error.message);
73+
}
74+
}
75+
76+
run();

.github/workflows/linux_ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Linux CI
2+
3+
on:
4+
push:
5+
branches: [ main, 'rel-*', 'snnn/linux_ci']
6+
pull_request:
7+
branches: [ main ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Set up Python 3.x
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.x'
25+
26+
- name: Install dependencies
27+
run: python -m pip install -r requirements-dev.txt
28+
29+
- name: Build Docker Image
30+
uses: ./.github/actions/build-docker-image # Path to your action directory
31+
with:
32+
Dockerfile: ${{ github.workspace }}/tools/ci_build/github/linux/docker/inference/x86_64/default/cpu/Dockerfile
33+
DockerBuildArgs: "--build-arg BUILD_UID=$( id -u ) --container-registry onnxruntimebuildcache --repository onnxruntimecpubuildcentos8x64"
34+
Repository: 'onnxruntimecpubuildcentos8x64'
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed for context

0 commit comments

Comments
 (0)