diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1b8de0d4afb6..4a5a7229bb99 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,11 +1,25 @@ { "name": "Addons-Server Devcontainer", "image": "mcr.microsoft.com/devcontainers/base:bullseye", + "workspaceFolder": "/workspaces/addons-server", + "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/addons-server,type=bind", "features": { "ghcr.io/devcontainers/features/docker-in-docker": { "version": "latest", "enableNonRootDocker": "true", "moby": "true" } - } + }, + "forwardPorts": [80], + "appPort": [80], + "portsAttributes": { + "80": { + "label": "Addons-Server", + "onAutoForward": "notify", + "protocol": "http", + "requireLocalPort": true, + "elevateIfNeeded": true + } + }, + "postStartCommand": "make up" } diff --git a/docker-compose.yml b/docker-compose.yml index 4e847cacc989..0c23f7dead9b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ x-env-mapping: &env - MEMCACHE_LOCATION=memcached:11211 - MYSQL_DATABASE=olympia - MYSQL_ROOT_PASSWORD=docker - - OLYMPIA_SITE_URL=http://olympia.test - PYTHONDONTWRITEBYTECODE=1 - PYTHONUNBUFFERED=1 - PYTHONBREAKPOINT=ipdb.set_trace @@ -21,6 +20,7 @@ x-env-mapping: &env - HISTCONTROL=erasedups - CIRCLECI - DATA_BACKUP_SKIP + - OLYMPIA_SITE_URL x-olympia: &olympia <<: *env diff --git a/scripts/setup.py b/scripts/setup.py index 176a05237c51..3edf0f02128d 100755 --- a/scripts/setup.py +++ b/scripts/setup.py @@ -86,6 +86,14 @@ def get_olympia_mount(docker_target): return olympia_mount, olympia_mount_source +def get_olympia_site_url(): + # In codespaces, we set the site URL to the codespace name port 80 + # this will map to the nginx service in the devcontainer. + if os.environ.get('CODESPACE_NAME'): + return f'https://{os.environ.get("CODESPACE_NAME")}-80.githubpreview.dev' + # On local hosts, we set the site URL to olympia.test + return 'http://olympia.test' + # Env file should contain values that are referenced in docker-compose*.yml files # so running docker compose commands produce consistent results in terminal and make. @@ -123,6 +131,7 @@ def main(): # use a value derived from other stable values. debug = os.environ.get('DEBUG', str(False if is_production else True)) olympia_deps = os.environ.get('OLYMPIA_DEPS', docker_target) + olympia_site_url = get_olympia_site_url() set_env_file( { @@ -140,6 +149,7 @@ def main(): 'HOST_MOUNT_SOURCE': olympia_mount_source, 'DEBUG': debug, 'OLYMPIA_DEPS': olympia_deps, + 'OLYMPIA_SITE_URL': olympia_site_url, } )