/apigee-kickstart-docker-gke

Apigee kickstart Docker project to deploy on GCP

Primary LanguagePHPApache License 2.0Apache-2.0

Apigee Kickstart docker image based on Google App Engine Flex PHP runtime

This is an open-source project. It is not covered by Apigee support contracts. For help, please open an issue in this GitHub project. You are also always welcome to submit a pull request.

This is a sample project to show you how to setup Apigee Developer Portal Kickstart on Google Kubernetes Engine

The reason we used the GCP PHP docker base image is to take advantage of the updates GCP team provides and also to use integrations with other GCP tools

Running this setup on GKE

  1. This repository is setup as a Template Repository to allow you to easily clone for multiple projects

  2. Clone this repository and set it up on Cloud Source Repositories for your GCP project

  3. Create a trigger using Cloud Build. Use the cloudbuild.yaml file provided with this project or make appropriate modifications for your project.

  4. You may choose to set this up on Docker Hub make sure to set the Dockerfile location to container-assets/Dockerfile and the Build Context to /

  5. Setup the Database

    • Create a Cloud SQL instance (MySQL)
    • Create a database with the name apigee_devportal
    • Create a User e.g. portal_dbuser and set a password
    • Make sure that to assign a private IP to this instance and removing public access
    • You can choose to run the following gcloud commands instead of configuring from the UI
     MYSQL_INSTANCE_NAME=apigee-devportal-instance
     COMPUTE_REGION=us-east1
     COMPUTE_ZONE=us-east1-c
     DRUPAL_DB_NAME=apigee_devportal
     DRUPAL_DB_USER=portal_dbuser
     DRUPAL_DB_PASS=portal_dbpassword
    
     gcloud beta sql instances create $MYSQL_INSTANCE_NAME \
         --tier=db-n1-standard-2 --region=$COMPUTE_REGION  --network=default --no-assign-ip
     
     gcloud sql databases create $DRUPAL_DB_NAME --instance=$MYSQL_INSTANCE_NAME
     
     gcloud sql users create $DRUPAL_DB_USER \
        --host=% --instance=$MYSQL_INSTANCE_NAME --password=$DRUPAL_DB_PASS
    
  6. Drupal needs a file system to store the uploaded content and the generated assets. To allow GKE to spin multiple replicas of the container we are going to setup a Filestore Instance.

    You may choose to use the following gcloud command

     gcloud filestore instances create apigee-devportal-files-instance \
        --zone=$COMPUTE_ZONE --file-share=capacity=1TB,name=portal_files --network=name=default
    
  7. Create a Kubernetes cluster or you may choose to deploy this application to an existing cluster

  8. Copy the kubernetes/dev.example.com and set one up for your project e.g. developer.acme.com

     cp -rf kubernetes/dev.example.com kubernetes/developer.acme.com
    
  9. Modify the kubernetes/developer.acme.com/kustomization.yaml file to add in the Database server details and credentials.

          - database-host=127.0.0.1
          - database-port=3306
          - database-name=devportal
    
         - dbusername=dbuser
         - dbpassword=dbp@ssw0rd
    

    Update the image URL to build from your project. Insert your GCP Project Name.

     newName: gcr.io/<GCP-PROJECT-NAME>/apigee-devportal
    
  10. Modify the kubernetes/developer.acme.com/filestore-patch.yaml to add in your filestore details Modify the path if you modified the above command. Add in the IP address of the Filestore instance

    server: <Filestore_ip>
    path: /portal_files
    
  11. Create the deployment using the following command

    kubectl apply -k kubernetes/developer.acme.com/
    
  12. Get the IP Address of the apigee-portal-ingress from the Services. Use that to start the drupal install process from the browser.

Running this setup locally

You will need docker-compose to run this setup locally. Installation instructions here

Please note Docker on Mac could be slow.

  1. To setup the local project run ./setup-project.sh

    • This will run "composer install" and setup the code directory and the drupal-files directory locally.
    • You may choose to check in your entire code directory to the repository. This will ensure that your container image is built with the version in source control.
    • code/sites/default/files and drupal-files directory should not be added to source control. Since these are typically files that user uploads. You can choose to copy them over to your local files to Filestore instance after finishing development
    • code/sites/default/files content should be copied over the the filestore_instance/public
    • drupal-files/private content should be copied over to filestore_instance/private
    • drupal-files/config content should be copied over to filestore_instance/config
  2. To start the project run docker-compose up. Once the services are up you can navigate to http://localhost:5000

  3. You can run through the install from the browser.

  4. To stop the project run docker-compose down.

  5. To delete the database you can delete the volume that is created or run docker-compose down -v. This will let you run through a fresh install. You may need to delete the files in drupal-files/private , drupal-files/private, code/web/sites/default/files directory

  6. To update the dependencies you can run ./update-project.sh and then commit all the updates in the code directory to source control.

  7. To ssh into the Drupal container use

        docker-compose exec apigee-kickstart /bin/bash
    
    • You can run drush commands or composer install commands from the /app/code directory
    • code and the drupal-files directories are mounted to /app/code or /app/drupal-files directories on the container. So any changes you make will be automatically reflected in that directory.
  8. To get access to the database you can run

    docker-compose exec apigee-kickstart drush sqlc
    

Remove your local docker containers, images, volumes

docker-compose down -v