Zend certified PHP/Magento developer

Static files don’t fully deploy on a docker-based deployment

I’m having trouble implementing the deploy strategy described in e.g. https://info2.magento.com/rs/585-GGD-959/images/The%20New%20Magento%202.2%20Deployment%20Capabilities%20%26%20Patterns.pdf

I build a docker image ready to be deployed as shown on pages 8 or 9 of the document, using a fresh magento + composer.json + own modules + own themes + env.php + config.php + an initial sql dump. This is used in docker compose to create a local env.

When I start the env I see the site without styles, due to many static files being missing. For example /static/version1643293995/frontend/Magento/luma/es_ES/css/print.css.

I can generate the missing statics if I log into the running container and run bin/magento setup:static-content:deploy -f, but this clearly defeats the purpose of this deployment.

I would appreciate any hint on what I’m missing here.

Thanks!

The Dockerfile is as follows:

# syntax = docker/dockerfile:1.3
FROM ${REGISTRY}/magento-base:2.4.3

ENV APACHE_DOCUMENTROOT="/opt/magento"
ENV MAGENTO_HOME="/opt/magento"

# COPY DATA
COPY --chown=www-data:www-data magento/ /opt/magento/
RUN chown -R www-data:www-data /opt/magento/pub/* /opt/magento/var/*

# Build
USER www-data
RUN composer update --no-cache 
    && bin/magento setup:di:compile 
    && bin/magento setup:static-content:deploy -f 

COPY --chown=www-data:www-data files/ /

WORKDIR /opt/magento
USER root

# Magento (80)
EXPOSE 80 

docker-compose.yml

version: '3.1'

services:
  mysql:
    image: mysql:8
    command: ["--default-authentication-plugin=mysql_native_password", "--log_bin_trust_function_creators=1"]
    restart: always
    environment:
      MYSQL_DATABASE: magento
      MYSQL_ROOT_PASSWORD: magento
      MYSQL_USER: magento
      MYSQL_PASSWORD: magento
    ports:
      - "3306:3306"
    volumes:
      - 'mysql_data:/var/lib/mysql'
      - "./initial_schema.sql:/docker-entrypoint-initdb.d/00-schema.sql"
  elasticsearch:
    image: docker.io/bitnami/elasticsearch:7
    ports:
      - '9200:9200'
    volumes:
      - 'elasticsearch_data:/bitnami/elasticsearch/data'
  magento: 
    image: <registry>/magento
    ports:
      - '80:80'
    environment:
      - MAGENTO_HOST=localhost
      - MAGENTO_DATABASE_HOST=mysql
      - MAGENTO_DATABASE_PORT_NUMBER=3306
      - MAGENTO_DATABASE_USER=magento
      - MAGENTO_DATABASE_PASSWORD=magento
      - MAGENTO_DATABASE_NAME=magento
      - ELASTICSEARCH_HOST=elasticsearch
      - ELASTICSEARCH_PORT_NUMBER=9200
      - MAGENTO_MODE=production
      - REDIS_HOST=redis
    depends_on:
      - mysql
      - elasticsearch
      - redis
  redis:
    image: "redis:alpine"
    hostname: redis
    ports:
      - "6379:6379"
    restart: always
volumes:
  mysql_data:
    driver: local
  elasticsearch_data:
    driver: local