Skip to content

Commit

Permalink
CI: Automatically extract Docker tag
Browse files Browse the repository at this point in the history
Adds a script to extract Docker image tag from MODULE.bazel.lock file.
Utilizes extracted Docker image tag to execute local flow CI workflow.

Signed-off-by: Illia Vysochyn <[email protected]>
  • Loading branch information
ivysochyn committed Aug 9, 2024
1 parent cf3c01b commit d83aba8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
65 changes: 65 additions & 0 deletions .github/scripts/extract_docker_revision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import json
from pathlib import Path
import sys
from typing import Optional


def find_docker_orfs(data: dict) -> Optional[dict]:
"""
Recursively search for the 'docker_orfs' configuration in
the provided JSON data.
Parameters
----------
data : dict
The JSON data to search for the 'docker_orfs' configuration.
Returns
-------
Optional[dict]
The 'docker_orfs' configuration if found, otherwise None.
"""
if isinstance(data, dict):
if 'docker_orfs' in data:
return data['docker_orfs']
for key, value in data.items():
result = find_docker_orfs(value)
if result:
return result
elif isinstance(data, list):
for item in data:
result = find_docker_orfs(item)
if result:
return result
return None


if __name__ == "__main__":
if len(sys.argv) < 2 or not Path(sys.argv[1]).exists():
print(f"Usage: {sys.argv[0]} <MODULE.bazel>")
exit(1)

with open(sys.argv[1], 'r') as file:
try:
data = json.load(file)
except json.JSONDecodeError:
print(f"Unable to parse JSON data from {sys.argv[1]}")
exit(1)

docker_orfs = find_docker_orfs(data)
if docker_orfs is None or docker_orfs.get('attributes', None) is None:
print("Unable to find 'docker_orfs' configuration in the provided file") # noqa: E501
exit(1)

docker_tag = docker_orfs.get('attributes').get('image', None)
docker_sha256 = docker_orfs.get('attributes').get('sha256', None)

if docker_tag is None or docker_sha256 is None:
print("Unable to find Docker tag or SHA256 in the provided file.")
exit(1)

print(json.dumps({
'image': f"{docker_tag}@sha256:{docker_sha256}",
'tag': docker_tag,
'sha256': docker_sha256
}))
21 changes: 14 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ jobs:
run: |
buildifier -lint warn -r .
generate-config:
name: Generate configs
runs-on: ubuntu-latest
outputs:
docker-tag: ${{ steps.docker-image.outputs.docker-orfs }}
steps:
- name: Checkout megaboom
uses: actions/checkout@v4
- name: Extract Docker tag
id: docker-image
run: echo "docker-orfs=$(python3 .github/scripts/extract_docker_revision.py MODULE.bazel.lock)" | tee -a $GITHUB_OUTPUT

test-make-target:
name: ${{ matrix.STAGE_TARGET }}
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -68,18 +80,15 @@ jobs:
run: |
bazel run --subcommands --verbose_failures --sandbox_debug ${{ matrix.STAGE_TARGET }} -- `pwd`/build
test-target-local:
name: Local flow - test targets
runs-on: ubuntu-22.04
needs: generate-config
container:
# NOTE: Ensure this is kept in sync with MODULE.bazel
image: openroad/orfs:v3.0-1114-g46acc762@sha256:ae4df23391c26bcc48a506f8e0d0da73742d1b6cb3b1dc02f4d5ea71170195b5
image: ${{ fromJSON(needs.generate-config.outputs.docker-tag).image }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
env:
DEBIAN_FRONTEND: "noninteractive"
FLOW_HOME: /OpenROAD-flow-scripts/flow
Expand Down Expand Up @@ -122,8 +131,6 @@ jobs:
defaults:
run:
shell: bash
strategy:
fail-fast: false
env:
DEBIAN_FRONTEND: "noninteractive"
steps:
Expand Down
1 change: 0 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ git_override(
#)

orfs = use_extension("@bazel-orfs//:extension.bzl", "orfs_repositories")
# NOTE: Ensure this is kept in sync with CI
orfs.default(
image = "openroad/orfs:v3.0-1114-g46acc762",
sha256 = "ae4df23391c26bcc48a506f8e0d0da73742d1b6cb3b1dc02f4d5ea71170195b5",
Expand Down

0 comments on commit d83aba8

Please sign in to comment.