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

Conversation

joshdentremont
Copy link
Contributor

@joshdentremont joshdentremont commented Feb 24, 2023

Added new variables to give more flexibility with image name and tag, so there are new instructions in the comments below

Previously when running make build it would create a custom Drupal image with the name "projectname_drupal". This PR adds a variable to sample.env to allow setting a URL and namespace to create an image that's ready to push to dockerhub, gitlab, etc.

This also adds another make command called make push-image to then push that new image to dockerhub, gitlab, etc. using the same URL & namespace.

To test, change CUSTOM_DRUPAL_NAMESPACE in .env to be your dockerhub username, or your gitlab registry URL & namespace and run make build, then make push-image.

eg.
CUSTOM_DRUPAL_NAMESPACE=dockerhub_username
CUSTOM_DRUPAL_NAMESPACE=gitlab_registry_url.com/namespace

Leaving the namespace as the default shouldn't cause any issues, but will name the image mynamespace/projectname_drupal andmake push-image will not work with the default namespace because it just tries to push to a dockerhub namespace the user doesn't have access to.

@joshdentremont
Copy link
Contributor Author

joshdentremont commented Mar 10, 2023

Added another make command for creating a production site. This allows us to create a new Drupal site based on the Drupal root folder in the image instead of the codebase folder.

## Testing this PR

  • Create an initial local install using make starter
    • Set CUSTOM_DRUPAL_NAMESPACE to your Dockerhub username or your registry URL and namespace if you use something else (like Gitlab or GitHub)
    • Optionally change the COMPOSE_PROJECT_NAME variable if you don't want your image to be called isle-dc_drupal
  • Create an image based off that install using make build
  • Push that image to your container registry using make push-image
  • Dump your database to be imported on your production site later

After that you can create your production site:

  • Edit your .env
    • Use the same namespace and project name as above
    • Set ENVIRONMENT to custom and DOMAIN to your production domain
  • Run make production to create the Drupal site based on the Drupal root folder inside the image and spin up the containers for the other services
  • Import your database dump into your production site

@joshdentremont
Copy link
Contributor Author

This PR adds the ability to create a custom Drupal image, push that image to a container registry, then pull that image in a production environment without having to make local or make starter first.

It adds the following make commands:

  • make push-image
  • make production

And the following environment variables:

  • CUSTOM_IMAGE_NAMESPACE
  • CUSTOM_IMAGE_NAME
  • CUSTOM_IMAGE_TAG

To test this we can create a local install to build and push our image by doing the following:

  1. Run make starter
  2. Create a repository on Dockerhub (or gitlab, github, etc.) to store your image
  3. Update the three new environment variables in .env to point to your container registry
    a. The namespace would be your dockerhub username
    b. The image name would be whatever you named your Dockerhub repo
    c. The tag can be whatever you like (eg. latest or 1.0)
  4. Run make build to create the image
  5. Run make push-image to push the image to your container repository
    a. Make sure you are logged into Dockerhub

Once you have created your image, you can also test make production by doing the following:

  1. Run make clean to get back to a fresh state
  2. Set your environment variables in your .env to the same three things as above so they point to the repo you just pushed your image to
    a. The namespace would be your dockerhub username
    b. The image name would be whatever you named your Dockerhub repo
    c. The tag can be whatever you like (eg. latest or 1.0)
  3. In your .env, set ENVIRONMENT=custom
  4. Run make production

This will give you a fresh install using your custom image as the Drupal container, without the need for a local codebase folder

@aOelschlager aOelschlager self-requested a review April 19, 2023 17:45
@joshdentremont
Copy link
Contributor Author

Forgot to mention that those environment variables are also now used in make build so it makes the image with the specified namespace, name, and tag.

I also changed docker-compose.custom.yml to use the image instead of building in place. The idea is that you won't have a codebase folder on your production machine, and instead will build that image elsewhere and just pull it in production.

Copy link
Contributor

@aOelschlager aOelschlager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both make push-image and make production work without errors. When viewing the site created from make production it is missing the taxonomy terms normally gotten from make run-islandora-migrations. It's also missing the Fits migration tag as well. Would you be able to put these in the make production function?

@joshdentremont
Copy link
Contributor Author

@aOelschlager I've updated it to be more in line with make starter and run make hydrate. I had to update update-settings-php to only try to change the ownership of settings.php if there is a local codebase folder.

Copy link
Contributor

@aOelschlager aOelschlager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pulled in the new changes and everything works now on production like it does for make starter. Thank you Josh!

@aOelschlager aOelschlager merged commit f1f294b into Islandora-Devops:development May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants