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

Populate user dir once (#44) #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 18 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ USER www-data
# Define Grav specific version of Grav or use latest stable
ARG GRAV_VERSION=latest

# Install grav
# Install grav (skip user dir)
WORKDIR /var/www
RUN curl -o grav-admin.zip -SL https://getgrav.org/download/core/grav-admin/${GRAV_VERSION} && \
unzip grav-admin.zip && \
mv -T /var/www/grav-admin /var/www/html && \
for file in $(ls -A "grav-admin/" | egrep -v user); do mv "grav-admin/$file" "html/"; done && \
rm grav-admin.zip

# Create cron job for Grav maintenance scripts
Expand All @@ -70,9 +70,23 @@ USER root
# Copy init scripts
# COPY docker-entrypoint.sh /entrypoint.sh

# Create script that populates user dir
RUN { \
echo '#!/bin/bash'; \
echo '# Ensure user dir exists'; \
echo 'mkdir -p /var/www/html/user/'; \
echo '# Ensure user dir is owned by user www-data'; \
echo 'chown www-data: /var/www/html/user/'; \
echo '# Populate user dir if it is empty'; \
echo 'if test -n "$(find /var/www/html/user -maxdepth 0 -empty)" ; then'; \
echo 'cp -rp /var/www/grav-admin/user/* /var/www/html/user/'; \
echo 'fi'; \
} > /usr/local/bin/populate-userdir && \
chmod +x /usr/local/bin/populate-userdir

# provide container inside image for data persistence
VOLUME ["/var/www/html"]
VOLUME ["/var/www/html/backup", "/var/www/html/logs", "/var/www/html/user"]

# ENTRYPOINT ["/entrypoint.sh"]
# CMD ["apache2-foreground"]
CMD ["sh", "-c", "cron && apache2-foreground"]
CMD ["sh", "-c", "populate-userdir && cron && apache2-foreground"]
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ This currently is pretty minimal and uses:

## Persisting data

To save the Grav site data to the host file system (so that it persists even after the container has been removed), simply map the container's `/var/www/html` directory to a named Docker volume or to a directory on the host.
To save the Grav site data to the host file system (so that it persists even after the container has been removed), simply map the container's `/var/www/html/user` directory to a named Docker volume or to a directory on the host.

> If the mapped directory or named volume is empty, it will be automatically populated with a fresh install of Grav the first time that the container starts. However, once the directory/volume has been populated, the data will persist and will not be overwritten the next time the container starts.
> If the mapped directory or named volume is empty, it will be automatically populated with a fresh user dir the first time that the container starts. However, once the directory/volume has been populated, the data will persist and will not be overwritten the next time the container starts.

This also applies for '/var/www/backup' and '/var/www/logs' except population at first startup.

## Building the image from Dockerfile

Expand All @@ -35,7 +37,7 @@ Point browser to `http://localhost:8000` and create user account...
## Running Grav Image with Latest Grav + Admin with a named volume (can be used in production)

```
docker run -d -p 8000:80 --restart always -v grav_data:/var/www/html grav:latest
docker run -d -p 8000:80 --restart always -v grav_backup:/var/www/backup -v grav_logs:/var/www/logs -v gravi_user:/var/www/html/user grav:latest
```

## Running Grav Image with docker-compose and a volume mapped to a local directory
Expand Down