Skip to content

Commit

Permalink
TMP: fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Jan 7, 2025
1 parent ff0f48b commit a99472d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ tmp/*
# do not ignore the following files
!docker-compose.private.yml
!private/README.md
!storage/.gitignore
!deps/.gitkeep
Empty file removed deps/.gitkeep
Empty file.
21 changes: 7 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ services:
# used by: web, worker, nginx
- ${HOST_MOUNT_SOURCE:?}:/data/olympia
- ${HOST_MOUNT_SOURCE:?}deps:/deps
- data_site_static:/data/olympia/site-static
- ${HOST_MOUNT_SOURCE:?}storage:/data/olympia/storage
- ./site-static:/data/olympia/site-static
- ./storage:/data/olympia/storage
worker:
<<: *olympia
command: [
Expand All @@ -65,7 +65,7 @@ services:
volumes:
- ${HOST_MOUNT_SOURCE:?}:/data/olympia
- ${HOST_MOUNT_SOURCE:?}deps:/deps
- ${HOST_MOUNT_SOURCE:?}storage:/data/olympia/storage
- ./storage:/data/olympia/storage
extra_hosts:
- "olympia.test:127.0.0.1"
restart: on-failure:5
Expand Down Expand Up @@ -94,18 +94,16 @@ services:
retries: 3
start_interval: 1s
volumes:
# Don't mount generated files. They only exist in the container
# and would otherwiser be deleted by mounting the cwd volume above
- data_static_build:/data/olympia/static-build
- data_site_static:/data/olympia/site-static
- ./static-build:/data/olympia/static-build
- ./site-static:/data/olympia/site-static

nginx:
image: nginx
volumes:
- data_nginx:/etc/nginx/conf.d
- ${HOST_MOUNT_SOURCE:?}:/srv
- data_site_static:/srv/site-static
- ${HOST_MOUNT_SOURCE:?}storage:/srv/storage
- ./site-static:/srv/site-static
- ./storage:/srv/storage
ports:
- "80:80"
networks:
Expand Down Expand Up @@ -204,10 +202,6 @@ networks:
enable_ipv6: false

volumes:
# Volumes for static files that should not be
# mounted from the host.
data_static_build:
data_site_static:
# Volumes for the production olympia mounts
# allowing to conditionally mount directories
# from the host or from the image to <path>
Expand All @@ -218,7 +212,6 @@ volumes:
# (data_olympia_)<name>:/<path>
data_olympia_:
data_olympia_deps:
data_olympia_storage:
# Volume for rabbitmq/redis to avoid anonymous volumes
data_rabbitmq:
data_redis:
Expand Down
15 changes: 12 additions & 3 deletions scripts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import os


root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

env_path = os.path.join(root, '.env')


def set_env_file(values):
with open('.env', 'w') as f:
with open(env_path, 'w') as f:
print('Environment:')
for key, value in values.items():
f.write(f'{key}="{value}"\n')
Expand All @@ -14,8 +19,8 @@ def set_env_file(values):
def get_env_file():
env = {}

if os.path.exists('.env'):
with open('.env', 'r') as f:
if os.path.exists(env_path):
with open(env_path, 'r') as f:
for line in f:
key, value = line.strip().split('=', 1)
env[key] = value.strip('"')
Expand Down Expand Up @@ -143,6 +148,10 @@ def main():
}
)

# Create the directories that are expected to exist in the container.
for dir in ['deps', 'site-static', 'static-build', 'storage']:
os.makedirs(os.path.join(root, dir), exist_ok=True)


if __name__ == '__main__':
main()
18 changes: 12 additions & 6 deletions src/olympia/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ def nginx_check(app_configs, **kwargs):

configs = [
(settings.MEDIA_ROOT, 'http://nginx/user-media'),
(settings.STATIC_ROOT, 'http://nginx/static'),
(settings.STATIC_FILES_PATH, 'http://nginx/static'),
(settings.STATIC_ROOT, 'http://nginx/static'),
]

files_to_remove = []

for dir, base_url in configs:
file_path = os.path.join(dir, 'test.txt')
file_url = f'{base_url}/test.txt'
Expand All @@ -177,12 +179,15 @@ def nginx_check(app_configs, **kwargs):
errors.append(Error(f'{dir} does not exist', id='setup.E007'))

try:
open(file_path, 'w').close()
with open(file_path, 'w') as f:
f.write(dir)

files_to_remove.append(file_path)
response = requests.get(file_url)

expected_config = (
(response.status_code, 200),
(response.text, ''),
(response.text, dir),
(response.headers.get('X-Served-By'), 'nginx'),
)

Expand All @@ -197,9 +202,10 @@ def nginx_check(app_configs, **kwargs):
id='setup.E010',
)
)
finally:
if os.path.exists(file_path):
os.remove(file_path)

# Always remove the files we created.
for file_path in files_to_remove:
os.remove(file_path)

return errors

Expand Down
2 changes: 1 addition & 1 deletion src/olympia/core/tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def _test_nginx_response(

expected_config = (
(status_code, 200),
(response_text, ''),
(response_text, self.media_root),
(served_by, 'nginx'),
)

Expand Down
Empty file removed storage/.gitignore
Empty file.
14 changes: 5 additions & 9 deletions tests/make/make.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ describe('docker-compose.yml', () => {
target: '/data/olympia',
}),
expect.objectContaining({
source: isProdMountTarget
? 'data_olympia_storage'
: expect.any(String),
source: expect.any(String),
target: '/data/olympia/storage',
}),
]),
Expand All @@ -125,11 +123,11 @@ describe('docker-compose.yml', () => {
expect(web.volumes).toEqual(
expect.arrayContaining([
expect.objectContaining({
source: 'data_static_build',
source: expect.any(String),
target: '/data/olympia/static-build',
}),
expect.objectContaining({
source: 'data_site_static',
source: expect.any(String),
target: '/data/olympia/site-static',
}),
]),
Expand Down Expand Up @@ -162,14 +160,12 @@ describe('docker-compose.yml', () => {
target: '/srv',
}),
expect.objectContaining({
source: 'data_site_static',
source: expect.any(String),
target: '/srv/site-static',
}),
// mapping for local host directory to /data/olympia/storage
expect.objectContaining({
source: isProdMountTarget
? 'data_olympia_storage'
: expect.any(String),
source: expect.any(String),
target: '/srv/storage',
}),
]),
Expand Down
12 changes: 12 additions & 0 deletions tests/make/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ def test_override_env_olympia_deps_development_on_target_development(self):
def test_olympia_deps_override(self):
main()
self.assert_set_env_file_called_with(OLYMPIA_DEPS='test')


@override_env()
@mock.patch('scripts.setup.os.makedirs')
def test_make_dirs(mock_makedirs):
from scripts.setup import root

main()
assert mock_makedirs.call_args_list == [
mock.call(os.path.join(root, dir), exist_ok=True)
for dir in ['deps', 'site-static', 'static-build', 'storage']
]

0 comments on commit a99472d

Please sign in to comment.