Skip to content

Commit

Permalink
Remove HOST_MOUNT concept and always mount host files
Browse files Browse the repository at this point in the history
- Updated docker-compose.yml to simplify volume mounts by using the current directory for all services.
- Removed HOST_MOUNT and HOST_MOUNT_SOURCE environment variables from settings and entrypoint scripts, streamlining the configuration for local and production environments.
- Refactored setup.py to eliminate the get_olympia_mount function, replacing it with a more straightforward approach to determine the Docker target.
- Adjusted GitHub Actions workflows to remove references to the obsolete mount input, ensuring cleaner CI/CD processes.
- Enhanced test cases to reflect changes in Docker configuration and environment variable handling.
  • Loading branch information
KevinMind committed Jan 7, 2025
1 parent f87560f commit 8e76203
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 194 deletions.
5 changes: 0 additions & 5 deletions .github/actions/run-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ inputs:
description: 'Docker target to run (development|production)'
required: false
default: 'production'
mount:
description: 'Mount host files at runtime? (development|production)'
required: false
default: 'production'
deps:
description: 'Which dependencies to install at runtime? (development|production)'
required: false
Expand All @@ -44,7 +40,6 @@ runs:
DOCKER_DIGEST="${{ inputs.digest }}" \
DOCKER_TARGET="${{ inputs.target }}" \
OLYMPIA_UID="$(id -u)" \
OLYMPIA_MOUNT="${{ inputs.mount }}" \
OLYMPIA_DEPS="${{ inputs.deps }}" \
DATA_BACKUP_SKIP="${{ inputs.data_backup_skip }}" \
DOCKER_WAIT="true"
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/_test_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
name: |
version: '${{ matrix.version }}' |
target: '${{ matrix.target }}' |
mount: '${{ matrix.mount }}' |
deps: '${{ matrix.deps }}'
strategy:
fail-fast: false
Expand All @@ -57,9 +56,6 @@ jobs:
target:
- development
- production
mount:
- development
- production
deps:
- development
- production
Expand All @@ -72,7 +68,6 @@ jobs:
Values passed to the action:
version: ${{ matrix.version }}
target: ${{ matrix.target }}
mount: ${{ matrix.mount }}
deps: ${{ matrix.deps }}
EOF
- name: ${{ matrix.version == 'local' && 'Uncached Build' || 'Pull' }} Check
Expand All @@ -84,7 +79,6 @@ jobs:
with:
version: ${{ matrix.version }}
target: ${{ matrix.target }}
mount: ${{ matrix.mount }}
deps: ${{ matrix.deps }}
run: make check
- name: Cached Build Check
Expand All @@ -93,7 +87,6 @@ jobs:
with:
version: ${{ matrix.version }}
target: ${{ matrix.target }}
mount: ${{ matrix.mount }}
deps: ${{ matrix.deps }}
run: echo true

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/_test_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ jobs:
services: ''
digest: ${{ inputs.digest }}
version: ${{ inputs.version }}
mount: development
deps: development
run: |
split="--splits ${{ needs.test_config.outputs.splits }}"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ jobs:
with:
digest: ${{ needs.build.outputs.digest }}
version: ${{ needs.build.outputs.version }}
mount: development
deps: development
target: development
run: |
Expand Down Expand Up @@ -140,7 +139,6 @@ jobs:
with:
digest: ${{ needs.build.outputs.digest }}
version: ${{ needs.build.outputs.version }}
mount: development
deps: development
run: make extract_locales

Expand Down
26 changes: 3 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ services:
command: ["sleep", "infinity"]
volumes:
# used by: web, worker, nginx
- ${HOST_MOUNT_SOURCE:?}:/data/olympia
- ${HOST_MOUNT_SOURCE:?}deps:/data/olympia/deps
- ./site-static:/data/olympia/site-static
- ./storage:/data/olympia/storage
- ./:/data/olympia
worker:
<<: *olympia
command: [
Expand All @@ -63,9 +60,7 @@ services:
"celery -A olympia.amo.celery:app worker -E -c 2 --loglevel=INFO",
]
volumes:
- ${HOST_MOUNT_SOURCE:?}:/data/olympia
- ${HOST_MOUNT_SOURCE:?}deps:/data/olympia/deps
- ./storage:/data/olympia/storage
- ./:/data/olympia
extra_hosts:
- "olympia.test:127.0.0.1"
restart: on-failure:5
Expand Down Expand Up @@ -93,17 +88,12 @@ services:
interval: 30s
retries: 3
start_interval: 1s
volumes:
- ./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
- ./site-static:/srv/site-static
- ./storage:/srv/storage
- ./:/srv
ports:
- "80:80"
networks:
Expand Down Expand Up @@ -202,16 +192,6 @@ networks:
enable_ipv6: false

volumes:
# Volumes for the production olympia mounts
# allowing to conditionally mount directories
# from the host or from the image to <path>
# in the running docker container.
# If OLYMPIA_MOUNT_SOURCE matches (data_olympia_)
# then we use the production volume mounts. Otherwise
# it will map to the current directory ./<name>
# (data_olympia_)<name>:/<path>
data_olympia_:
data_olympia_deps:
# Volume for rabbitmq/redis to avoid anonymous volumes
data_rabbitmq:
data_redis:
Expand Down
6 changes: 0 additions & 6 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ fi
NEW_HOST_UID=$(get_olympia_uid)
OLYMPIA_ID_STRING="${NEW_HOST_UID}:$(get_olympia_gid)"

# If we are on production mode, update the ownership of /data/olympia to match the new id
if [[ "${HOST_MOUNT}" == "production" ]]; then
echo "Updating ownership of /data/olympia to ${OLYMPIA_ID_STRING}"
chown -R ${OLYMPIA_ID_STRING} /data/olympia
fi

cat <<EOF | su -s /bin/bash $OLYMPIA_USER
echo "Running command as ${OLYMPIA_USER} ${OLYMPIA_ID_STRING}"
set -xue
Expand Down
54 changes: 13 additions & 41 deletions scripts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_value(key, default_value):
return default_value


def get_docker_tag():
def get_docker_image_meta():
image = 'mozilla/addons-server'
version = 'local'

Expand All @@ -64,32 +64,20 @@ def get_docker_tag():
tag = f'{image}:{version}'
digest = None

# Docker target can be set on local images, but should be inferred from the image
# on remote images. Remote images are always built for production.
target = (
get_value('DOCKER_TARGET', 'development')
if version == 'local'
else 'production'
)

print('tag: ', tag)
print('target: ', target)
print('version: ', version)
print('digest: ', digest)

return tag, version, digest


def get_olympia_mount(docker_target):
"""
When running on production targets, the user can specify the olympia mount
to one of the valid values: development or production. In development, we
hard code the values to ensure we have necessary files and permissions.
"""
dev_source = './'
prod_source = 'data_olympia_'
olympia_mount = docker_target
olympia_mount_source = dev_source if docker_target == 'development' else prod_source

if (
docker_target == 'production'
and os.environ.get('OLYMPIA_MOUNT') == 'development'
):
olympia_mount = 'development'
olympia_mount_source = dev_source

return olympia_mount, olympia_mount_source
return tag, target, version, digest


# Env file should contain values that are referenced in docker-compose*.yml files
Expand All @@ -107,26 +95,14 @@ def get_olympia_mount(docker_target):


def main():
docker_tag, docker_version, _ = get_docker_tag()

is_local = docker_version == 'local'

# The default target should be inferred from the version
# but can be freely overridden by the user.
# E.g running local image in production mode
docker_target = get_value(
'DOCKER_TARGET', ('development' if is_local else 'production')
)

is_production = docker_target == 'production'
docker_tag, docker_target, _, _ = get_docker_image_meta()

olympia_uid = os.getuid()
olympia_mount, olympia_mount_source = get_olympia_mount(docker_target)

# These variables are special, as we should allow the user to override them
# but we should not set a default to the previously set value but instead
# use a value derived from other stable values.
debug = os.environ.get('DEBUG', str(False if is_production else True))
debug = os.environ.get('DEBUG', str(docker_target != 'production'))
olympia_deps = os.environ.get('OLYMPIA_DEPS', docker_target)

set_env_file(
Expand All @@ -139,10 +115,6 @@ def main():
# These values are mapped back to the olympia_* values in the environment
# of the container so everywhere they can be referenced as the user expects.
'HOST_UID': olympia_uid,
'HOST_MOUNT': olympia_mount,
# Save the docker compose volume name
# to use as the source of the /data/olympia volume
'HOST_MOUNT_SOURCE': olympia_mount_source,
'DEBUG': debug,
'OLYMPIA_DEPS': olympia_deps,
}
Expand Down
1 change: 0 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
DEV_MODE = DOCKER_TARGET != 'production'

HOST_UID = os.environ.get('HOST_UID')
HOST_MOUNT = os.environ.get('HOST_MOUNT')

WSGI_APPLICATION = 'olympia.wsgi.application'

Expand Down
1 change: 0 additions & 1 deletion src/olympia/lib/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def path(*folders):

# Host info that is hard coded for production images.
HOST_UID = None
HOST_MOUNT = None

# Used to determine if django should serve static files.
# For local deployments we want nginx to proxy static file requests to the
Expand Down
Loading

0 comments on commit 8e76203

Please sign in to comment.