Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move /deps/node_modules to /data/olympia/node_modules #22955

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ tmp/*
!private/README.md
!storage/.gitignore
!deps/.gitkeep
!site-static/.gitkeep
!static-build/.gitkeep
57 changes: 31 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ ENV BUILD_INFO=/build-info.json
SHELL ["/bin/bash", "-xue", "-c"]

ENV OLYMPIA_UID=9500
# give olympia access to the HOME directory
ENV HOME=/data/olympia
ENV DEPS_DIR=${HOME}/deps
ENV NPM_DEPS_DIR=${HOME}/node_modules

RUN <<EOF
groupadd -g ${OLYMPIA_UID} olympia
useradd -u ${OLYMPIA_UID} -g ${OLYMPIA_UID} -s /sbin/nologin -d /data/olympia olympia
useradd -u ${OLYMPIA_UID} -g ${OLYMPIA_UID} -s /sbin/nologin -d ${HOME} olympia

# Create and chown olympia directories
olympia_dirs=("${DEPS_DIR}" "${NPM_DEPS_DIR}" "${HOME}/storage")
for dir in "${olympia_dirs[@]}"; do
mkdir -p ${dir}
chown -R olympia:olympia ${dir}
done
EOF

# give olympia access to the HOME directory
ENV HOME=/data/olympia

WORKDIR ${HOME}
RUN chown -R olympia:olympia ${HOME}

Expand Down Expand Up @@ -74,37 +85,28 @@ ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8

RUN <<EOF
# Create directory for dependencies
mkdir /deps
chown -R olympia:olympia /deps


# For backwards-compatibility purposes, set up links to uwsgi. Note that
# the target does not exist yet at this point, but it will later.
ln -s /deps/bin/uwsgi /usr/bin/uwsgi
ln -s ${DEPS_DIR}/bin/uwsgi /usr/bin/uwsgi
ln -s /usr/bin/uwsgi /usr/sbin/uwsgi

# Create the storage directory and the test file to verify nginx routing
mkdir -p ${HOME}/storage
chown -R olympia:olympia ${HOME}/storage
EOF

USER olympia:olympia

ENV PIP_USER=true
ENV PIP_BUILD=/deps/build/
ENV PIP_CACHE_DIR=/deps/cache/
ENV PIP_SRC=/deps/src/
ENV PYTHONUSERBASE=/deps
ENV PIP_BUILD=${DEPS_DIR}/build/
ENV PIP_CACHE_DIR=${DEPS_DIR}/cache/
ENV PIP_SRC=${DEPS_DIR}/src/
ENV PYTHONUSERBASE=${DEPS_DIR}
ENV PATH=$PYTHONUSERBASE/bin:$PATH
ENV NPM_CONFIG_PREFIX=/deps/
ENV NPM_CACHE_DIR=/deps/cache/npm
ENV NPM_CACHE_DIR=${DEPS_DIR}/cache/npm
ENV NPM_DEBUG=true
# Set python path to the project root and src to resolve olympia modules correctly
ENV PYTHONPATH=${HOME}:${HOME}/src

ENV PIP_COMMAND="python3 -m pip"
ENV NPM_ARGS="--prefix ${NPM_CONFIG_PREFIX} --cache ${NPM_CACHE_DIR} --loglevel verbose"
ENV NPM_ARGS="--cache ${NPM_CACHE_DIR} --loglevel verbose"

# All we need in "base" is pip to be installed
#this let's other layers install packages using the correct version.
Expand Down Expand Up @@ -135,8 +137,8 @@ RUN \
# Files required to install pip dependencies
--mount=type=bind,source=./requirements/prod.txt,target=${HOME}/requirements/prod.txt \
# Files required to install npm dependencies
--mount=type=bind,source=package.json,target=/deps/package.json \
--mount=type=bind,source=package-lock.json,target=/deps/package-lock.json \
--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} \
Expand All @@ -146,6 +148,9 @@ EOF

FROM base AS development

# Copy build info from info
COPY --from=info ${BUILD_INFO} ${BUILD_INFO}

FROM base AS locales
ARG LOCALE_DIR=${HOME}/locale
# Compile locales
Expand All @@ -155,7 +160,7 @@ COPY --chown=olympia:olympia locale ${LOCALE_DIR}
RUN \
--mount=type=bind,source=requirements/locale.txt,target=${HOME}/requirements/locale.txt \
--mount=type=bind,source=Makefile-docker,target=${HOME}/Makefile-docker \
--mount=type=bind,source=locale/compile-mo.sh,target=${HOME}/compile-mo.sh \
--mount=type=bind,source=scripts/compile_locales.py,target=${HOME}/scripts/compile_locales.py \
make -f Makefile-docker compile_locales

# More efficient caching by mounting the exact files we need
Expand All @@ -173,12 +178,12 @@ COPY --chown=olympia:olympia static/ ${HOME}/static/
# Run that command without having to copy the whole source code
# This will shave nearly 1 minute off the best case build time
RUN \
--mount=type=bind,src=src,target=${HOME}/src \
--mount=type=bind,src=Makefile-docker,target=${HOME}/Makefile-docker \
--mount=type=bind,src=src,target=${HOME}/src \
--mount=type=bind,src=scripts/update_assets.py,target=${HOME}/scripts/update_assets.py \
--mount=type=bind,src=manage.py,target=${HOME}/manage.py \
<<EOF
echo "from olympia.lib.settings_base import *" > settings_local.py
DJANGO_SETTINGS_MODULE="settings_local" make -f Makefile-docker update_assets
make -f Makefile-docker update_assets
EOF

FROM base AS production
Expand All @@ -194,4 +199,4 @@ COPY --from=info ${BUILD_INFO} ${BUILD_INFO}
# Copy compiled locales from builder
COPY --from=locales --chown=olympia:olympia ${HOME}/locale ${HOME}/locale
# Copy dependencies from `pip_production`
COPY --from=pip_production --chown=olympia:olympia /deps /deps
COPY --from=pip_production --chown=olympia:olympia ${DEPS_DIR} ${DEPS_DIR}
49 changes: 8 additions & 41 deletions Makefile-docker
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ export PYTHON_COMMAND=python3
export PIP_COMMAND=$(PYTHON_COMMAND) -m pip
APP=src/olympia/

NODE_MODULES := $(NPM_CONFIG_PREFIX)node_modules/

REQUIRED_FILES := \
Makefile \
Makefile-os \
Makefile-docker \
/deps/package.json \
/deps/package-lock.json \
/addons-server-docker-container \

# Build list of dependencies to install
DEPS = pip prod
# If we're running a development image, then we should install the development dependencies
Expand All @@ -39,29 +29,12 @@ check_pip_packages: ## check the existence of multiple python packages
./scripts/check_pip_packages.sh $$dep.txt; \
done

.PHONY: check_files
check_files: ## check the existence of multiple files
@for file in $(REQUIRED_FILES); do test -f "$$file" || (echo "$$file is missing." && exit 1); done
@echo "All required files are present."

.PHONY: check_olympia_user
check_olympia_user: ## check if the olympia user exists and is current user
@if [ "$$(id -u olympia)" != "$$(id -u)" ]; then echo "The current user is not the olympia user."; exit 1; fi
@echo "The current user is the olympia user."

.PHONY: check_django
check_django: ## check if the django app is configured properly
./manage.py check

.PHONY: check_nginx
check_nginx: ## check if the nginx config for local development is configured properly
mkdir -p /data/olympia/storage/shared_storage/uploads
echo "OK" > /data/olympia/storage/shared_storage/uploads/.check
@if [ "$$(curl -sf http://nginx/user-media/.check)" != "OK" ]; then echo "Requesting http://nginx/user-media/.check failed"; exit 1; fi
@echo "Nginx user-media configuration looks correct."

.PHONY: check
check: check_nginx check_files check_olympia_user check_debian_packages check_pip_packages check_django
check: check_debian_packages check_pip_packages check_django

.PHONY: data_dump
data_dump:
Expand All @@ -72,14 +45,8 @@ data_load:
./manage.py data_load $(ARGS)

.PHONY: update_assets
update_assets:
# Copy files required in compress_assets to the static folder
# If changing this here, make sure to adapt tests in amo/test_commands.py
$(PYTHON_COMMAND) manage.py compress_assets
$(PYTHON_COMMAND) manage.py generate_jsi18n_files
# Collect static files: This MUST be run last or files will be missing
$(PYTHON_COMMAND) manage.py collectstatic --noinput

update_assets: ## Update the static assets
$(HOME)/scripts/update_assets.py

.PHONY: update_deps
update_deps: ## Update the dependencies
Expand All @@ -94,7 +61,7 @@ setup-ui-tests:
lint: ## lint the code
ruff check .
ruff format --check .
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --check '**'
npm exec $(NPM_ARGS) -- prettier --check '**'
curlylint src/

lint-codestyle: lint
Expand Down Expand Up @@ -199,15 +166,15 @@ test_failed: ## rerun the failed tests from the previous run

.PHONY: run_js_tests
run_js_tests: ## Run the JavaScript test suite (requires compiled/compressed assets).
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- jest tests/js
npm exec $(NPM_ARGS) -- jest tests/js

.PHONY: watch_js_tests
watch_js_tests: ## Run+watch the JavaScript test suite (requires compiled/compressed assets).
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- jest --watch
npm exec $(NPM_ARGS) -- jest --watch

.PHONY: format
format: ## Autoformat our codebase.
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --write '**'
npm exec $(NPM_ARGS) -- prettier --write '**'
ruff check --fix-only .
ruff format .

Expand All @@ -218,7 +185,7 @@ extract_locales: ## extracts and merges translation strings
.PHONE: compile_locales
compile_locales: ## compiles translation strings
$(PIP_COMMAND) install --progress-bar=off --no-deps -r requirements/locale.txt
./locale/compile-mo.sh ./locale/
$(HOME)/scripts/compile_locales.py

.PHONY: help_submake
help_submake:
Expand Down
9 changes: 5 additions & 4 deletions Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,22 @@ docker_clean_build_cache: ## Remove buildx build cache
.PHONY: clean_docker
clean_docker: docker_compose_down docker_mysqld_volume_remove docker_clean_images docker_clean_volumes docker_clean_build_cache ## Remove all docker resources taking space on the host machine

.PHONY: docker_update_deps
docker_update_deps: docker_mysqld_volume_create ## Update the dependencies in the container based on the docker tag and target
.PHONY: docker_sync_host
docker_sync_host: docker_mysqld_volume_create ## Update the dependencies in the container based on the docker tag and target
docker compose run \
--rm \
--no-deps \
$(DOCKER_RUN_ARGS) \
web \
make update_deps
./scripts/sync_host_files.py

.PHONY: up_pre
up_pre: setup docker_pull_or_build docker_update_deps ## Pre-up the environment, setup files, volumes and host state
up_pre: setup docker_pull_or_build docker_sync_host ## Pre-up the environment, setup files, volumes and host state

.PHONY: up_start
up_start: docker_mysqld_volume_create ## Start the docker containers
docker compose up $(DOCKER_COMPOSE_ARGS) $(ARGS)
docker compose rm olympia_volumes -f

.PHONY: up_post
up_post: docker_clean_images docker_clean_volumes ## Post-up the environment, setup files, volumes and host state
Expand Down
Loading
Loading