Skip to content

Commit

Permalink
Make "up" go Brrrrrrrr
Browse files Browse the repository at this point in the history
data seed command synchronizes storage directory

Remove storage volume (reuse olympia volume)

Remove data_olympia (use anonymous volume)

Remove sources from development DOCKER_TARGET

Invert docker-compose.ci to docker-compose.dev (update defaults in setup script to support prod mode in ci)
  • Loading branch information
KevinMind committed Oct 18, 2024
1 parent 436ca0e commit b6ec560
Show file tree
Hide file tree
Showing 34 changed files with 272 additions and 163 deletions.
8 changes: 1 addition & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ src/olympia/discovery/strings.jinja2
static-build/*
static/css/node_lib/*
static/js/node_lib/*
storage/files/*
storage/git-storage/*
storage/guarded-addons/*
storage/mlbf/*
storage/shared_storage/*
storage/sitemaps/*
storage
tmp/*

# Additionally ignore these files from the docker build that are not in .gitignore
Expand All @@ -62,7 +57,6 @@ tmp/*
.github
docs
private
storage
docker-bake.hcl
docker-compose*.yml
Dockerfile*
Expand Down
5 changes: 1 addition & 4 deletions .github/actions/build-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ inputs:
version:
required: true
description: The image version to tag with
target:
required: true
description: The stage to target in the build
push:
required: false
description: Push the image?
Expand Down Expand Up @@ -57,7 +54,7 @@ runs:
- name: Create .env and version.json files
shell: bash
run: |
echo "DOCKER_TARGET=${{ inputs.target }}" >> $GITHUB_ENV
echo "DOCKER_TARGET=production" >> $GITHUB_ENV
echo "DOCKER_VERSION=${{ steps.meta.outputs.version }}" >> $GITHUB_ENV
echo "DOCKER_COMMIT=${{ steps.context.outputs.git_sha }}" >> $GITHUB_ENV
echo "DOCKER_BUILD=${{ steps.context.outputs.git_build_url }}" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/run-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
compose_file:
description: 'The docker-compose file to use'
required: false
default: 'docker-compose.yml:docker-compose.ci.yml'
default: 'docker-compose.yml'
logs:
description: 'Show logs'
required: false
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,28 @@ jobs:
-
name: Needs Locale Compilation
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
run: |
make compile_locales
make test_needs_locales_compilation
-
name: Static Assets
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
run: make test_static_assets
-
name: Internal Routes
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
run: make test_internal_routes_allowed
-
name: Elastic Search
services: ''
compose_file: docker-compose.yml:docker-compose.ci.yml
run: make test_es_tests
-
name: Codestyle
services: web
compose_file: docker-compose.yml:docker-compose.ci.yml
run: make lint-codestyle
-
name: Manage Check
services: web nginx
compose_file: docker-compose.yml:docker-compose.ci.yml
run: make check
steps:
- uses: actions/checkout@v4
Expand All @@ -78,5 +72,4 @@ jobs:
version: ${{ inputs.version }}
digest: ${{ inputs.digest }}
services: ${{ matrix.services }}
compose_file: ${{ matrix.compose_file }}
run: ${{ matrix.run }}
2 changes: 1 addition & 1 deletion .github/workflows/_test_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
services: ''
digest: ${{ inputs.digest }}
version: ${{ inputs.version }}
compose_file: docker-compose.yml
compose_file: docker-compose.yml:docker-compose.dev.yml
run: |
split="--splits ${{ needs.test_config.outputs.splits }}"
group="--group ${{ matrix.group }}"
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ jobs:
registry: ${{ steps.docker_hub.outputs.registry }}
image: ${{ steps.docker_hub.outputs.image }}
version: ci-${{ needs.context.outputs.docker_version }}
target: development
push: true

test_make_docker_configuration:
Expand All @@ -88,7 +87,7 @@ jobs:
shell: bash
run: |
docker compose version
npm exec jest -- ./tests/make --runInBand
make test_setup
test_run_docker_action:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -171,7 +170,7 @@ jobs:
with:
digest: ${{ needs.build.outputs.digest }}
version: ${{ needs.build.outputs.version }}
compose_file: docker-compose.yml
compose_file: docker-compose.yml:docker-compose.dev.yml
run: |
make docs
Expand Down Expand Up @@ -222,7 +221,7 @@ jobs:
with:
digest: ${{ needs.build.outputs.digest }}
version: ${{ needs.build.outputs.version }}
compose_file: docker-compose.yml
compose_file: docker-compose.yml:docker-compose.dev.yml
run: make extract_locales

- name: Push Locales
Expand Down Expand Up @@ -289,7 +288,6 @@ jobs:
registry: ${{ steps.docker_hub.outputs.registry }}
image: ${{ steps.docker_hub.outputs.image }}
version: ${{ needs.context.outputs.docker_version }}
target: production
push: true

push_gar:
Expand Down Expand Up @@ -321,5 +319,4 @@ jobs:
registry: ${{ steps.docker_gar.outputs.registry }}
image: ${{ steps.docker_gar.outputs.image }}
version: ${{ needs.context.outputs.docker_version }}
target: production
push: true
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@ src/olympia/discovery/strings.jinja2
static-build/*
static/css/node_lib/*
static/js/node_lib/*
storage/files/*
storage/git-storage/*
storage/guarded-addons/*
storage/mlbf/*
storage/shared_storage/*
storage/sitemaps/*
storage
tmp/*

# End of .gitignore. Please keep this in sync with the top section of .dockerignore

# do not ignore the following files
!docker-compose.development.yml
!docker-compose.dev.yml
!docker-compose.private.yml
!private/README.md
31 changes: 13 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ EOF
ARG DOCKER_TARGET
ENV DOCKER_TARGET=${DOCKER_TARGET}

# Add our custom mime types (required for for ts/json/md files)
COPY docker/etc/mime.types /etc/mime.types


# Define production dependencies as a single layer
# let's the rest of the stages inherit prod dependencies
# and makes copying the /deps dir to the final layer easy.
Expand All @@ -115,7 +119,10 @@ ${PIP_COMMAND} install --progress-bar=off --no-deps --exists-action=w -r require
npm ci ${NPM_ARGS} --include=prod
EOF

FROM base AS pip_development
# In the local development image, we stop with dependencies
# Everything else is about compiling production assets which is not needed
# in the typical development workflow.
FROM base AS development

RUN \
# Files required to install pip dependencies
Expand Down Expand Up @@ -168,35 +175,23 @@ echo "from olympia.lib.settings_base import *" > settings_local.py
DJANGO_SETTINGS_MODULE="settings_local" make -f Makefile-docker update_assets
EOF

FROM base AS sources
FROM base AS production

ARG DOCKER_BUILD DOCKER_COMMIT DOCKER_VERSION

ENV DOCKER_BUILD=${DOCKER_BUILD}
ENV DOCKER_COMMIT=${DOCKER_COMMIT}
ENV DOCKER_VERSION=${DOCKER_VERSION}

# Add our custom mime types (required for for ts/json/md files)
COPY docker/etc/mime.types /etc/mime.types
# Copy the rest of the source files from the host
COPY --chown=olympia:olympia . ${HOME}
# Copy compiled locales from builder
COPY --from=locales --chown=olympia:olympia ${HOME}/locale ${HOME}/locale
# Copy assets from assets
COPY --from=assets --chown=olympia:olympia ${HOME}/site-static ${HOME}/site-static
COPY --from=assets --chown=olympia:olympia ${HOME}/static-build ${HOME}/static-build

# Set shell back to sh until we can prove we can use bash at runtime
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
COPY --from=locales --chown=olympia:olympia ${HOME}/locale ${HOME}/locale
# Copy dependencies from `pip_production`
COPY --from=pip_production --chown=olympia:olympia /deps /deps


# Set shell back to sh until we can prove we can use bash at runtime
SHELL ["/bin/sh", "-c"]
4 changes: 4 additions & 0 deletions Makefile-os
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ help_submake:
@echo "\nAll other commands will be passed through to the docker 'web' container make:"
@make -f Makefile-docker help_submake

.PHONY: test_setup
test_setup:
npm exec jest -- ./tests/make --runInBand

.PHONY: setup
setup: ## create configuration files version.json and .env required to run this project
for path in $(CLEAN_PATHS); do rm -rf "$(PWD)/$$path" && echo "$$path removed"; done
Expand Down
13 changes: 0 additions & 13 deletions docker-compose.ci.yml

This file was deleted.

17 changes: 17 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
worker:
environment:
- HOST_UID
volumes:
- ./:/data/olympia
# Don't mount generated files. They only exist in the container
# and would otherwiser be deleted by mounbting data_olympia
- /data/olympia/static-build
- /data/olympia/site-static
- ./package.json:/deps/package.json
- ./package-lock.json:/deps/package-lock.json

web:
extends:
service: worker

37 changes: 4 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ x-env-mapping: &env
- HISTIGNORE=ls:exit:"cd .."
- HISTCONTROL=erasedups
- CIRCLECI
- HOST_UID
- HOST_UID=9500
- DEBUG
- DATA_BACKUP_SKIP

Expand Down Expand Up @@ -51,15 +51,6 @@ services:
"--",
"celery -A olympia.amo.celery:app worker -E -c 2 --loglevel=INFO",
]
volumes:
- data_olympia:/data/olympia
# Don't mount generated files. They only exist in the container
# and would otherwiser be deleted by mounbting data_olympia
- /data/olympia/static-build
- /data/olympia/site-static
- storage:/data/olympia/storage
- ./package.json:/deps/package.json
- ./package-lock.json:/deps/package-lock.json
extra_hosts:
- "olympia.test:127.0.0.1"
restart: on-failure:5
Expand Down Expand Up @@ -99,8 +90,7 @@ services:
image: nginx
volumes:
- ./docker/nginx/addons.conf:/etc/nginx/conf.d/addons.conf
- ./static:/srv/static
- storage:/srv/user-media
- ./:/srv
ports:
- "80:80"
networks:
Expand Down Expand Up @@ -143,13 +133,9 @@ services:
- "discovery.type=single-node"
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
mem_limit: 2g
volumes:
- data_elasticsearch:/usr/share/elasticsearch/data

redis:
image: redis:6.2
volumes:
- data_redis:/data

rabbitmq:
image: rabbitmq:3.12
Expand All @@ -160,8 +146,6 @@ services:
- RABBITMQ_DEFAULT_USER=olympia
- RABBITMQ_DEFAULT_PASS=olympia
- RABBITMQ_DEFAULT_VHOST=olympia
volumes:
- data_rabbitmq:/var/lib/rabbitmq

autograph:
image: mozilla/autograph:3.3.2
Expand Down Expand Up @@ -191,23 +175,10 @@ networks:
default:

volumes:
data_redis:
data_elasticsearch:
data_mysqld:
# Keep this value in sync with Makefile-os
# External volumes must be manually created/destroyed
name: addons-server_data_mysqld
external: true
data_rabbitmq:
data_olympia:
driver: local
driver_opts:
type: none
o: bind
device: ${PWD}
storage:
driver: local
driver_opts:
type: none
o: bind
device: ./storage


4 changes: 2 additions & 2 deletions docker/nginx/addons.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server {

location /data/olympia/storage/ {
internal;
alias /srv/user-media/;
alias /srv/storage/;
}

location /static/ {
Expand All @@ -20,7 +20,7 @@ server {
}

location /user-media/ {
alias /srv/user-media/shared_storage/uploads/;
alias /srv/storage/shared_storage/uploads/;
}

location ~ ^/api/ {
Expand Down
Loading

0 comments on commit b6ec560

Please sign in to comment.