Skip to content

Commit

Permalink
Updating homControl.sh and homControl.py to support --build option
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryGF committed Dec 5, 2023
1 parent 7103e6e commit 51b1a30
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/homControl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion docker/homControl/app/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def main():
🧭 Use the sidebar to glide through the app. Begin with setting up your Terraform configurations and then march ahead to plan and deploy your modules.
Ready. Set. Automate! 🤖
""")

if __name__ == "__main__":
Expand Down
11 changes: 10 additions & 1 deletion homControl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
# Get the directory of the current script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Running on: $DIR"

# Check for --build argument
BUILD_FLAG=""
for arg in "$@"; do
if [ "$arg" = "--build" ]; then
BUILD_FLAG="--build"
fi
done

# Set the path to the Python script based on the directory of the current script
SCRIPT_PATH="$DIR/scripts/python/homControl.py"

Expand All @@ -25,7 +34,7 @@ echo "Moving to $(dirname "$SCRIPT_PATH")"

# Run the Python script with pipenv
if [ -f "$SCRIPT_PATH" ]; then
pipenv run python "$(basename "$SCRIPT_PATH")"
pipenv run python "$(basename "$SCRIPT_PATH")" $BUILD_FLAG
else
echo "Error: Python script not found at $SCRIPT_PATH"
exit 1
Expand Down
23 changes: 14 additions & 9 deletions scripts/python/homControl.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import docker
import webbrowser
import argparse

def main():
def main(build_image):
# Initialize the Docker client
client = docker.from_env()

Expand All @@ -29,13 +30,14 @@ def main():
except docker.errors.NotFound:
print("No existing container found with the name 'homcontrol_container'.")

print("Building Docker image...")
try:
# Build the Docker image
client.images.build(path="../../docker/homControl", tag="terrahom/homcontrol")
except docker.errors.BuildError as e:
print("Error during build:", e)
return
if build_image:
print("Building Docker image...")
try:
# Build the Docker image
client.images.build(path="../../docker/homControl", tag="terrahom/homcontrol")
except docker.errors.BuildError as e:
print("Error during build:", e)
return

print("Starting Docker container...")
# Run the Docker container with the specified configurations
Expand Down Expand Up @@ -64,4 +66,7 @@ def main():
exit(0)

if __name__ == "__main__":
main()
parser = argparse.ArgumentParser()
parser.add_argument("--build", action="store_true", help="Build the Docker image")
args = parser.parse_args()
main(args.build)

0 comments on commit 51b1a30

Please sign in to comment.