1- # Copyright 2025 Google LLC
1+ # Copyright 2023-2026 Google LLC
22
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
2828 build_mode :
2929 required : true
3030 type : string
31- dockerfile :
32- required : true
33- type : string
3431 maxtext_sha :
3532 required : true
3633 type : string
37- image_date :
38- required : false
39- type : string
4034 workflow :
4135 required : false
4236 type : string
4539 required : false
4640 type : string
4741 default : ' '
42+ include_test_assets :
43+ required : false
44+ type : boolean
45+ default : false
4846 secrets :
4947 HF_TOKEN :
5048 required : true
@@ -54,7 +52,7 @@ permissions:
5452
5553jobs :
5654 build_and_push :
57- runs-on : linux-x86-n2-16-buildkit
55+ runs-on : ubuntu-latest
5856 container : google/cloud-sdk:524.0.0
5957 if : >
6058 github.event_name == 'release' ||
@@ -89,54 +87,69 @@ jobs:
8987 echo "workflow: ${{ inputs.workflow }}"
9088 echo "build_mode: ${{ inputs.build_mode }}"
9189 echo "image_name: ${{ inputs.image_name }}"
92- echo "dockerfile: ${{ inputs.dockerfile }}"
93-
94- - name : Checkout MaxText
95- uses : actions/checkout@v5
96- if : steps.check.outputs.should_run == 'true'
97- with :
98- # This ensures that every job clones the exact same commit as "setup" job
99- ref : ${{ inputs.maxtext_sha }}
100-
101- - name : Mark git repositories as safe
102- run : git config --global --add safe.directory ${GITHUB_WORKSPACE}
103- if : steps.check.outputs.should_run == 'true'
10490
10591 - name : Configure Docker
10692 run : gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
10793 if : steps.check.outputs.should_run == 'true'
10894
95+ - name : Configure gcloud project
96+ run : gcloud config set project tpu-prod-env-multipod
97+ if : steps.check.outputs.should_run == 'true'
98+
10999 - name : Set up Docker BuildX
110100 uses : docker/setup-buildx-action@v3.11.1
111101 if : steps.check.outputs.should_run == 'true'
102+
103+ - name : Download MaxText wheel
104+ uses : actions/download-artifact@v4
105+ if : steps.check.outputs.should_run == 'true'
112106 with :
113- driver : remote
114- endpoint : tcp://localhost:1234
107+ name : maxtext-wheel
115108
116- - name : Build and push Docker image
117- uses : docker/build-push-action@v6
109+ - name : Install uv and set the Python version
110+ uses : astral-sh/setup-uv@v7
118111 if : steps.check.outputs.should_run == 'true'
119112 with :
120- push : true
121- context : .
122- file : ${{ inputs.dockerfile }}
123- tags : gcr.io/tpu-prod-env-multipod/${{ inputs.image_name }}:${{ github.run_id }}
124- cache-from : type=gha
125- outputs : type=image,compression=zstd,force-compression=true
126- build-args : |
127- DEVICE=${{ inputs.device }}
128- MODE=${{ inputs.build_mode }}
113+ python-version : ' 3.12'
114+ enable-cache : true
115+
116+ - name : Install MaxText wheel
117+ if : steps.check.outputs.should_run == 'true'
118+ shell : bash
119+ run : |
120+ uv venv --seed
121+ source .venv/bin/activate
122+ maxtext_wheel=$(ls maxtext-*-py3-none-any.whl 2>/dev/null)
123+ uv pip install ${maxtext_wheel}[runner] --resolution=lowest
124+
125+ - name : Build and push Docker image
126+ if : steps.check.outputs.should_run == 'true'
127+ shell : bash
128+ env :
129+ IMAGE_TAG : " gcr.io/tpu-prod-env-multipod/${{ inputs.image_name }}:${{ github.run_id }}"
130+ INCLUDE_TEST_ASSETS : ${{ inputs.include_test_assets }}
131+ run : |
132+ source .venv/bin/activate
133+
134+ # Add .venv to .dockerignore so it is excluded from the Docker build context
135+ echo ".venv" >> .dockerignore
136+
137+ echo "Building MaxText Docker image..."
138+ build_maxtext_docker_image \
139+ DEVICE=${{ inputs.device }} \
140+ MODE=${{ inputs.build_mode }} \
129141 WORKFLOW=${{ inputs.workflow }}
130- PACKAGE_DIR=./src
131- JAX_VERSION=NONE
132- LIBTPU_VERSION=NONE
133- INCLUDE_TEST_ASSETS=true
142+
143+ echo "Pushing MaxText Docker image..."
144+ upload_maxtext_docker_image \
145+ CLOUD_IMAGE_NAME=${{ inputs.image_name }}
134146
135147 - name : Add tags to Docker image
136148 if : steps.check.outputs.should_run == 'true'
137149 shell : bash
138150 run : |
139151 SOURCE_IMAGE="gcr.io/tpu-prod-env-multipod/${INPUTS_IMAGE_NAME}"
152+
140153 TEMP_IMG="${SOURCE_IMAGE}:${{ github.run_id }}"
141154
142155 if [[ $INPUTS_VERSION_NAME ]]; then
@@ -146,16 +159,28 @@ jobs:
146159 echo "Tagging docker images corresponding to nightly release..."
147160
148161 # Add date tag
149- gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:${INPUTS_IMAGE_DATE}" --quiet
162+ IMAGE_DATE="$(date +%Y-%m-%d)"
163+ gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:$IMAGE_DATE" --quiet
150164
151165 # Convert date to YYYYMMDD format
152- clean_date=$(echo "${INPUTS_IMAGE_DATE} " | sed 's/[-:]//g' | cut -c1-8)
166+ clean_date=$(echo "$IMAGE_DATE " | sed 's/[-:]//g' | cut -c1-8)
153167
154168 # Add MaxText tag
155169 gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:maxtext_${MAXTEXT_SHA}_${clean_date}" --quiet
156170 fi
157171 env :
158172 INPUTS_IMAGE_NAME : ${{ inputs.image_name }}
159- INPUTS_IMAGE_DATE : ${{ inputs.image_date }}
160173 INPUTS_VERSION_NAME : ${{ inputs.version_name }}
161174 MAXTEXT_SHA : ${{ inputs.maxtext_sha }}
175+
176+ promote_image :
177+ needs : build_and_push
178+ runs-on : ubuntu-latest
179+ steps :
180+ - name : Promote image
181+ uses : ./.github/workflows/promote_docker_image.yml
182+ with :
183+ image_name : ${{ inputs.image_name }}
184+ image_tag : ${{ github.run_id }}
185+ device : ${{ inputs.device }}
186+ workflow : ${{ inputs.workflow }}
0 commit comments