Skip to content

Image Rdma Tools

Image Rdma Tools #161

name: Image Rdma Tools
env:
IMAGE_NAME: rdma-tools
DOCKERFILE_PATH: rdma-tools/image
GEN_DOCKERFILE_SCRIPT: rdma-tools/image/generateDockerfile.sh
on:
push:
branches:
- 'main'
paths:
- rdma-tools/image/**
pull_request_target:
types:
- opened
- synchronize
- reopened
paths:
# can not use env here
- rdma-tools/image/**
workflow_dispatch:
inputs:
ref:
description: 'compile the image based on the sha or branch of code'
required: true
default: main
permissions: write-all
jobs:
get_info:
runs-on: ubuntu-latest
outputs:
code_sha: ${{ env.code_sha }}
push_image: ${{ env.push_image }}
build_platform: ${{ env.build_platform }}
upload_artifact: ${{ env.upload_artifact }}
image_tag: ${{ env.image_tag }}
image_name: ${{ env.image_name }}
dockerfile_dirctory: ${{ env.dockerfile_dirctory }}
generateDockerfileScript: ${{ env.generateDockerfileScript }}
steps:
- name: get information
run: |
echo '${{ toJSON(github) }}'
echo "image_name=${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
echo "build_platform=linux/amd64" >> $GITHUB_ENV
echo "upload_artifact=false" >> $GITHUB_ENV
echo "dockerfile_dirctory=${{ env.DOCKERFILE_PATH }}" >> $GITHUB_ENV
echo "generateDockerfileScript=${{ env.GEN_DOCKERFILE_SCRIPT }}" >> $GITHUB_ENV
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "call by workflow_dispatch"
echo "code_sha=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
echo "push_image=true" >> $GITHUB_ENV
elif ${{ github.event_name == 'push' }} ; then
echo "call by push tag"
echo "code_sha=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "push_image=true" >> $GITHUB_ENV
else
echo "call by PR"
echo "use sha ${{ github.event.pull_request.head.sha }} , by pr"
echo "code_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
echo "push_image=false" >> $GITHUB_ENV
fi
- name: Checkout Source Code
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ env.code_sha }}
- name: Generate Dockerfile
run: |
set -x
cd ${{ env.DOCKERFILE_PATH }}
chmod +x ./generateDockerfile.sh
source ./generateDockerfile.sh
image_tag=$( git ls-tree --full-tree HEAD -- ${{ env.DOCKERFILE_PATH }} | awk '{ print $3 }' )
[ -n "${image_tag}" ] || { echo "error, failed to get image_tag from commit id"; exit 1 ; }
echo "image_tag=${ENV_BASEIMAGE_CUDA_VERISON}-${image_tag}" >> $GITHUB_ENV
call-workflow:
needs: [get_info]
uses: ./.github/workflows/callBuildImage.yaml
with:
code_sha: ${{ needs.get_info.outputs.code_sha }}
push_image: ${{ needs.get_info.outputs.push_image }}
image_name: ${{ needs.get_info.outputs.image_name }}
dockerfile_dirctory: ${{ needs.get_info.outputs.dockerfile_dirctory }}
build_platform: ${{ needs.get_info.outputs.build_platform }}
upload_artifact: ${{ needs.get_info.outputs.upload_artifact }}
image_tag: ${{ needs.get_info.outputs.image_tag }}
generateDockerfileScript: ${{ needs.get_info.outputs.generateDockerfileScript }}
secrets: inherit