Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
replaces the cmd entrypoint with pebble (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruyaume committed Apr 19, 2023
1 parent 08874a8 commit d0725c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
14 changes: 13 additions & 1 deletion rockcraft.yaml
Expand Up @@ -7,7 +7,19 @@ license: Apache-2.0
platforms:
amd64:

cmd: ["/bin/yarn", "run", "start:prod"]
services:
nms:
override: replace
command: yarn run start:prod
environment:
PORT: 8080
HOST: 0.0.0.0
MYSQL_DIALECT: postgres
MYSQL_PASS: password
MYSQL_USER: username
MYSQL_DB: magma
MYSQL_PORT: 5432
MYSQL_HOST: postgres_container

parts:

Expand Down
32 changes: 14 additions & 18 deletions tests/integration/test_integration.py
Expand Up @@ -4,14 +4,17 @@

"""Integration tests for the nms-magmalte rock."""

import logging
import time
import unittest
from pathlib import Path
from time import sleep

import docker # type: ignore[import]
import requests
import yaml

logger = logging.getLogger(__name__)

MAGMALTE_DOCKER_URL = "http://localhost"
MAGMALTE_DOCKER_PORT = 8081
MAGMALTE_LOGIN_PAGE = "/user/login"
Expand Down Expand Up @@ -58,17 +61,8 @@ def _run_magmalte_container(self):
f"ghcr.io/canonical/{image_name}:{version}",
detach=True,
ports={"8080/tcp": 8081},
command="start nms",
name="app_container",
environment={
"PORT": "8080",
"HOST": "0.0.0.0",
"MYSQL_DIALECT": "postgres",
"MYSQL_PASS": POSTGRES_PASSWORD,
"MYSQL_USER": POSTGRES_USER,
"MYSQL_DB": POSTGRES_DB,
"MYSQL_PORT": "5432",
"MYSQL_HOST": "postgres_container",
},
)
self.network.connect(magmalte_container)

Expand All @@ -77,13 +71,15 @@ def test_given_nms_magmalte_container_is_running_when_http_get_then_hello_messag
):
"""Test to validate that the container is running correctly."""
url = f"{MAGMALTE_DOCKER_URL}:{MAGMALTE_DOCKER_PORT}{MAGMALTE_LOGIN_PAGE}" # noqa: E501
for _ in range(30):
initial_time = time.time()
timeout = 30
while time.time() - initial_time < timeout:
try:
response = requests.get(url)
if response.status_code == 200:
break
except requests.exceptions.RequestException:
assert response.status_code == 200
return
except requests.exceptions.ConnectionError:
logger.info(f"Connection error when reaching {url}, will retry")
pass
sleep(1)
else:
assert False, "Failed to get a 200 response within 10 seconds."
time.sleep(1)
raise TimeoutError(f"Failed to get a 200 response within {timeout} seconds.")

0 comments on commit d0725c0

Please sign in to comment.