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

Makefile additions for building and pushing custom images #327

Merged
Merged
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ 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 .'
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


#############################################
## Helper Rules for managing your install ##
#############################################
Expand Down Expand Up @@ -248,7 +262,13 @@ 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_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_IMAGE_NAMESPACE)/$(CUSTOM_IMAGE_NAME):${CUSTOM_IMAGE_TAG}"


.SILENT: docker-compose.yml
Expand Down Expand Up @@ -515,7 +535,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
Expand Down Expand Up @@ -649,6 +669,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"




61 changes: 30 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,37 +164,36 @@ 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, 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
`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/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
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, 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

## 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.
Expand Down
4 changes: 1 addition & 3 deletions build/docker-compose/docker-compose.custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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_IMAGE_NAMESPACE}/${CUSTOM_IMAGE_NAME}:${CUSTOM_IMAGE_TAG}
environment:
#
# Set environment variables that allow use to install from an existing configuration.
Expand Down
15 changes: 15 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ 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)
# 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_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

# Packagist repo to use when creating a site with make starter
# Change this if you want to build from a different codebase than the starter site
CODEBASE_PACKAGE=islandora/islandora-starter-site:dev-main
Expand Down