From 394778d1974a45b048b26a24a5463fad2467d66e Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Mon, 22 Jan 2024 16:39:24 -0500 Subject: [PATCH] Attempt to fix broker quay image build/push The quay publish job is having trouble installing broker in the container. I simplified the Dockerfile a bit and things are building correctly locally. I also improved the interactive logic with the settings file download, this was initially reproduced by running the container for `--version` while not passing interactive flags to docker. --- .github/workflows/python-publish.yml | 1 + .github/workflows/update_broker_image.yml | 3 +- .gitignore | 1 + Dockerfile | 4 +-- broker/settings.py | 34 ++++++++++++++--------- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 3ac38298..4a25997d 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -9,6 +9,7 @@ jobs: publish: name: Build and Deploy to PyPi runs-on: ubuntu-latest + if: github.repository == 'SatelliteQE/broker' strategy: matrix: # build/push in lowest support python version diff --git a/.github/workflows/update_broker_image.yml b/.github/workflows/update_broker_image.yml index d310630e..32d45896 100644 --- a/.github/workflows/update_broker_image.yml +++ b/.github/workflows/update_broker_image.yml @@ -8,6 +8,7 @@ jobs: broker_container: name: Update Broker container image on Quay. runs-on: ubuntu-latest + if: github.repository == 'SatelliteQE/broker' steps: - name: Checkout @@ -29,6 +30,6 @@ jobs: - name: Build and push image to Quay uses: docker/build-push-action@v5 with: - file: ./Dockerfile + context: . push: true tags: ${{ secrets.QUAY_SERVER }}/${{ secrets.QUAY_NAMESPACE }}/broker:latest diff --git a/.gitignore b/.gitignore index 6e9d040f..70ccf710 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,4 @@ ENV/ # project *settings.yaml inventory.yaml +*.bak diff --git a/Dockerfile b/Dockerfile index bcbff7c4..427eee7b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,11 +5,9 @@ RUN dnf -y install make cmake gcc-c++ zlib-devel \ openssl-devel git python3-pip python3-devel \ && dnf clean all WORKDIR /root/broker -ENV BROKER_DIRECTORY=/root/broker/ COPY . /root/broker/ -RUN pip install . -RUN cp broker_settings.yaml.example broker_settings.yaml +RUN pip install . ENTRYPOINT ["broker"] CMD ["--help"] diff --git a/broker/settings.py b/broker/settings.py index 4396f8fa..3372fdf6 100644 --- a/broker/settings.py +++ b/broker/settings.py @@ -4,7 +4,7 @@ settings: The settings object. init_settings: Function to initialize the settings file. validate_settings: Function to validate the settings file. - interactive_mode: Whether or not Broker is running in interactive mode. + INTERACTIVE_MODE: Whether or not Broker is running in interactive mode. BROKER_DIRECTORY: The directory where Broker looks for its files. settings_path: The path to the settings file. inventory_path: The path to the inventory file. @@ -25,21 +25,29 @@ def init_settings(settings_path, interactive=False): raw_url = ( "https://raw.githubusercontent.com/SatelliteQE/broker/master/broker_settings.yaml.example" ) - if ( - not interactive - or click.prompt( - f"Download example file from GitHub?\n{raw_url}", - type=click.Choice(["y", "n"]), - ) - == "y" - ): + proceed = not False + if interactive: + try: + proceed = ( + click.prompt( + f"Download example file from GitHub?\n{raw_url}", + type=click.Choice(["y", "n"]), + default="y", + ) + == "y" + ) + except click.core.Abort: + # We're likely in a different non-interactive environment (container?) + global INTERACTIVE_MODE + proceed, INTERACTIVE_MODE = True, False + if proceed: # download example file from github import requests click.echo(f"Downloading example file from: {raw_url}") raw_file = requests.get(raw_url, timeout=60) settings_path.write_text(raw_file.text) - if interative_mode: + if INTERACTIVE_MODE: try: click.edit(filename=str(settings_path.absolute())) except click.exceptions.ClickException: @@ -51,13 +59,13 @@ def init_settings(settings_path, interactive=False): raise ConfigurationError(f"Broker settings file not found at {settings_path.absolute()}.") -interative_mode = False +INTERACTIVE_MODE = False # GitHub action context if "GITHUB_WORKFLOW" not in os.environ: # determine if we're being ran from a CLI for frame in inspect.stack()[::-1]: if "/bin/broker" in frame.filename: - interative_mode = True + INTERACTIVE_MODE = True break @@ -76,7 +84,7 @@ def init_settings(settings_path, interactive=False): if not settings_path.exists(): click.secho(f"Broker settings file not found at {settings_path.absolute()}.", fg="red") - init_settings(settings_path, interactive=interative_mode) + init_settings(settings_path, interactive=INTERACTIVE_MODE) validators = [ Validator("HOST_USERNAME", default="root"),