Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container2step #300

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

thomas-robinson
Copy link
Member

@thomas-robinson thomas-robinson commented Dec 23, 2024

Describe your changes

Adds two-step container build capability to fre make

Issue ticket number and link (if applicable)

#266

Checklist before requesting a review

  • I ran my code
  • I tried to make my code readable
  • I tried to comment my code
  • I wrote a new test, if applicable
  • I wrote new instructions/documentation, if applicable
  • I ran pytest and inspected it's output
  • I ran pylint and attempted to implement some of it's feedback

@thomas-robinson
Copy link
Member Author

Did i break this?

"""
container_plat = CONTAINER_PLAT2[0]
yamlfile_path = f"{TEST_DIR}/{NM_EXAMPLE}/{YAMLFILE}"
create_makefile_script.makefile_create(yamlfile_path,container_plat,TARGET)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try just passing create_makefile_script.makefile_create(yamlfile_path,CONTAINER_PLAT2,TARGET) instead. I'm pretty sure either the platformfre.py or yamlfre.py file is looking for a list that is passed. I used something like container_plat = CONTAINER_PLAT2[0] in some other tests mainly for assertions for directory names I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That worked!

@thomas-robinson thomas-robinson marked this pull request as draft December 23, 2024 18:17
@thomas-robinson
Copy link
Member Author

thomas-robinson commented Dec 23, 2024

This needs an update to the schema submodule. NOAA-GFDL/gfdl_msd_schemas#17

@ilaflott
Copy link
Member

ilaflott commented Jan 17, 2025

NOAA-GFDL/gfdl_msd_schemas#17

was merged! is this still in need of further development? would suggest a quick and local git checkout main; git fetch; git merge main; git push to ensure compatibility with recent changes.

edit: or w/e the exact git command sequence is...

@thomas-robinson thomas-robinson marked this pull request as ready for review January 21, 2025 10:34
@thomas-robinson
Copy link
Member Author

This should be ready now.

except:
p["containerViews"] = False
raise NameError("Platform "+p["name"]+": You must specify the base container you wish to use to build your application")
## Check if this is a 2 step (multi stage) build
try:
p["container2step"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this try/except clause just checking to see if a dictionary's attribute is defined at all? or is it about the boolean value assigned elsewhere?

if it's about being defined- how about using p.get("key"), then checking for None? or catching the KeyError explicitly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of both I think? With some platforms, the container key doesn't even need to be defined. So the try/except checks for if it's even there under a certain platform's information (and not just that it's not defined, being None. If it doesn't exist, it'll set things as empty or False for the next if statement it goes through

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe this could be done a different way that's slightly easier to follow but my brain keeps going back and forth on logic and is confusing itself. Not sure what's the best way

Comment on lines +67 to +70
self.secondstage = ["FROM "+self.stage2base+" as final\n",
"COPY --from=builder "+self.src+" "+self.src+"\n",
"COPY --from=builder "+self.bld+" "+self.bld+"\n",
"ENV PATH=$PATH:"+self.bld+"\n"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might i recommend f-strings for readability generally? with them, this reads like:

self.secondstage = [f"FROM {self.stage2base} as final\n",
                    f"COPY --from=builder {self.src} {self.src}\n",
                    f"COPY --from=builder {self.bld} {self.bld}\n",
                    f"ENV PATH=$PATH:{self.bld}\n"]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree here, f-strings for the win

Comment on lines +134 to +153
def test_run_fremake_build_script_creation_container():
''' checks container build script creation from previous test '''
assert Path("createContainer.sh").exists()

def test_run_fremake_dockerfile_creation_container():
''' checks dockerfile creation from previous test '''
assert Path("Dockerfile").exists()

def test_run_fremake_checkout_script_creation_container():
''' checks checkout script creation from previous test '''
assert Path(f"tmp/{CONTAINER_PLAT2[0]}/checkout.sh").exists()

def test_run_fremake_makefile_creation_container():
''' checks makefile creation from previous test '''
assert Path(f"tmp/{CONTAINER_PLAT2[0]}/Makefile").exists()

def test_run_fremake_run_script_creation_container():
''' checks (internal) container run script creation from previous test '''
assert Path(f"tmp/{CONTAINER_PLAT2[0]}/execrunscript.sh").exists()

Copy link
Member

@ilaflott ilaflott Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these shouldn't be separate- lets do something like

def test_run_fremake_container():
    run_fremake_script.fremake_run(
        YAMLPATH, CONTAINER_PLAT2, TARGET, False, 1, True, False, VERBOSE)
    assert all( [ condition1,
                  condition2,
                  ...
                  conditionN ] )

# tests container 2 stage build script/makefile/dockerfile creation
def test_run_fremake_container():
'''run run-fremake with options for containerized build'''
run_fremake_script.fremake_run(YAMLPATH, CONTAINER_PLAT2, TARGET, False, 1, True, False, VERBOSE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any return-codes to check?

Copy link
Member

@ilaflott ilaflott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna approve b.c. most of what i am pointing out is either style or readability driven, and the changes seem to function as intended given the test(s).

i'm not a fre make expert, but certain patterns in this subtool should be revisited and rewritten for maintainability's sake. E.g., class __init__ routines seem like a prime target.

@@ -137,3 +150,17 @@ def getContainerImage(self,name):
for p in self.yaml:
if p["name"] == name:
return p["containerBase"]
def is2stepContainer(self,name):
Copy link
Collaborator

@singhd789 singhd789 Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function used anywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants