Skip to content

Commit

Permalink
Let opta push optionally terraform init if needed (#104)
Browse files Browse the repository at this point in the history
* Let opta push optionally terraform init if needed

```
 source $(pipenv --venv)/bin/activate
  export PYTHONPATH=$(pwd)
  cd ..
  python ./runxc/opta/cli.py push app:$IMAGE_VERSION --env staging
  shell: /bin/bash -e {0}
  env:
    ECR_REPO: ***.dkr.ecr.us-east-1.amazonaws.com/test-service-runx-app
    IMAGE_VERSION: 5e6ffbb65803891d45d071bcf8a223767452c246
    SSH_AUTH_SOCK: /tmp/ssh-t5c9NgsKdaxC/agent.2524
    SSH_AGENT_PID: 2525
    pythonLocation: /opt/hostedtoolcache/Python/3.8.7/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.7/x64/lib
    AWS_DEFAULT_REGION: us-east-1
    AWS_REGION: us-east-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
ERROR: Command '['terraform', 'output', '-json']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "./runxc/opta/cli.py", line 161, in <module>
    cli()
  File "/home/runner/.local/share/virtualenvs/runxc-xo5BZeII/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/runner/.local/share/virtualenvs/runxc-xo5BZeII/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/runner/.local/share/virtualenvs/runxc-xo5BZeII/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/runner/.local/share/virtualenvs/runxc-xo5BZeII/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/runner/.local/share/virtualenvs/runxc-xo5BZeII/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/runner/work/test-service/test-service/runxc/opta/commands/push.py", line 82, in push
    registry_url = get_registry_url()
  File "/home/runner/work/test-service/test-service/runxc/opta/commands/push.py", line 16, in get_registry_url
    outputs = Terraform.get_outputs()
  File "/home/runner/work/test-service/test-service/runxc/opta/core/terraform.py", line 27, in get_outputs
    raw_output = nice_run(
  File "/home/runner/work/test-service/test-service/runxc/opta/nice_subprocess.py", line 93, in nice_run
    raise CalledProcessError(retcode, process.args, output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['terraform', 'output', '-json']' returned non-zero exit status 1.
ERROR: 
```

* Addressing cr
  • Loading branch information
juandiegopalomino authored Feb 24, 2021
1 parent 001b04d commit 8d2644c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions opta/commands/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from botocore.config import Config

from opta.core.generator import gen_all
from opta.core.terraform import Terraform
from opta.core.terraform import get_terraform_outputs
from opta.layer import Layer
from opta.nice_subprocess import nice_run
from opta.utils import is_tool


def get_registry_url() -> str:
outputs = Terraform.get_outputs()
outputs = get_terraform_outputs()
if "docker_repo_url" not in outputs:
raise Exception(
"Unable to determine docker repository url. There is likely something wrong with your opta configuration."
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
class TestGetRegistryUrl:
def test_get_registry_url(self, mocker: MockFixture) -> None:
mocker.patch(
"opta.commands.push.Terraform.get_outputs", return_value=TERRAFORM_OUTPUTS
"opta.commands.push.get_terraform_outputs", return_value=TERRAFORM_OUTPUTS
)

docker_repo_url = get_registry_url()
assert docker_repo_url == REGISTRY_URL

def test_no_docker_repo_url_in_output(self, mocker: MockFixture) -> None:
mocker.patch("os.path.isdir", return_value=True)
mocker.patch("opta.commands.push.Terraform.get_outputs", return_value={})
mocker.patch("opta.commands.push.get_terraform_outputs", return_value={})

with pytest.raises(Exception) as e_info:
get_registry_url()
Expand Down

0 comments on commit 8d2644c

Please sign in to comment.