Use Docker images locally and in CI #176
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Generated Files | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
check-generate: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
actions: read | |
packages: read | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Determine Docker image | |
id: docker-image | |
run: | | |
# Check if Dockerfile.ci or build workflow was modified | |
git fetch origin ${{ github.base_ref }} | |
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^(Dockerfile\.ci|\.github/workflows/build-ci-image\.yml)$'; then | |
echo "modified=true" >> $GITHUB_OUTPUT | |
echo "image=ghcr.io/flyteorg/flyte/ci:pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | |
echo "📦 Dockerfile.ci modified - will use PR-specific image" | |
else | |
echo "modified=false" >> $GITHUB_OUTPUT | |
echo "image=ghcr.io/flyteorg/flyte/ci:v2" >> $GITHUB_OUTPUT | |
echo "📦 Using default v2 image" | |
fi | |
- name: Wait for Docker image build workflow | |
if: steps.docker-image.outputs.modified == 'true' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const maxAttempts = 60; // 20 minutes max | |
const delaySeconds = 20; | |
console.log('⏳ Waiting for Docker image build workflow to complete...'); | |
for (let attempt = 0; attempt < maxAttempts; attempt++) { | |
// Get workflow runs for this PR | |
const { data: runs } = await github.rest.actions.listWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'build-ci-image.yml', | |
event: 'pull_request', | |
per_page: 10 | |
}); | |
// Find the run for this PR | |
const prRun = runs.workflow_runs.find(run => | |
run.head_sha === context.payload.pull_request.head.sha | |
); | |
if (prRun) { | |
console.log(`Found workflow run: ${prRun.html_url}`); | |
console.log(`Status: ${prRun.status}, Conclusion: ${prRun.conclusion}`); | |
if (prRun.status === 'completed') { | |
if (prRun.conclusion === 'success') { | |
console.log('✅ Docker image build completed successfully!'); | |
return; | |
} else { | |
core.setFailed(`❌ Docker image build failed with conclusion: ${prRun.conclusion}`); | |
return; | |
} | |
} | |
console.log(`Attempt ${attempt + 1}/${maxAttempts}: Build still running, waiting ${delaySeconds} seconds...`); | |
} else { | |
console.log(`Attempt ${attempt + 1}/${maxAttempts}: Build not started yet, waiting ${delaySeconds} seconds...`); | |
} | |
await new Promise(resolve => setTimeout(resolve, delaySeconds * 1000)); | |
} | |
core.setFailed('❌ Timeout waiting for Docker image build to complete'); | |
- name: Login to GHCR | |
if: steps.docker-image.outputs.modified == 'true' | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Pull Docker image | |
if: steps.docker-image.outputs.modified == 'true' | |
run: | | |
IMAGE="${{ steps.docker-image.outputs.image }}" | |
echo "📦 Pulling image: $IMAGE" | |
docker pull "$IMAGE" | |
- name: Run checks in container | |
run: | | |
IMAGE="${{ steps.docker-image.outputs.image }}" | |
echo "Using image: $IMAGE" | |
docker run --rm \ | |
-v ${{ github.workspace }}:/workspace \ | |
-w /workspace \ | |
-e SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 \ | |
-e UV_PROJECT_ENVIRONMENT=/tmp/flyte-venv \ | |
"$IMAGE" \ | |
bash -c " | |
git config --global --add safe.directory /workspace && | |
cd gen/python && uv sync --all-groups --frozen && cd ../.. && | |
make download_tooling && | |
make gen && | |
git diff --exit-code || (echo 'Generated files are out of date. Run \`make gen\` and commit changes.' && exit 1) && | |
make build-crate | |
" | |