Skip to content

Commit

Permalink
OLYMPIA_DEPS to control runtime dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Dec 11, 2024
1 parent 7a18f09 commit 3446792
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .github/actions/run-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ inputs:
description: 'Skip data backup'
required: false
default: 'true'
olympia_deps:
description: 'Which dependencies to install at runtime? (development|production)'
required: false
default: 'development'

runs:
using: 'composite'
Expand All @@ -40,6 +44,7 @@ runs:
COMPOSE_FILE: ${{ inputs.compose_file }}
HOST_UID: ${{ steps.id.outputs.id }}
DATA_BACKUP_SKIP: ${{ inputs.data_backup_skip }}
OLYMPIA_DEPS: ${{ inputs.olympia_deps }}
run: |
# Start the specified services
make up
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/_test_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
name: |
version: '${{ matrix.version }}' |
compose_file: '${{ matrix.compose_file }}'
olympia_deps: '${{ matrix.olympia_deps }}'
strategy:
fail-fast: false
matrix:
Expand All @@ -55,6 +56,9 @@ jobs:
compose_file:
- docker-compose.yml
- docker-compose.yml:docker-compose.ci.yml
olympia_deps:
- development
- production
steps:
- uses: actions/checkout@v4
- shell: bash
Expand All @@ -64,6 +68,7 @@ jobs:
Values passed to the action:
version: ${{ matrix.version }}
compose_file: ${{ matrix.compose_file }}
olympia_deps: ${{ matrix.olympia_deps }}
EOF
- uses: ./.github/actions/run-docker
# Set environment variables that are expected to be ignored
Expand All @@ -73,6 +78,7 @@ jobs:
with:
version: ${{ matrix.version }}
compose_file: ${{ matrix.compose_file }}
olympia_deps: ${{ matrix.olympia_deps }}
run: make check

test_make_docker_configuration:
Expand Down
20 changes: 0 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,6 @@ RUN \
${HOME}/scripts/install_deps.py prod
EOF

FROM pip_production AS pip_development

RUN \
--mount=type=bind,source=scripts/install_deps.py,target=${HOME}/scripts/install_deps.py \
# Files required to install pip dependencies
--mount=type=bind,source=./requirements/prod.txt,target=${HOME}/requirements/prod.txt \
--mount=type=bind,source=./requirements/dev.txt,target=${HOME}/requirements/dev.txt \
# Files required to install npm dependencies
--mount=type=bind,source=package.json,target=${HOME}/package.json \
--mount=type=bind,source=package-lock.json,target=${HOME}/package-lock.json \
# Mounts for caching dependencies
--mount=type=cache,target=${PIP_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
--mount=type=cache,target=${NPM_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
<<EOF
${HOME}/scripts/install_deps.py dev
EOF

FROM base AS locales
ARG LOCALE_DIR=${HOME}/locale
# Compile locales
Expand Down Expand Up @@ -187,9 +170,6 @@ SHELL ["/bin/sh", "-c"]

FROM sources AS development

# Copy dependencies from `pip_development`
COPY --from=pip_development --chown=olympia:olympia /deps /deps

FROM sources AS production

# Copy compiled locales from builder
Expand Down
10 changes: 1 addition & 9 deletions Makefile-docker
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ REQUIRED_FILES := \
# Build list of dependencies to install
DEPS = pip prod
# If we're running a development image, then we should install the development dependencies
ifeq ($(DOCKER_TARGET), development)
ifeq ($(OLYMPIA_DEPS), development)
DEPS += dev
endif

Expand Down Expand Up @@ -83,14 +83,6 @@ update_assets:

.PHONY: update_deps
update_deps: ## Update the dependencies
# If we're running a non local or production image, remove the existing deps and install clean
ifneq ($(and $(findstring local, $(DOCKER_TAG)), $(findstring development, $(DOCKER_TARGET))),)
@echo "Updating existing deps"
else
@echo "Removing existing deps"
rm -rf /deps/**
endif
# Install all dependencies in one call
$(HOME)/scripts/install_deps.py $(DEPS)

# TOOD: remove this after we migrate addons-frontned to not depend on it.
Expand Down
1 change: 1 addition & 0 deletions Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export DOCKER_COMMIT ?=
export DOCKER_BUILD ?=
export DOCKER_VERSION ?=
export DATA_BACKUP_SKIP ?=
export OLYMPIA_DEPS ?= development
override DOCKER_MYSQLD_VOLUME = addons-server_data_mysqld

INITIALIZE_ARGS ?=
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ x-env-mapping: &env
- HOST_UID
- DEBUG
- DATA_BACKUP_SKIP
- OLYMPIA_DEPS

x-deps-mount: &deps-mount
data_deps:/deps
Expand Down
13 changes: 13 additions & 0 deletions scripts/install_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

# Constants
ALLOWED_NPM_TARGETS = set(['prod', 'dev'])
DOCKER_TAG = os.environ.get('DOCKER_TAG', 'local')
DOCKER_TARGET = os.environ.get('DOCKER_TARGET', '')
OLYMPIA_DEPS = os.environ.get('OLYMPIA_DEPS', '')


def copy_package_json():
Expand All @@ -26,6 +29,16 @@ def main():
print('No targets specified')
sys.exit(1)

if (
'local' not in DOCKER_TAG or
'production' in DOCKER_TARGET or
'production' in OLYMPIA_DEPS
):
print('Removing existing deps')
subprocess.run(['rm', '-rf', '/deps/**'])
else:
print('Updating existing deps')

# Copy package.json files
copy_package_json()

Expand Down
3 changes: 2 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def insert_debug_toolbar_middleware(middlewares):
return tuple(ret_middleware)


if DEV_MODE:
# We can only add these dependencies if we have development dependencies
if os.environ.get('OLYMPIA_DEPS', '') == 'development':
INSTALLED_APPS += (
'debug_toolbar',
'dbbackup',
Expand Down

0 comments on commit 3446792

Please sign in to comment.