From 32aa8daca0186f9bbb5a733a5e60d6eddf661f60 Mon Sep 17 00:00:00 2001 From: Josh d'Entremont Date: Fri, 24 Feb 2023 15:30:45 -0400 Subject: [PATCH 1/9] added namespace to make build --- Makefile | 2 +- sample.env | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 007fd9340..faab10b96 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,7 @@ build: if [ ! -f $(PROJECT_DRUPAL_DOCKERFILE) ]; then \ cp "$(CURDIR)/sample.Dockerfile" $(PROJECT_DRUPAL_DOCKERFILE); \ fi - docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t $(COMPOSE_PROJECT_NAME)_drupal --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . + docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . .PHONY: set-files-owner diff --git a/sample.env b/sample.env index be0f23474..e8822a8b5 100644 --- a/sample.env +++ b/sample.env @@ -32,6 +32,10 @@ DOCKER_BUILDKIT=1 # Dockerfile to use when building the custom project. PROJECT_DRUPAL_DOCKERFILE=Dockerfile +# Custom namespace for your created Drupal images (eg. your dockerhub username) +# Used in the image name when running `make build` +CUSTOM_DRUPAL_NAMESPACE=mynamespace + # Includes `traefik` as a service, if false assume we are sharing a traefik # from another project. INCLUDE_TRAEFIK_SERVICE=true From 946ae33bf50074504403cd91946413f576c7aa80 Mon Sep 17 00:00:00 2001 From: Josh d'Entremont Date: Fri, 24 Feb 2023 15:46:43 -0400 Subject: [PATCH 2/9] added make push-image for pushing custom drupal images --- Makefile | 4 ++++ sample.env | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index faab10b96..138ce80e5 100644 --- a/Makefile +++ b/Makefile @@ -120,6 +120,10 @@ build: fi docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . +.PHONY: push-image +## Push your custom drupal image to dockerhub or a container registry +push-image: + docker push "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" .PHONY: set-files-owner ## Updates codebase folder to be owned by the host user and nginx group. diff --git a/sample.env b/sample.env index e8822a8b5..1ba353c5f 100644 --- a/sample.env +++ b/sample.env @@ -33,7 +33,8 @@ DOCKER_BUILDKIT=1 PROJECT_DRUPAL_DOCKERFILE=Dockerfile # Custom namespace for your created Drupal images (eg. your dockerhub username) -# Used in the image name when running `make build` +# preface this with a URL to use a container registry like Github or Gitlab +# Used in the image name when running `make build` and `make push-image` CUSTOM_DRUPAL_NAMESPACE=mynamespace # Includes `traefik` as a service, if false assume we are sharing a traefik From d4f4b5c231e61677de4be0aeede087c188a11284 Mon Sep 17 00:00:00 2001 From: Josh d'Entremont Date: Thu, 2 Mar 2023 14:13:56 -0400 Subject: [PATCH 3/9] added make production for spinning up a production site from a custom image --- Makefile | 18 +++++++++++++----- build/docker-compose/docker-compose.custom.yml | 4 +--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 138ce80e5..3f57ef4f1 100644 --- a/Makefile +++ b/Makefile @@ -118,12 +118,8 @@ build: if [ ! -f $(PROJECT_DRUPAL_DOCKERFILE) ]; then \ cp "$(CURDIR)/sample.Dockerfile" $(PROJECT_DRUPAL_DOCKERFILE); \ fi - docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . + docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t $(COMPOSE_PROJECT_NAME)_drupal --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . -.PHONY: push-image -## Push your custom drupal image to dockerhub or a container registry -push-image: - docker push "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" .PHONY: set-files-owner ## Updates codebase folder to be owned by the host user and nginx group. @@ -154,7 +150,9 @@ update-settings-php: docker-compose exec -T drupal with-contenv bash -lc "if [ ! -f /var/www/drupal/web/sites/default/settings.php ]; then cp /var/www/drupal/web/sites/default/default.settings.php /var/www/drupal/web/sites/default/settings.php; fi" docker-compose exec -T drupal with-contenv bash -lc "for_all_sites update_settings_php" # Make sure the host user can read the settings.php files after they have been updated. +ifneq ($(ENVIRONMENT), custom) sudo find ./codebase -type f -name "settings.php" -exec chown $(shell id -u):101 {} \; +endif .PHONY: update-config-from-environment ## Updates configuration from environment variables. @@ -568,3 +566,13 @@ starter-finalize: #docker-compose exec -T drupal with-contenv bash -lc 'chown -R `id -u`:nginx /var/www/drupal' #docker-compose exec -T drupal with-contenv bash -lc 'drush migrate:rollback islandora_defaults_tags,islandora_tags' $(MAKE) login + +.PHONY: production +production: generate-secrets + $(MAKE) download-default-certs + $(MAKE) -B docker-compose.yml + $(MAKE) pull + docker-compose up -d --remove-orphans + docker-compose exec -T drupal with-contenv bash -lc 'composer install; chown -R nginx:nginx .' + $(MAKE) remove_standard_profile_references_from_config drupal-database update-settings-php + docker-compose exec -T drupal with-contenv bash -lc "drush si -y --existing-config minimal --account-pass $(shell cat secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD)" diff --git a/build/docker-compose/docker-compose.custom.yml b/build/docker-compose/docker-compose.custom.yml index 83dcdccf0..bd8bda050 100644 --- a/build/docker-compose/docker-compose.custom.yml +++ b/build/docker-compose/docker-compose.custom.yml @@ -11,9 +11,7 @@ volumes: services: # The service name is drupal that is the default host name used by micro-services etc. drupal: - build: - context: ../../ - dockerfile: ${PROJECT_DRUPAL_DOCKERFILE:-./Dockerfile} + image: ${CUSTOM_DRUPAL_NAMESPACE}/${COMPOSE_PROJECT_NAME}_drupal:latest environment: # # Set environment variables that allow use to install from an existing configuration. From a5a09a734970f8729dc9829e5b259a919817bf55 Mon Sep 17 00:00:00 2001 From: Josh d'Entremont Date: Fri, 10 Mar 2023 10:50:44 -0400 Subject: [PATCH 4/9] adding back push-image and namespace in build that were accidentally removed --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3f57ef4f1..f05ab0b6c 100644 --- a/Makefile +++ b/Makefile @@ -118,8 +118,12 @@ build: if [ ! -f $(PROJECT_DRUPAL_DOCKERFILE) ]; then \ cp "$(CURDIR)/sample.Dockerfile" $(PROJECT_DRUPAL_DOCKERFILE); \ fi - docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t $(COMPOSE_PROJECT_NAME)_drupal --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . + docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t $(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . +.PHONY: push-image +## Push your custom drupal image to dockerhub or a container registry +push-image: + docker push "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" .PHONY: set-files-owner ## Updates codebase folder to be owned by the host user and nginx group. From 0cfb9ad6753e2dd9a725f2a9dbd0eaf5661bd568 Mon Sep 17 00:00:00 2001 From: Josh d'Entremont Date: Fri, 10 Mar 2023 16:31:32 -0400 Subject: [PATCH 5/9] updated README with instructions for starting a production site from a custom image --- README.md | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f4487c53b..9cd676315 100644 --- a/README.md +++ b/README.md @@ -164,37 +164,35 @@ Then you can `git push` your site to Github and `git clone` it down whenever you ## Custom Environment This environment is used to run your custom `drupal` image which can be produced -outside of this repository. You can specify the image in your `.env` file using -the settings `PROJECT_DRUPAL_DOCKERFILE` if you want to build it in the context -of this repository. You can also set the memory limits for each containers here as well. - -For convenience a `sample.Dockerfile` is provided from which you can generate a -custom image from the [codebase](./codebase) folder. For example if you followed -the guide above to create the codebase folder from the `islandora/demo` image. - -And then run it by changing `ENVIRONMENT` to be `custom` and regenerating the -`docker-compose.yml` file and building the image. - -```bash -make docker-compose.yml -make build -``` - -At this point you could run it using `docker-compose`: - -```bash -make up -# Or in some situations you could run this instead. -docker-compose up -d -``` - -To specify an image created outside of this repository, you can add the -following to `docker-compose.env.yml`: - -```yaml -drupal: - image: YOUR_CUSTOM_IMAGE -``` +outside of this repository, or from another isle-dc instance, such as a local +development environment as described above. You can specify a namespace and the +image name in your `.env` file. + +This assumes you have already created an image and have it stored in a container +registry like Dockerhub or Gitlab. If you are setting this up for the first time +you should first create a local environment as described above. Once you have +your local environment created you can do the following: +- In your .env set the name of the image to create using +`COMPOSE_PROJECT_NAME` and the namespace using `CUSTOM_DRUPAL_NAMESPACE` +- Run `make build` to create an image based on the codebase folder + - This will create an image named `namespace/projectname_drupal` +- Run `make push-image` to push that image to your container registry + +For convenience a `sample.Dockerfile` is provided which `make build` will use to +generate a custom image from the [codebase](./codebase) folder. For example if +you followed the guide above to create the codebase folder from the +`islandora/demo` image. + +Once you have done that you can create your production or staging site by: +- Modify your .env + - Set ENVIRONMENT=custom + - Set DOMAIN=yourdomain.com + - Set the namespace and the name of the image using + `CUSTOM_DRUPAL_NAMESPACE` and `COMPOSE_PROJECT_NAME` + - They should be the same values as on your local machine +- Create your production site using `make production` +- Export the database from your local machine and import it to your production +site ## Shutting down and bring back up To run a non-destructive shutdown and bring it back up without having to know the docker commands needed. This keeps all of the commands for basic operations within the make commands. From d5f15c9b2e7490e5737a35b51100bccab3490df1 Mon Sep 17 00:00:00 2001 From: Josh d'Entremont Date: Thu, 16 Mar 2023 16:19:49 -0300 Subject: [PATCH 6/9] added make production back after it was lost in merge --- Makefile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 953af11ba..00b12788e 100644 --- a/Makefile +++ b/Makefile @@ -189,6 +189,17 @@ starter_dev: generate-secrets $(MAKE) starter-finalize ENVIRONMENT=starter_dev +.PHONY: production +production: generate-secrets + $(MAKE) download-default-certs + $(MAKE) -B docker-compose.yml + $(MAKE) pull + docker-compose up -d --remove-orphans + docker-compose exec -T drupal with-contenv bash -lc 'composer install; chown -R nginx:nginx .' + $(MAKE) remove_standard_profile_references_from_config drupal-database update-settings-php + docker-compose exec -T drupal with-contenv bash -lc "drush si -y --existing-config minimal --account-pass $(shell cat secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD)" + + ############################################# ## Helper Rules for managing your install ## ############################################# @@ -652,4 +663,4 @@ fix_masonry: fix_views: docker cp scripts/patch_views.sh $$(docker ps --format "{{.Names}}" | grep drupal):/var/www/drupal/patch_views.sh docker-compose exec -T drupal with-contenv bash -lc "bash /var/www/drupal/patch_views.sh ; rm /var/www/drupal/patch_views.sh ; drush cr" - \ No newline at end of file + From e4a5b2096fb0b86ee00050b65874b6d91cda828f Mon Sep 17 00:00:00 2001 From: Josh D'entremont Date: Mon, 17 Apr 2023 16:32:18 -0300 Subject: [PATCH 7/9] updated to allow for custom image name and tag --- Makefile | 8 +++++--- build/docker-compose/docker-compose.custom.yml | 2 +- sample.env | 12 +++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 00b12788e..53ae25777 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,9 @@ production: generate-secrets $(MAKE) pull docker-compose up -d --remove-orphans docker-compose exec -T drupal with-contenv bash -lc 'composer install; chown -R nginx:nginx .' - $(MAKE) remove_standard_profile_references_from_config drupal-database update-settings-php + $(MAKE) remove_standard_profile_references_from_config drupal-database + docker-compose exec -T drupal with-contenv bash -lc "if [ ! -f /var/www/drupal/web/sites/default/settings.php ]; then cp /var/www/drupal/web/sites/default/default.settings.php /var/www/drupal/web/sites/default/settings.php; fi" + docker-compose exec -T drupal with-contenv bash -lc "for_all_sites update_settings_php" docker-compose exec -T drupal with-contenv bash -lc "drush si -y --existing-config minimal --account-pass $(shell cat secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD)" @@ -257,13 +259,13 @@ build: if [ ! -f $(PROJECT_DRUPAL_DOCKERFILE) ]; then \ cp "$(CURDIR)/sample.Dockerfile" $(PROJECT_DRUPAL_DOCKERFILE); \ fi - docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t $(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . + docker build -f $(PROJECT_DRUPAL_DOCKERFILE) -t $(CUSTOM_IMAGE_NAMESPACE)/$(CUSTOM_IMAGE_NAME):${CUSTOM_IMAGE_TAG} --build-arg REPOSITORY=$(REPOSITORY) --build-arg TAG=$(TAG) . .PHONY: push-image ## Push your custom drupal image to dockerhub or a container registry push-image: - docker push "$(CUSTOM_DRUPAL_NAMESPACE)/$(COMPOSE_PROJECT_NAME)_drupal" + docker push "$(CUSTOM_IMAGE_NAMESPACE)/$(CUSTOM_IMAGE_NAME):${CUSTOM_IMAGE_TAG}" .SILENT: docker-compose.yml diff --git a/build/docker-compose/docker-compose.custom.yml b/build/docker-compose/docker-compose.custom.yml index bd8bda050..8acc481e9 100644 --- a/build/docker-compose/docker-compose.custom.yml +++ b/build/docker-compose/docker-compose.custom.yml @@ -11,7 +11,7 @@ volumes: services: # The service name is drupal that is the default host name used by micro-services etc. drupal: - image: ${CUSTOM_DRUPAL_NAMESPACE}/${COMPOSE_PROJECT_NAME}_drupal:latest + image: ${CUSTOM_IMAGE_NAMESPACE}/${CUSTOM_IMAGE_NAME}:${CUSTOM_IMAGE_TAG} environment: # # Set environment variables that allow use to install from an existing configuration. diff --git a/sample.env b/sample.env index 1ba353c5f..48a77e22d 100644 --- a/sample.env +++ b/sample.env @@ -35,7 +35,17 @@ PROJECT_DRUPAL_DOCKERFILE=Dockerfile # Custom namespace for your created Drupal images (eg. your dockerhub username) # preface this with a URL to use a container registry like Github or Gitlab # Used in the image name when running `make build` and `make push-image` -CUSTOM_DRUPAL_NAMESPACE=mynamespace +CUSTOM_IMAGE_NAMESPACE=mynamespace + +# Image name of custom drupal image +# This is used when pulling a custom image for environments set to custom and +# when building a custom image with make build +CUSTOM_IMAGE_NAME=${COMPOSE_PROJECT_NAME}_drupal + +# Tag for custom image +# This is used when pulling a custom image for environments set to custom and +# when building a custom image with make build +CUSTOM_IMAGE_TAG=latest # Includes `traefik` as a service, if false assume we are sharing a traefik # from another project. From cae6dcbde37a7560d86bdbf189184f65c7ed7dff Mon Sep 17 00:00:00 2001 From: Josh D'entremont Date: Mon, 17 Apr 2023 17:00:39 -0300 Subject: [PATCH 8/9] updated readme with new .env variables --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9cd676315..004512e4d 100644 --- a/README.md +++ b/README.md @@ -165,17 +165,18 @@ Then you can `git push` your site to Github and `git clone` it down whenever you This environment is used to run your custom `drupal` image which can be produced outside of this repository, or from another isle-dc instance, such as a local -development environment as described above. You can specify a namespace and the -image name in your `.env` file. +development environment as described above. You can specify a namespace, the +image name, and tag in your `.env` file. This assumes you have already created an image and have it stored in a container registry like Dockerhub or Gitlab. If you are setting this up for the first time you should first create a local environment as described above. Once you have your local environment created you can do the following: - In your .env set the name of the image to create using -`COMPOSE_PROJECT_NAME` and the namespace using `CUSTOM_DRUPAL_NAMESPACE` +`CUSTOM_IMAGE_NAME`, the namespace using `CUSTOM_IMAGE_NAMESPACE`, and the tag +using `CUSTOM_IMAGE_TAG` - Run `make build` to create an image based on the codebase folder - - This will create an image named `namespace/projectname_drupal` + - This will create an image named `namespace/name:tag` - Run `make push-image` to push that image to your container registry For convenience a `sample.Dockerfile` is provided which `make build` will use to @@ -187,9 +188,9 @@ Once you have done that you can create your production or staging site by: - Modify your .env - Set ENVIRONMENT=custom - Set DOMAIN=yourdomain.com - - Set the namespace and the name of the image using - `CUSTOM_DRUPAL_NAMESPACE` and `COMPOSE_PROJECT_NAME` - - They should be the same values as on your local machine + - Set the namespace, the name of the image, and the tag using + `CUSTOM_IMAGE_NAMESPACE`, `CUSTOM_IMAGE_NAME`, and `CUSTOM_IMAGE_TAG` + - They should be the same values you used on your local machine when creating the image - Create your production site using `make production` - Export the database from your local machine and import it to your production site From 513eef77027b8fb96444e03dbb7c02a16876c497 Mon Sep 17 00:00:00 2001 From: Josh D'entremont Date: Wed, 26 Apr 2023 16:01:14 -0300 Subject: [PATCH 9/9] updated make production to run make hydrate --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 53ae25777..32f89a48c 100644 --- a/Makefile +++ b/Makefile @@ -196,10 +196,11 @@ production: generate-secrets $(MAKE) pull docker-compose up -d --remove-orphans docker-compose exec -T drupal with-contenv bash -lc 'composer install; chown -R nginx:nginx .' - $(MAKE) remove_standard_profile_references_from_config drupal-database - docker-compose exec -T drupal with-contenv bash -lc "if [ ! -f /var/www/drupal/web/sites/default/settings.php ]; then cp /var/www/drupal/web/sites/default/default.settings.php /var/www/drupal/web/sites/default/settings.php; fi" - docker-compose exec -T drupal with-contenv bash -lc "for_all_sites update_settings_php" - docker-compose exec -T drupal with-contenv bash -lc "drush si -y --existing-config minimal --account-pass $(shell cat secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD)" + docker-compose exec -T drupal with-contenv bash -lc "drush si -y --existing-config minimal --account-pass '$(shell cat secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD)'" + docker-compose exec -T drupal with-contenv bash -lc "drush -l $(SITE) user:role:add fedoraadmin admin" + MIGRATE_IMPORT_USER_OPTION=--userid=1 $(MAKE) hydrate + docker-compose exec -T drupal with-contenv bash -lc 'drush -l $(SITE) migrate:import --userid=1 islandora_fits_tags' + $(MAKE) login ############################################# @@ -531,7 +532,7 @@ update-settings-php: docker-compose exec -T drupal with-contenv bash -lc "if [ ! -f /var/www/drupal/web/sites/default/settings.php ]; then cp /var/www/drupal/web/sites/default/default.settings.php /var/www/drupal/web/sites/default/settings.php; fi" docker-compose exec -T drupal with-contenv bash -lc "for_all_sites update_settings_php" # Make sure the host user can read the settings.php files after they have been updated. - sudo find ./codebase -type f -name "settings.php" -exec chown $(shell id -u):101 {} \; + if [ -d ./codebase ]; then sudo find ./codebase -type f -name "settings.php" -exec chown $(shell id -u):101 {} \;; fi # Created by the standard profile, need to be deleted to import a site that was