Git Product home page Git Product logo

drupal-github-aws-ci-cd-testing's Introduction

drupal-github-aws-ci-cd-testing

This repository contains a new Landoified vanilla Drupal 10 site that will be deployed to and AWS EC2 instance using GitHub Actions and AWS CodeDeploy for CI/CD.

Prerequisites:

AWS roles and permissions setup for CodeDeploy, Cloudformation, and GitHub Actions

  1. Cloudformation roles and permissions
  2. CodeDeploy and GitHub Actions roles and permissions
    aws cloudformation create-stack \
       --stack-name "codedeploy-stack" \
       --disable-rollback \
       --region us-gov-west-1 \
       --capabilities CAPABILITY_NAMED_IAM \
       --template-body file://.aws/cloudformation-templates/codedeploy/codedeploy_setup_CF.yaml \
       --parameters file://.aws/cloudformation-templates/codedeploy/parameters.json

Github Repository setup

  1. Using environments for deployment
  2. Github Actions
  3. Configuring OpenID Connect in Amazon Web Services

SonarQube Setup

  1. Deploying SonarQube
    1. Deploy on AWS using cloudformation
      aws cloudformation create-stack \
         --stack-name "sonarqube-stack" \
         --disable-rollback \
         --region us-gov-west-1 \
         --capabilities CAPABILITY_NAMED_IAM \
         --template-body file://.aws/cloudformation-templates/sonarqube/sonarqube_single_instance_CF_stack.yml \
         --parameters file://.aws/cloudformation-templates/sonarqube/parameters.json
    2. Deploy Locally with Docker Compose
      cd .aws/cloudformation-templates/sonarqube
      docker compose up -d
  2. Once your instance is up and running, Log in to SonarQube using System Administrator credentials. Set a new admin password when prompted.
    • If you deployed to AWS use the EC2 Public IPv4 address to login.
    • If you deployed locally use http://localhost to login.
    • Default System Administrator credentials:
      • login: admin
      • password: admin

    [!IMPORTANT] Be sure to save your new admin password somewhere safe!

  3. Complete GitHub Integration following SonarQubes documentation.

    [!IMPORTANT] Be sure to save the GitHub Client secret and Private key somewhere safe

  4. To allow users to log in to SonarQube with GitHub credentials follow SonarQube's Connecting your GitHub App to SonarQube documentation.
  5. You should now be ready to start analyzing projects.

Analyzing projects with GitHub Actions:

  1. For basic setup and configuration see Analyzing projects with GitHub Actions

Deploying the Drupal 10 site

  1. Deploy Drupal 10 site
    1. Deploy on AWS using cloudformation
      aws cloudformation create-stack \
         --stack-name "drupal-github-aws-ci-cd-testing-dev" \
         --disable-rollback \
         --region us-gov-west-1 \
         --capabilities CAPABILITY_NAMED_IAM \
         --template-body file://.aws/cloudformation-templates/drupal/drupal10_single_instance_CF_stack.yml \
         --parameters file://.aws/cloudformation-templates/drupal/parameters.json
    2. Deploy Locally with Docker Compose
      cd .aws/cloudformation-templates/sonarqube
      docker compose up -d

Deploy locally with a specific environment

  1. Install lando
  2. Start the drupal stack for a specific environment
    • OPTION 1 Simple Startup

      # run the start.sh script with the environment (local, dev, stage, prod) as an argument
      ./start.sh dev
    • OPTION 2: Manual Startup Steps

      Click to Expand
      1. Run composer install

        lando composer install
      2. Create settings.php from default.settings.php and add the following at the bottom.

        cp web/sites/default/default.settings.php web/sites/default/settings.php
        $databases['default']['default'] = array (
          'database' => 'drupal10',
          'username' => 'drupal10',
          'password' => 'drupal10',
          'prefix' => '',
          'host' => 'database',
          'port' => '',
          'isolation_level' => 'READ COMMITTED',
          'namespace' => 'Drupal\\mysql\\Driver\\Database\\mysql',
          'driver' => 'mysql',
          'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
        );
        
        $settings['config_sync_directory'] = '../config/sync/default';
        
        $split_filename_prefix = 'config_split.config_split';
        
        /** Set environment splits. */
        $split_envs = [ 'local', 'dev', 'stage', 'prod' ];
        
        // Disable all split by default.
        foreach ($split_envs as $split_env) {
          $config['$split_filename_prefix.$split_env']['status'] = FALSE;
        }
        
        # manually set environment
        #putenv('ENVIRONMENT=local');
        
        $split = getenv('ENVIRONMENT');
        
        // Enable the environment split only if it exists.
        if ($split != FALSE) {
          $config['$split_filename_prefix.$split']['status'] = TRUE;
        } else {
          $split = 'local';
          $config['$split_filename_prefix.$split']['status'] = TRUE;
        }
        
      3. Set the environment you want to use in defaults.env

        echo "ENVIRONMENT=local" > ./defaults.env
      4. Start it up and make sure the environment you want is correct

        lando start
        
        # check env variable is set correctly in the appserver
        lando ssh -s appserver -c env | grep ENVIRONMENT
      5. Set hash_salt in settings.php

        # generate a random base64 encoded string for hash_salt value
        HASH_SALT=$(lando drush eval "print_r(Drupal\Component\Utility\Crypt::randomBytesBase64(55))")
        
        # print the generated hash_salt
        echo "Hash Salt: $HASH_SALT"
        
        # set hash_salt in settings.php
        sed -i "s/^\$settings\['hash_salt'\].*$/\$settings\['hash_salt'\] = '$HASH_SALT';/" web/sites/default/settings.php
        
        # check settings.php has the generated hash_salt value
        grep hash_salt web/sites/default/settings.php
      6. Install the site using existing configs

        # Install drupal using existing configs
        lando drush site:install -y \
          --account-name=admin \
          --account-pass=admin \
          --existing-config
        
        # Update database, import configs, and clear cache
        lando deploy

Creating or Modifying Drupal site config spits for an environment

Create a new config split environment

  1. Navigate to http://drupal-github-aws-ci-cd-testing_2.lndo.site/admin/config/development/configuration/config-split/add
  2. In the user interface enter values for the following fields
    • Label: some_new_environment
    • Folder: ../config/sync/some_new_environment
    • Weight: 1
    • Select the Modules or Items you want to be different from the default configuration
    • click save
  3. See the Modify config for an environment section to enable the config split and make any additional changes needed.

Modify config split for an environment

  1. Make sure you have the environment you want to modify set
    # check env variable is set correctly in the appserver
    lando ssh -s appserver -c env | grep ENVIRONMENT
    
    # change the environment if needed and rebuild
    echo "ENVIRONMENT=local" > ./defaults.env
    
    lando rebuild
  2. Make the configuration changes you need to make
  3. Export the configuration changes
    lando cex
  4. commit the changes and push

drupal-github-aws-ci-cd-testing's People

Contributors

jbirkhimer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.