Skip to content

Commit

Permalink
docker volume mounting tweaks to nondev script
Browse files Browse the repository at this point in the history
  • Loading branch information
clpetersonucf committed Nov 18, 2024
1 parent 1b63662 commit 35efc33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
12 changes: 7 additions & 5 deletions docker/docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

services:
webserver:
ports:
- "80:80" # main materia
- "443:443" # main materia
- "8008:8008" # static files (simulates a different domain sandbox & cdn)
volumes:
- ../public:/var/www/html/public:ro
- uploaded_widgets:/var/www/html/public/widget/:ro
- ../public/widget:/var/www/html/public/widget/:ro
- ./config/nginx/key.pem:/etc/nginx/conf.d/key.pem:ro
- ./config/nginx/cert.pem:/etc/nginx/conf.d/cert.pem:ro
- ./config/nginx/nginx-dev.conf:/etc/nginx/nginx.conf:ro
Expand All @@ -17,7 +21,7 @@ services:
- .env.local
volumes:
- ..:/var/www/html/
- uploaded_widgets:/var/www/html/public/widget/
- ../public/widget:/var/www/html/public/widget/:rw
- ./dockerfiles/wait-for-it.sh:/wait-for-it.sh
depends_on:
- fakes3
Expand Down Expand Up @@ -59,6 +63,4 @@ services:
- backend

volumes:
# static_files: {} # compiled js/css and uploaded widgets
uploaded_media: {} # uploaded media files
uploaded_widgets: {}
uploaded_media: {} # uploaded media files
1 change: 0 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
ports:
- "80:80" # main materia
- "443:443" # main materia
- "8008:8008" # static files (simulates a different domain sandbox & cdn)
networks:
- frontend
depends_on:
Expand Down
46 changes: 22 additions & 24 deletions docker/run_first_for_nondev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,23 @@ echo ""

docker compose pull app webserver

# Remove the unnecessary volume mounts for the app service
# Remove the fakes3 service from the docker-compose override
yq e 'del(.services.fakes3)' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
yq e 'del(.services.app.depends_on[] | select(. == "fakes3"))' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Clean volume mounts from the app service
yq e 'del(.services.app.volumes)' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
yq e '.services.app.volumes += ["uploaded_widgets:/var/www/html/public/widget/"]' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Re-apply the widgets volume to the app service
yq e '.services.app.volumes += ["../public/widget/:/var/www/html/public/widget/:rw"]' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Add an additional compiled_assets volume definition
yq e '.volumes.compiled_assets = {}' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Add compiled_assets volume to the app service
yq e '.services.app.volumes += ["compiled_assets:/var/www/html/public"]' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Remove the host machine public mount from the webserver definition
yq e 'del(.services.webserver.volumes[] | select(. == "../public:/var/www/html/public:ro"))' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Remove port 8008 from the port mounts on the webserver service
yq e 'del(.services.webserver.ports[] | select(. == "8008:8008"))' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
# Add compiled_assets volume to the webserver service
yq e '.services.webserver.volumes += ["compiled_assets:/var/www/html/public"]' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml

# Update nginx config to use non-dev configuration
yq e '(.services.webserver.volumes[] | select(contains("nginx-dev.conf"))) |= sub("nginx-dev.conf", "nginx-nondev.conf")' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
Expand Down Expand Up @@ -167,28 +181,20 @@ fi

echo ""
echo "Finally, let's select the asset storage driver: where user-uploaded media will be stored."
echo "1. s3 (default for local dev, which uses fakes3. Addl configs required for production)"
echo "2. file"
echo "3. db (not recommended at scale)"
read -p "Enter an option (1, 2, or 3): " asset_driver_choice
echo "1. file"
echo "2. db (not recommended at scale)"
read -p "Enter an option (1 or 2): " asset_driver_choice

if [ "$asset_driver_choice" == "1" ]; then
echo "Setting ASSET_STORAGE_DRIVER env variable to s3"
docker compose pull fakes3
elif [ "$asset_driver_choice" == "2" ]; then
echo "Setting ASSET_STORAGE_DRIVER env variable to file"
echo "ASSET_STORAGE_DRIVER=file" >> .env.local

# Remove the fakes3 service from the docker-compose override
yq e 'del(.services.fakes3)' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
yq e 'del(.services.app.depends_on[] | select(. == "fakes3"))' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
elif [ "$asset_driver_choice" == "3" ]; then
yq e '.services.app.volumes += ["../fuel/app/media/:/var/www/html/fuel/app/media/:rw"]' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml

elif [ "$asset_driver_choice" == "2" ]; then
echo "Setting ASSET_STORAGE_DRIVER env variable to db"
echo "ASSET_STORAGE_DRIVER=db" >> .env.local

# Remove the fakes3 service from the docker-compose override
yq e 'del(.services.fakes3)' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
yq e 'del(.services.app.depends_on[] | select(. == "fakes3"))' docker-compose.override.yml > temp.yml && mv temp.yml docker-compose.override.yml
else
echo "Invalid choice."
exit 1
Expand Down Expand Up @@ -225,14 +231,6 @@ else
echo "Skipping widget installation: note that this requires a functional DB configuration. If needed, the widget install process can be performed after the db is configured."
fi

# assets must be build using a node container so they can be mounted to the webserver filesystem
# this will make the assets available in public/dist
source run_build_assets.sh

# symlink the assets from public/dist to public/ - since we're using the prod configuration, assets will be served from public/
ln -s ../public/dist/js ../public/js
ln -s ../public/dist/css ../public/css

echo ""
echo -e "Materia will be hosted on \033[32m$docker_ip\033[0m"
echo -e "A default superuser was created using your shell user \033[32m$USER\033[0m with password \033[32mkogneato\033[0m"
Expand Down

0 comments on commit 35efc33

Please sign in to comment.