Skip to content

Commit

Permalink
Test checkout remote
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Dec 18, 2024
1 parent c06f6b1 commit c59e883
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
backups
build*.py
buildx-bake-metadata.json
deps
deps/*
docker*.yml
docker/artifacts/*
docs/_build
Expand Down
14 changes: 12 additions & 2 deletions .github/actions/run-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ inputs:
required: false
default: 'true'
mount:
description: 'Mount olympia files from host'
description: 'Mount host files at runtime? (development|production)'
required: false
default: 'production'
deps:
description: 'Which dependencies to install at runtime? (development|production)'
required: false
default: 'production'

Expand All @@ -36,6 +40,7 @@ runs:
DOCKER_DIGEST="${{ inputs.digest }}" \
OLYMPIA_UID="$(id -u)" \
OLYMPIA_MOUNT="${{ inputs.mount }}" \
OLYMPIA_DEPS="${{ inputs.deps }}" \
DATA_BACKUP_SKIP="${{ inputs.data_backup_skip }}" \
DOCKER_WAIT="true"
Expand All @@ -46,7 +51,12 @@ runs:
${{ inputs.run }}
EOF
- name: Logs
- name: Cleanup
if: always()
shell: bash
run: make down

- name: Logs
if: ${{ inputs.logs }}
shell: bash
run: docker compose logs
1 change: 1 addition & 0 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ jobs:
version: ${{ inputs.version }}
digest: ${{ inputs.digest }}
services: ${{ matrix.services }}
deps: development
run: ${{ matrix.run }}
8 changes: 8 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 }}' |
mount: '${{ matrix.mount }}'
deps: '${{ matrix.deps }}'
strategy:
fail-fast: false
matrix:
Expand All @@ -55,6 +56,9 @@ jobs:
mount:
- development
- production
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 }}
mount: ${{ matrix.mount }}
deps: ${{ matrix.deps }}
EOF
- name: ${{ matrix.version == 'local' && 'Uncached Build' || 'Pull' }} Check
uses: ./.github/actions/run-docker
Expand All @@ -74,13 +79,15 @@ jobs:
with:
version: ${{ matrix.version }}
mount: ${{ matrix.mount }}
deps: ${{ matrix.deps }}
run: make check
- name: Cached Build Check
uses: ./.github/actions/run-docker
if: ${{ matrix.version == 'local' }}
with:
version: ${{ matrix.version }}
mount: ${{ matrix.mount }}
deps: ${{ matrix.deps }}
run: echo true

test_make_docker_configuration:
Expand All @@ -102,6 +109,7 @@ jobs:
with:
digest: ${{ inputs.digest }}
version: ${{ inputs.version }}
deps: development
run: |
pytest tests/make/
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/_test_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
digest: ${{ inputs.digest }}
version: ${{ inputs.version }}
mount: development
deps: development
run: |
split="--splits ${{ needs.test_config.outputs.splits }}"
group="--group ${{ matrix.group }}"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
digest: ${{ needs.build.outputs.digest }}
version: ${{ needs.build.outputs.version }}
mount: development
deps: development
run: |
make docs
Expand Down Expand Up @@ -140,6 +141,7 @@ jobs:
digest: ${{ needs.build.outputs.digest }}
version: ${{ needs.build.outputs.version }}
mount: development
deps: development
run: make extract_locales

- name: Push Locales
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
backups
build*.py
buildx-bake-metadata.json
deps
deps/*
docker*.yml
docker/artifacts/*
docs/_build
Expand Down Expand Up @@ -56,3 +56,4 @@ tmp/*
!docker-compose.private.yml
!private/README.md
!storage/.gitignore
!deps/.gitkeep
30 changes: 4 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,12 @@ ENV NPM_ARGS="--prefix ${NPM_CONFIG_PREFIX} --cache ${NPM_CACHE_DIR} --loglevel
# All we need in "base" is pip to be installed
#this let's other layers install packages using the correct version.
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/pip.txt,target=${HOME}/requirements/pip.txt \
--mount=type=cache,target=${PIP_CACHE_DIR},uid=${OLYMPIA_UID},gid=${OLYMPIA_UID} \
<<EOF
# Work arounds "Multiple .dist-info directories" issue.
rm -rf /deps/build/*
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/pip.txt
${HOME}/scripts/install_deps.py pip
EOF

# TODO: we should remove dependency on the environment variable
Expand All @@ -129,6 +128,7 @@ ENV DOCKER_TARGET=${DOCKER_TARGET}
FROM base AS pip_production

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 \
# Files required to install npm dependencies
Expand All @@ -138,26 +138,7 @@ RUN \
--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
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/prod.txt
npm ci ${NPM_ARGS} --include=prod
EOF

FROM pip_production AS pip_development

RUN \
# 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=/deps/package.json \
--mount=type=bind,source=package-lock.json,target=/deps/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
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/prod.txt
${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r requirements/dev.txt
npm install ${NPM_ARGS} --no-save
${HOME}/scripts/install_deps.py prod
EOF

FROM base AS locales
Expand Down Expand Up @@ -213,9 +194,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
20 changes: 14 additions & 6 deletions Makefile-docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ REQUIRED_FILES := \
/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
ifeq ($(OLYMPIA_DEPS), development)
DEPS += dev
endif

.PHONY: help_redirect
help_redirect:
@$(MAKE) help --no-print-directory
Expand All @@ -28,12 +35,9 @@ check_debian_packages: ## check the existence of multiple debian packages

.PHONY: check_pip_packages
check_pip_packages: ## check the existence of multiple python packages
@ ./scripts/check_pip_packages.sh prod.txt
# "production" corresponds to the "propduction" DOCKER_TARGET defined in the Dockerfile
# When the target is "production" it means we cannot expect dev.txt dependencies to be installed.
@if [ "$(DOCKER_TARGET)" != "production" ]; then \
./scripts/check_pip_packages.sh dev.txt; \
fi
@for dep in $(DEPS); do \
./scripts/check_pip_packages.sh $$dep.txt; \
done

.PHONY: check_files
check_files: ## check the existence of multiple files
Expand Down Expand Up @@ -77,6 +81,10 @@ update_assets:
$(PYTHON_COMMAND) manage.py collectstatic --noinput


.PHONY: update_deps
update_deps: ## Update the dependencies
$(HOME)/scripts/install_deps.py $(DEPS)

# TOOD: remove this after we migrate addons-frontned to not depend on it.
.PHONY: setup-ui-tests
setup-ui-tests:
Expand Down
12 changes: 10 additions & 2 deletions Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ CLEAN_PATHS := \
version.json \
logs \
buildx-bake-metadata.json \
deps \

.PHONY: help_redirect
help_redirect:
Expand Down Expand Up @@ -154,8 +153,17 @@ 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
docker compose run \
--rm \
--no-deps \
$(DOCKER_RUN_ARGS) \
web \
make update_deps

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

.PHONY: up_start
up_start: docker_mysqld_volume_create ## Start the docker containers
Expand Down
Empty file added deps/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
volumes:
# 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
worker:
Expand All @@ -63,6 +64,7 @@ services:
]
volumes:
- ${HOST_MOUNT_SOURCE:?}:/data/olympia
- ${HOST_MOUNT_SOURCE:?}deps:/deps
- ${HOST_MOUNT_SOURCE:?}storage:/data/olympia/storage
extra_hosts:
- "olympia.test:127.0.0.1"
Expand Down Expand Up @@ -215,6 +217,7 @@ volumes:
# it will map to the current directory ./<name>
# (data_olympia_)<name>:/<path>
data_olympia_:
data_olympia_deps:
data_olympia_storage:
# Volume for rabbitmq/redis to avoid anonymous volumes
data_rabbitmq:
Expand Down
94 changes: 94 additions & 0 deletions scripts/install_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python3

import os
import shutil
import subprocess
import sys


def copy_package_json():
"""Copy package.json files to deps directory if they exist."""
try:
shutil.copy('/data/olympia/package.json', '/deps')
shutil.copy('/data/olympia/package-lock.json', '/deps')
except (IOError, OSError):
pass # Ignore if files don't exist or can't be copied


def main(targets):
# 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', '')

if not targets:
raise ValueError('No targets specified')

print(
'Updating deps... \n',
f'targets: {", ".join(targets)} \n',
f'DOCKER_TAG: {DOCKER_TAG} \n',
f'DOCKER_TARGET: {DOCKER_TARGET} \n',
f'OLYMPIA_DEPS: {OLYMPIA_DEPS} \n',
)

# If we are installing production dependencies or on a non local image
# we always remove existing deps as we don't know what was previously
# installed or in the host ./deps directory before running this script
if 'local' not in DOCKER_TAG or OLYMPIA_DEPS == 'production':
print('Removing existing deps')
for item in os.listdir('/deps'):
item_path = os.path.join('/deps', item)
if os.path.isdir(item_path) and item != 'cache':
shutil.rmtree(item_path)
else:
print('Updating existing deps')

# Copy package.json files
copy_package_json()

# Prepare the includes lists
pip_includes = []
npm_includes = []

# PIP_COMMAND is set by the Dockerfile
pip_command = os.environ['PIP_COMMAND']
pip_args = pip_command.split() + [
'install',
'--progress-bar=off',
'--no-deps',
'--exists-action=w',
]

# NPM_ARGS is set by the Dockerfile
npm_args_env = os.environ['NPM_ARGS']
npm_args = [
'npm',
'install',
'--no-save',
'--no-audit',
'--no-fund',
] + npm_args_env.split()

# Add the relevant targets to the includes lists
for target in targets:
pip_includes.append(target)
pip_args.extend(['-r', f'requirements/{target}.txt'])
if target in ALLOWED_NPM_TARGETS:
npm_includes.append(target)
npm_args.extend(['--include', target])

if pip_includes:
# Install pip dependencies
print(f"Installing pip dependencies: {', '.join(pip_includes)} \n")
subprocess.run(pip_args, check=True)

if npm_includes:
# Install npm dependencies
print(f"Installing npm dependencies: {', '.join(npm_includes)} \n")
subprocess.run(npm_args, check=True)


if __name__ == '__main__':
main(sys.argv[1:])
Loading

0 comments on commit c59e883

Please sign in to comment.