Drupal 8 CI/CD with Docker via Jenkins. Part 2: Delivery

Chingis
Wodby blog
Published in
4 min readOct 12, 2016

--

THIS ARTICLE IS OUTDATED: please see new article “New deployment method — CI/CD via third-party CI”

This is the second part of the two-parts article. You can find the first part here.

There’s no universal rule how you should deliver your build. It depends on your workflow and infrastructure. Also, with docker there 2 major options:

  1. Deliver your code (deployment tarball)
  2. Deliver docker containers with code

In this article we will cover the first option where you deliver your code to the infrastructure prepared by Wodby. We will prepare the deployment tarball and upload it to AWS S3. Then we deploy a new docker-based environment for Drupal via Wodby and deliver there our tarball.

AWS S3 Bucket

We will use AWS Simple Safe Storage (S3) to store deployment tarballs. We’ve installed AWS CLI in the first part of the article.

Open your AWS S3 console and create a new bucket:

Switch to AWS IAM service and create a new user for Jenkins. Copy generated credentials for the newly created user (Access Key Id and Secret Access Key), we will need them later.

Add AWS S3 permissions for this user by attaching the AmazonS3FullAccess policy:

Attach AmazonS3FullAccess policy to allow the user uploading to S3 bucket

Delivering Build via Wodby

Deploy your Drupal website with Wodby. By default dev instance will be created. We will create a copy of this instance from Jenkins and import there our deployment tarball via Wodby PHP SDK. The bundle (a set of containers) provided by Wodby is 95% consistent with docker4drupal containers.

Deploy your app via Wodby. We will deploy new instances of this app from Jenkins

Delivery Scripts

Copy the following scripts from this repository (under jenkins) to your Drupal project. It contains the following files:

  • deploy-new-instance.php, this script will deploy a new instance of the application deployed via Wodby and import the build
  • composer.json, here we define Wodby PHP SDK dependency for our PHP script
  • deploy.sh, this script will create a deployment tarball (archive with our code), upload it to AWS S3 bucket and trigger our PHP script

Configure Environment Variables

Open your project configuration page. We need to define the following environment variables and tokens for our delivery scripts:

  • AWS_S3_BUCKET. The name of your AWS S3 bucket where we will upload deployment tarballs
  • AWS_S3_FILE_NAME. The base name of the tarball file, the build number will be added as a suffix
  • WODBY_API_TOKEN. You can copy the token from your Wodby profile page
  • WODBY_SERVER_ID. Navigate to the server page of Wodby dashboard, copy ID from the URL
Choose a server where you want to deploy your new instance
Copy the ID of the server
  • WODBY_APP_ID. Navigate to the application page of Wodby dashboard, copy Application UUID from the Settings > Info tab
  • WODBY_SOURCE_INSTANCE_ID. From the same tab copy Instance UUID. This instance will be used as a source of database and files for the new instance
Copy Application and Instance IDs
  • AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY. The credentials you acquired via AWS IAM

Build Setup

Now we need to add the following build step that will trigger our delivery script:

./scripts/deploy.sh

That’s it! Now with every build Jenkins will create a deployment tarball, upload it to AWS S3, spin up a new application instance on your server via Wodby and import your tarball.

Now we have a newly created instance with the information about our build:

Drupal instance deployed via Wodby with delivered build

That’s it! You can find all the files in this repository under the jenkins directory.

--

--