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

Provide dockerx setup for docker builds #1194

Merged
merged 27 commits into from
Oct 22, 2024
Merged

Conversation

sikehish
Copy link
Contributor

@sikehish sikehish commented Oct 18, 2024

This address #1064.
A shell script was created to handle building and pushing multi-architecture images using docker buildx.

Changes

This PR introduces a shell script (buildx_and_push.sh) to automate the process of building and pushing Docker images for multiple architectures using docker buildx. It ensures that the Docker images are always built with the latest version of the sf-hamilton-ui library from PyPI.

Key Changes:

  1. Multi-architecture support:

    • Builds images for multiple platforms (linux/amd64, linux/arm64).
  2. Automated version management:

    • The script dynamically fetches the latest sf-hamilton-ui version from PyPI.
    • The fetched version is used to tag Docker images, ensuring that both the versioned tag and latest tag are always in sync with the current release.
  3. Builder instance setup:

    • Ensures that Docker Buildx is enabled and uses a named builder instance (hamilton-builder).
  4. Image tagging and pushing:

    • Tags both backend and frontend images with:
      • The latest sf-hamilton-ui version.
      • The latest tag.

How I Tested This

  1. Environment:

    • Tested on a local machine with Docker Buildx enabled.
  2. Test Cases:

    • Checked the output to confirm that the fetched version from PyPI was used for tagging the images.
    • Built and pushed the backend and frontend images successfully using:
      ./buildx_and_push.sh
    • Verified that both versioned and latest tags were pushed to the repository.
  3. Validation:

    • Confirmed that the following tags were pushed:
      • dagworks/ui-backend:<fetched_version>
      • dagworks/ui-backend:latest
      • dagworks/ui-frontend:<fetched_version>
      • dagworks/ui-frontend:latest

Notes

  • Ensure Docker Buildx is installed before running the script. The setup logic in the script will handle creating the builder instance if it is not already configured.

  • Why this change is needed: This automation ensures consistency between the versioned tag and the latest tag. It also simplifies multi-architecture builds and makes them easier to manage across multiple platforms.

  • PR has an informative and human-readable title (this will be pulled into the release notes)

  • Changes are limited to a single goal (no scope creep)

  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.

  • Any change in functionality is tested

  • New functions are documented (with a description, list of inputs, and expected output)

  • Placeholder code is flagged / future TODOs are captured in comments

  • Project documentation has been updated if adding/changing functionality.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to 19d2d98 in 21 seconds

More details
  • Looked at 34 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. ui/buildx_and_push.sh:7
  • Draft comment:
    Ensure that jq is installed before using it to parse JSON. You can add a check at the beginning of the script to verify its presence and provide a helpful error message if it's missing. Additionally, consider adding error handling for the curl command to ensure the script behaves correctly if the request to PyPI fails. For example, check if the response is empty or invalid and handle it appropriately.
  • Reason this comment was not posted:
    Comment did not seem useful.
2. ui/buildx_and_push.sh:5
  • Draft comment:
    Consider adding this script to the Sphinx documentation under docs/ to guide users on building and pushing multi-architecture Docker images.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The script is straightforward and doesn't have repeated code, except for the docker buildx command which is slightly different for frontend and backend. The script is not overly complicated, so comments are not necessary beyond what is already provided. Variable names are descriptive. There are no secrets or credentials in the code. The script follows a single responsibility of building and pushing docker images. The function naming is consistent. Sensitive data is not logged. The script could be added to the documentation for users who want to build and push docker images.

Workflow ID: wflow_SV8PcasBZOtbB0DH


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

ui/buildx_and_push.sh Show resolved Hide resolved
Copy link
Collaborator

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

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

Looks great!

what would a github action look like to get this to run once a new sf-hamilton-ui version was published?

@sikehish
Copy link
Contributor Author

Looks great!

what would a github action look like to get this to run once a new sf-hamilton-ui version was published?
I'll be working on the action soon. But I'm currently building the images without the env variables/args. What do I do? Do I add multi arch builds to the docker compose file, or is there any other approach that I need to take?

@skrawcz
Copy link
Collaborator

skrawcz commented Oct 19, 2024

I'll be working on the action soon. But I'm currently building the images without the env variables/args. What do I do? Do I add multi arch builds to the docker compose file, or is there any other approach that I need to take?

Sorry I'm not following. The multi-arch builds would just use your script here right?

@sikehish
Copy link
Contributor Author

I'll be working on the action soon. But I'm currently building the images without the env variables/args. What do I do? Do I add multi arch builds to the docker compose file, or is there any other approach that I need to take?

Sorry I'm not following. The multi-arch builds would just use your script here right?

Yes. Just wanted to ask if you if the script is satisfying the requirements.

@skrawcz
Copy link
Collaborator

skrawcz commented Oct 19, 2024

Yes. Just wanted to ask if you if the script is satisfying the requirements.

Script looks great thanks. I haven't run it yet to verify though; so I assume it works right now.

@sikehish
Copy link
Contributor Author

sikehish commented Oct 19, 2024

Looks great!

what would a github action look like to get this to run once a new sf-hamilton-ui version was published?

Looks great!

what would a github action look like to get this to run once a new sf-hamilton-ui version was published?

Hi @skrawcz . Ive created a new workflow, tested it on my fork, and it's building and pushing those images. So it's working fine. Let me know if I need to make any changes :)

@sikehish
Copy link
Contributor Author

Hi @skrawcz
I've made the reuqested changes. Let me know if anything else needs to be changed. I've tested it on my local fork, and its working fine.

Copy link
Collaborator

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

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

just tried it - seems to work - i just had to change two small things

ui/buildx_and_push.sh Outdated Show resolved Hide resolved
ui/buildx_and_push.sh Outdated Show resolved Hide resolved
@sikehish
Copy link
Contributor Author

just tried it - seems to work - i just had to change two small things

Oh Okay. Anything else that I need to work on?

@skrawcz
Copy link
Collaborator

skrawcz commented Oct 22, 2024

@sikehish just need to fix up the whitespace pre-commit issues. Otherwise this is ready to merge. Thanks!

e.g. pip install pre-commit
pre-commit run --all-files
I think those are the commands

@sikehish
Copy link
Contributor Author

@sikehish just need to fix up the whitespace pre-commit issues. Otherwise this is ready to merge. Thanks!

e.g. pip install pre-commit pre-commit run --all-files I think those are the commands

I have executed the above command. Does everything look good now?
Thank you for the opportunity:)) It was fun working on this issue.

@skrawcz skrawcz merged commit bc7cbbf into DAGWorks-Inc:main Oct 22, 2024
22 of 24 checks passed
@skrawcz skrawcz added hacktoberfest Hacktoberfest issues hacktoberfest2024 hacktoberfest 2024 labels Oct 22, 2024
@skrawcz skrawcz linked an issue Oct 22, 2024 that may be closed by this pull request
sikehish pushed a commit to sikehish/hamilton that referenced this pull request Oct 29, 2024
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182901 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182885 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182883 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182877 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182862 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182842 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182748 +0530

Update materialization.rst

Fix mutate docstring

Docstring raised Pytest escape error due to /* so we wrap it in quotes.

Improve pipe_output first node naming

Current name convention is very prone to name clashes with user naming.

We assign the same naming convention using namespace.raw to indicate the
first node.

Provide dockerx setup for docker builds (DAGWorks-Inc#1194)

This change adds a script for multi-platform docker builds as
well as a github workflow to automatically build them when a new sf-hamilton-ui version
has been published.

Squashed commits:

* Created buildx_and_push.sh script in ui directory to create multi-platform docker builds

* Fixed content related issue in buildx_and_push.sh

* buildx_and_push.sh: Added functionality to fecth the latest version from PyPi

* buildx_and_push.sh: Added check_buildx_installed

* buildx_and_push.sh: Added check_buildx_installed

* buildx_and_push.sh: Enhanced error handling(checking if jq exists, curl response handling and docker buildx error handling)

* Adding build args to buildx_and_push.sh

* buildx_and_push.sh: Changes made to test a new workflow

* Created a new workflow: hamilton-ui-build-and-push

* buildx_and_push.sh: echo statement added to debug

* buildx_and_push.sh: cd'ing to the directory(ui) where the shell script is located to prevent context related errors in workflow.

* hamilton-ui-build-and-push.yml: Added Docker Hub login step

* buildx_and_push.sh: added dagworks dockerhub username; workflow worked on the fork.

* hamilton-ui-build-and-push.yml: Replaced previous version from cache with version tag from Dockerhub image.

* buildx_and_push.sh: Changed dockerhub username for testing

* hamilton-ui-build-and-push.yml: Minor change in the docker registry URL(version)

* hamilton-ui-build-and-push.yml: Minor change in the "Fetch highest version from Docker Hub" step's shell script

* hamilton-ui-build-and-push.yml: Replacing deprecated set-output with GITHUB_OUTPUT

* hamilton-ui-build-and-push.yml: Conditional execution of steps implemented

* Undid change in dockerhub username

* Update ui/buildx_and_push.sh

* Update ui/buildx_and_push.sh

* chore: fix pre-commit whitespace issues

---------

Co-authored-by: Stefan Krawczyk <stefan@dagworks.io>

Fix `keep_dot` propagation in `Driver` display functions

Bumps hamilton version from 1.81.0 to 1.81.1

fix: caching `SQLiteMetadataStore.get_run_ids()` (DAGWorks-Inc#1205)

* fixed .get_run_ids() and standardized .get_run() + tests

* fixed docstrings formatting errors

---------

Co-authored-by: zilto <tjean@DESKTOP-V6JDCS2>

Bumps hamilton version from 1.81.1 to 1.81.2

buildx_and_push.sh: Changes made to test a new workflow

buildx_and_push.sh: echo statement added to debug

buildx_and_push.sh: added dagworks dockerhub username; workflow worked on the fork.

buildx_and_push.sh: Changed dockerhub username for testing

Undid change in dockerhub username

Created a new update external blogs script which updates External Blogs section in learning_resources.md with the latest blogs(with a date cutoff)

Added docstring in update_blogs_in_learning_resources.py

chore: fix pre-commit whitespace issues

update_blogs_in_learning_resources.py: Added a "print to standard out" option (using --print flag)

update_blogs_in_learning_resources.py: Argument parser with expaned help text

update_blogs_in_learning_resources.py: Expanded docstring

Fixes whitespace and small docs typo

buildx_and_push.sh: Changes made to test a new workflow

buildx_and_push.sh: echo statement added to debug

hamilton-ui-build-and-push.yml: Added Docker Hub login step

buildx_and_push.sh: added dagworks dockerhub username; workflow worked on the fork.

buildx_and_push.sh: Changed dockerhub username for testing

hamilton-ui-build-and-push.yml: Minor change in the "Fetch highest version from Docker Hub" step's shell script

hamilton-ui-build-and-push.yml: Replacing deprecated set-output with GITHUB_OUTPUT

chore: fix pre-commit whitespace issues

Update ui/buildx_and_push.sh

Update ui/buildx_and_push.sh

Fixes whitespace and small docs typo
skrawcz pushed a commit to sikehish/hamilton that referenced this pull request Oct 30, 2024
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182901 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182885 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182883 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182877 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182862 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182842 +0530

parent 7b9f52a
author Dimitry Foures <dimitry.foures@gmail.com> 1729160952 +0100
committer sikehish <hisham0502@gmail.com> 1730182748 +0530

Update materialization.rst

Fix mutate docstring

Docstring raised Pytest escape error due to /* so we wrap it in quotes.

Improve pipe_output first node naming

Current name convention is very prone to name clashes with user naming.

We assign the same naming convention using namespace.raw to indicate the
first node.

Provide dockerx setup for docker builds (DAGWorks-Inc#1194)

This change adds a script for multi-platform docker builds as
well as a github workflow to automatically build them when a new sf-hamilton-ui version
has been published.

Squashed commits:

* Created buildx_and_push.sh script in ui directory to create multi-platform docker builds

* Fixed content related issue in buildx_and_push.sh

* buildx_and_push.sh: Added functionality to fecth the latest version from PyPi

* buildx_and_push.sh: Added check_buildx_installed

* buildx_and_push.sh: Added check_buildx_installed

* buildx_and_push.sh: Enhanced error handling(checking if jq exists, curl response handling and docker buildx error handling)

* Adding build args to buildx_and_push.sh

* buildx_and_push.sh: Changes made to test a new workflow

* Created a new workflow: hamilton-ui-build-and-push

* buildx_and_push.sh: echo statement added to debug

* buildx_and_push.sh: cd'ing to the directory(ui) where the shell script is located to prevent context related errors in workflow.

* hamilton-ui-build-and-push.yml: Added Docker Hub login step

* buildx_and_push.sh: added dagworks dockerhub username; workflow worked on the fork.

* hamilton-ui-build-and-push.yml: Replaced previous version from cache with version tag from Dockerhub image.

* buildx_and_push.sh: Changed dockerhub username for testing

* hamilton-ui-build-and-push.yml: Minor change in the docker registry URL(version)

* hamilton-ui-build-and-push.yml: Minor change in the "Fetch highest version from Docker Hub" step's shell script

* hamilton-ui-build-and-push.yml: Replacing deprecated set-output with GITHUB_OUTPUT

* hamilton-ui-build-and-push.yml: Conditional execution of steps implemented

* Undid change in dockerhub username

* Update ui/buildx_and_push.sh

* Update ui/buildx_and_push.sh

* chore: fix pre-commit whitespace issues

---------

Co-authored-by: Stefan Krawczyk <stefan@dagworks.io>

Fix `keep_dot` propagation in `Driver` display functions

Bumps hamilton version from 1.81.0 to 1.81.1

fix: caching `SQLiteMetadataStore.get_run_ids()` (DAGWorks-Inc#1205)

* fixed .get_run_ids() and standardized .get_run() + tests

* fixed docstrings formatting errors

---------

Co-authored-by: zilto <tjean@DESKTOP-V6JDCS2>

Bumps hamilton version from 1.81.1 to 1.81.2

buildx_and_push.sh: Changes made to test a new workflow

buildx_and_push.sh: echo statement added to debug

buildx_and_push.sh: added dagworks dockerhub username; workflow worked on the fork.

buildx_and_push.sh: Changed dockerhub username for testing

Undid change in dockerhub username

Created a new update external blogs script which updates External Blogs section in learning_resources.md with the latest blogs(with a date cutoff)

Added docstring in update_blogs_in_learning_resources.py

chore: fix pre-commit whitespace issues

update_blogs_in_learning_resources.py: Added a "print to standard out" option (using --print flag)

update_blogs_in_learning_resources.py: Argument parser with expaned help text

update_blogs_in_learning_resources.py: Expanded docstring

Fixes whitespace and small docs typo

buildx_and_push.sh: Changes made to test a new workflow

buildx_and_push.sh: echo statement added to debug

hamilton-ui-build-and-push.yml: Added Docker Hub login step

buildx_and_push.sh: added dagworks dockerhub username; workflow worked on the fork.

buildx_and_push.sh: Changed dockerhub username for testing

hamilton-ui-build-and-push.yml: Minor change in the "Fetch highest version from Docker Hub" step's shell script

hamilton-ui-build-and-push.yml: Replacing deprecated set-output with GITHUB_OUTPUT

chore: fix pre-commit whitespace issues

Update ui/buildx_and_push.sh

Update ui/buildx_and_push.sh

Fixes whitespace and small docs typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Hacktoberfest issues hacktoberfest2024 hacktoberfest 2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide dockerx setup for docker builds
2 participants