Skip to content

Commit e409348

Browse files
author
Tim Martin
committed
unify use of static drupal image for local and static builds
1 parent ab565b4 commit e409348

9 files changed

+73
-77
lines changed

Dockerfile

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
# syntax=docker/dockerfile:experimental
2+
# Dockerfile for drupal-static build
3+
24
ARG REPOSITORY
35
ARG TAG
46
FROM ${REPOSITORY}/drupal:${TAG}
57

6-
COPY --chown=0:0 rootfs /
7-
COPY --chown=nginx:www-data codebase /var/www/drupal/
8-
98
USER nginx
10-
RUN echo "Creating tmp directory " && \
11-
mkdir -m 0775 -p /var/www/drupal/web/sites/default/files/tmp && \
12-
mkdir -m 0755 -p /tmp/private && \
13-
echo "Copy Generic File" && \
14-
if [ ! -f web/sites/default/files/generic.png ] ; then \
15-
cp "web/core/modules/media/images/icons/generic.png" "web/sites/default/files/generic.png" ; \
16-
fi
17-
18-
USER root
19-
# Final permissions sets:
20-
RUN bash /var/www/drupal/fix_permissions.sh /var/www/drupal/web nginx
219

2210
# Run composer install as application user:
23-
USER nginx
24-
RUN COMPOSER_MEMORY_LIMIT=-1 COMPOSER_DISCARD_CHANGES=true composer install --no-interaction --no-progress
25-
26-
# Normal startup (via /init) must happen as root:
11+
# Normal startup (via /init) must also happen as root
2712
USER root
13+
COPY --chown=nginx:www-data codebase /var/www/drupal/
14+
COPY --chown=0:0 rootfs /
15+
16+
RUN COMPOSER_MEMORY_LIMIT=-1 COMPOSER_DISCARD_CHANGES=true composer install --no-interaction --no-progress && \
17+
chmod 0750 /var/www/drupal/fix_permissions.sh && \
18+
/var/www/drupal/fix_permissions.sh /var/www/drupal/web nginx
2819

codebase/fix_permissions.sh

100644100755
Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ echo -e $help
1717
exit
1818
fi
1919

20-
cd $path
21-
2220
set -e
23-
#CHMOD="echo /bin/chmod"
24-
CHMOD="/bin/chmod -v"
21+
22+
### IDC Customizations below here to remove multiple recursive find commands:
23+
24+
CHMOD="/bin/chmod"
25+
26+
cd $path
2527

2628
echo -e "Fixing directory permissions beneath '$path'"
2729
find . -type d \( \
@@ -39,22 +41,3 @@ find . -type f \( \
3941
#> /tmp/fix_permissions-files.log
4042

4143
exit 0
42-
43-
# This is now performed in the Docker COPY layer:
44-
#echo -e "Changing ownership of all contents of \"${path}\" :\n user => \"${user}\" \t group => \"${group}\"\n"
45-
#chown -R ${user}:${group} .
46-
47-
# Replaced by above finds:
48-
#echo "Changing permissions of all directories inside \"${path}\" to \"750\"..."
49-
#1 find . -type d -exec chmod u=rwx,g=rx,o= {} \;
50-
#echo -e "Changing permissions of all files inside \"${path}\" to \"640\"...\n"
51-
#2 find . -type f -exec chmod u=rw,g=r,o= {} \;
52-
#
53-
#cd $path/sites;
54-
#
55-
#echo "Changing permissions of \"files\" directories in \"${path}/sites\" to \"770\"..."
56-
#3 find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
57-
#echo "Changing permissions of all files inside all \"files\" directories in \"${path}/sites\" to \"660\"..."
58-
#4 find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chmod ug=rw,o= "$FILE"; done
59-
#echo "Changing permissions of all directories inside all \"files\" directories in \"${path}/sites\" to \"770\"..."
60-
#5 find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmod ug=rwx,o= "$DIR"; done

codebase/web/sites/default/settings.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,14 @@
792792
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
793793
include $app_root . '/' . $site_path . '/settings.local.php';
794794
}
795+
$settings['config_sync_directory'] = '/var/www/drupal/config/sync';
796+
$settings['flysystem']['fedora']['driver'] = 'fedora';
797+
$settings['flysystem']['fedora']['config']['root'] = 'http://fcrepo.isle-dc.localhost/fcrepo/rest/';
798+
$databases['default']['default']['database'] = 'drupal_default';
799+
$databases['default']['default']['username'] = 'drupal_default';
800+
$databases['default']['default']['password'] = 'password';
801+
$databases['default']['default']['host'] = 'mariadb-idc.traefik.me';
802+
$databases['default']['default']['port'] = '3306';
803+
$databases['default']['default']['prefix'] = '';
804+
$databases['default']['default']['driver'] = 'mysql';
805+
$databases['default']['default']['namespace'] = 'Drupal\\Core\\Database\\Driver\\mysql';

docker-compose.drupal-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ volumes:
1515
solr-data:
1616
services:
1717
drupal:
18-
image: ${REPOSITORY:-islandora}/drupal-dev:${TAG:-latest}
18+
image: ${REPOSITORY:-islandora}/drupal-dev:static
19+
#image: ${REPOSITORY:-islandora}/drupal-dev:${TAG:-latest}
1920
# Uncomment below to PHP commands executed on container start, or PHP commands (e.g. drush) run from the CLI
2021
# (significantly slows down the container startup)
2122
# If debugging container startup is not necessary, consider setting the environment variables within a shell via

docker-compose.local.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ volumes:
1515
solr-data:
1616
services:
1717
drupal:
18-
image: ${REPOSITORY:-islandora}/drupal:${TAG:-latest}
18+
#image: ${REPOSITORY:-islandora}/drupal:${DRUPAL_STATIC_TAG:-${TAG:-latest}}
19+
image: ${REPOSITORY:-islandora}/drupal-static:static
1920
volumes:
2021
- ./codebase:/var/www/drupal:delegated
2122
- drupal-sites-data:/var/www/drupal/web/sites/default/files

docker-compose.static.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ services:
2020
args:
2121
TAG: ${TAG}
2222
REPOSITORY: ${REPOSITORY}
23-
image: ${REPOSITORY}/drupal-static:${DRUPAL_STATIC_TAG}
23+
#image: ${REPOSITORY}/drupal-static:${DRUPAL_STATIC_TAG}
24+
image: ${REPOSITORY}/drupal-static:static
2425
environment:
2526
DRUPAL_INSTANCE: static
2627
volumes:

idc.Makefile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ snapshot-push:
102102

103103
.PHONY: up
104104
.SILENT: up
105-
up: download-default-certs docker-compose.yml start
105+
up: download-default-certs static-drupal-image docker-compose.yml start
106106

107107
.PHONY: down
108108
.SILENT: down
@@ -163,7 +163,6 @@ start:
163163
echo "Pre-existing Drupal state found, not loading db from snapshot"; \
164164
${MAKE} _docker-up-and-wait; \
165165
fi;
166-
-docker-compose exec -T drupal bash -lc "bash /var/www/drupal/scripts/bash/start_up.sh"
167166
$(MAKE) solr-cores
168167

169168
.PHONY: _docker-up-and-wait
@@ -193,12 +192,14 @@ static-drupal-image:
193192
else \
194193
echo "Using existing Drupal image $${EXISTING}" ; \
195194
fi
195+
docker tag ${REPOSITORY}/drupal-static:${GIT_TAG} ${REPOSITORY}/drupal-static:static
196196

197197
# Export a tar of the static drupal image
198198
.PHONY: static-drupal-image-export
199199
.SILENT: static-drupal-image-export
200200
static-drupal-image-export: static-drupal-image
201201
IMAGE=${REPOSITORY}/drupal-static:${GIT_TAG} ; \
202+
echo saving docker image $${IMAGE} ; \
202203
mkdir -p images ; \
203204
docker save $${IMAGE} > images/static-drupal.tar
204205

@@ -208,8 +209,8 @@ static-drupal-image-export: static-drupal-image
208209
.PHONY: static-docker-compose.yml
209210
.SILENT: static-docker-compose.yml
210211
static-docker-compose.yml: static-drupal-image
211-
ENV_FILE=.env ; \
212-
if [ "$(env)" != "" ] ; then ENV_FILE=$(env); fi; \
212+
ENV_FILE=.env
213+
if [ "$(env)" != "" ] ; then echo inherited environment ; ENV_FILE=$(env); fi; \
213214
echo '' > .env_static && \
214215
while read line; do \
215216
if echo $$line | grep -q "ENVIRONMENT" ; then \
@@ -218,11 +219,24 @@ static-docker-compose.yml: static-drupal-image
218219
echo $$line >> .env_static ; \
219220
fi \
220221
done < $${ENV_FILE} && \
221-
echo DRUPAL_STATIC_TAG=${GIT_TAG} >> .env_static
222-
mv $${ENV_FILE} .env.bak
223-
mv .env_static $${ENV_FILE}
224-
$(MAKE) -B docker-compose.yml args="--env-file $${ENV_FILE}" || mv .env.bak $${ENV_FILE}
225-
if [ -f .env.bak ] ; then mv .env.bak $${ENV_FILE} ; fi
222+
echo setting xxDRUPAL_STATIC_TAG && \
223+
echo xxDRUPAL_STATIC_TAG=static >> .env_static
224+
mv ${ENV_FILE} .env.bak
225+
mv .env_static ${ENV_FILE}
226+
echo Building static drupal configuration
227+
#grep DRUPAL_STATIC_TAG= ${ENV_FILE}
228+
grep ENVIRONMENT= ${ENV_FILE}
229+
$(MAKE) -B docker-compose.yml args="--env-file ${ENV_FILE}" || ( echo reverting ${ENV_FILE} ; mv -v .env.bak ${ENV_FILE} )
230+
231+
.SILENT: revert-env
232+
.PHONY: revert-env
233+
234+
revert-env:
235+
ENV_FILE=.env
236+
if [ -f .env.bak ] ; then \
237+
echo reverting ${ENV_FILE} ; \
238+
mv -v .env.bak ${ENV_FILE} ; \
239+
fi
226240

227241
.SILENT: test
228242
.PHONY: test

rootfs/etc/cont-init.d/04-custom-setup.sh

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,6 @@ function main {
2525

2626
# Create missing solr cores.
2727
create_solr_core_with_default_config "${site}"
28-
29-
# JHU: no triplestore
30-
# Create namespace assumed one per site.
31-
#create_blazegraph_namespace_with_default_properties "${site}"
32-
33-
# JHU: SKIP BELOW
34-
exit 0
35-
36-
# Need to run migration to get expected default content, now that our required services are running.
37-
import_islandora_migrations "${site}"
38-
# Workaround for this issue (only seems to apply to islandora_fits):
39-
# https://www.drupal.org/project/drupal/issues/2914213
40-
cat << EOF > /tmp/fix.php
41-
<?php
42-
use Drupal\taxonomy\Entity\Term;
43-
\$term = array_pop(taxonomy_term_load_multiple_by_name('FITS File'));
44-
\$default = ['uri' => 'https://projects.iq.harvard.edu/fits'];
45-
\$term->set('field_external_uri', \$default);
46-
\$term->save();
47-
EOF
48-
drush php:script /tmp/fix.php
49-
# Rebuild the cache.
50-
drush cr
5128
}
5229
main
30+
exit 0

rootfs/etc/cont-init.d/99-startup.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ echo " - Running a Start up script
88
echo " -------------------------------------------------------------------------- "
99
echo ""
1010

11+
DRUPAL_DIR=/var/www/drupal
12+
13+
echo "Creating tmp and private directories"
14+
for d in $DRUPAL_DIR/web/sites/default/files/tmp /tmp/private ; do
15+
echo " directory: '$d'"
16+
mkdir -m 0775 -p "$d"
17+
chown -R nginx:nginx "$d"
18+
done
19+
20+
chmod 0750 $DRUPAL_DIR/fix_permissions.sh
21+
$DRUPAL_DIR/fix_permissions.sh $DRUPAL_DIR/web nginx
22+
1123
# This is a workaround for a bug.
1224
drush cdel core.extension module.search_api_solr_defaults || true
1325
drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='search_api_solr_defaults';" || true
@@ -17,7 +29,6 @@ drush php-eval "\Drupal::keyValue('system.schema')->delete('matomo')" || true
1729
drush config:import -y
1830

1931
# Fix for Github runner "the input device is not a TTY" error
20-
bash /var/www/drupal/fix_permissions.sh /var/www/drupal/web nginx
2132
drush search-api-solr:install-missing-fieldtypes || true
2233
drush search-api:rebuild-tracker || true
2334
drush search-api-solr:finalize-index || true
@@ -31,6 +42,11 @@ drush -d status
3142
CURRENT_VERSION=$(drush cr && drush core-status --fields=drupal-version | cut -d\: -f2 | sed 's/ //g')
3243
echo "Current Drupal version: $CURRENT_VERSION"
3344

45+
echo "Copy Generic File"
46+
if [ ! -f web/sites/default/files/generic.png ] ; then
47+
cp "web/core/modules/media/images/icons/generic.png" "web/sites/default/files/generic.png"
48+
fi
49+
3450
echo ""
3551
echo ""
3652
echo " -------------------------------------------------------------------------- "

0 commit comments

Comments
 (0)