- Understanding a sample application.
- Creating authentication credentials for Bitbucket.
- Creating a Bitbucket repository.
- Creating a continuous delivery pipeline to App Engine.
- Testing the pipeline.
This tutorial uses billable components of Google Cloud Platform (GCP), including:
- App Engine
App Engine has free quotas that might cover this tutorial in a live production environment. Use the Pricing Calculator to generate a cost estimate based on your projected usage for this tutorial.
Before you begin
Understanding the application
This tutorial demonstrates a Python app that runs on App Engine with Flask, a Python web framework, and interacts with the Google Books API. The sample app has a simple Python Flask endpoint that looks up the author of a book by its title.
Creating authorization credentials for Bitbucket
Create an App Engine service account and API key. Bitbucket needs this information to deploy to App Engine.
Creating an App Engine service account
In the Google Cloud Platform Console, go to the Credentials page.
Click Create credentials > Service account key.
In the Service account dropdown, select New service account.
In the Service account name field, input
In the Role dropdown, select the following roles:
- App Engine > App Engine Admin
- Storage > Storage Object Admin
Click the Create button. A copy of the JSON file downloads to your computer.
Creating an API Key
Click Create credentials > API key.
Copy the value that displays in the Your API key field. Use this value below when setting up environment variables.
Create an App Engine application
The pipeline script expects your project to have an App Engine application. To create an App Engine application:
In the Cloud Platform Console, go to Cloud Shell.
Run the following command to create your default App Engine application:
gcloud app create
Importing the tutorial repository in Bitbucket
Navigate to Bitbucket and log in.
Click Repositories in the left navigation.
Click the + button, then click Repository.
Click Import repository.
Select Git from the Source dropdown.
https://github.com/GoogleCloudPlatform/continuous-deployment-bitbucketinto the URL field.
Click the Import repository button.
Creating the pipeline to App Engine
To create the pipeline, follow the Atlassian instructions to enable Bitbucket Pipelines. Don't try to run a pipeline yet.
Next, you would typically configure the pipeline by editing the
bitbucket-pipelines.yml file. Because the repository you imported contains an
already-configured version of the
bitbucket-pipelines.yml file, you don't
need to complete any additional pipeline configuration steps for this tutorial.
Finally, configure the environment variables required by the pipeline script:
- In Bitbucket's left navigation menu, click Settings.
- In the Settings page's navigation menu, under the PIPELINES heading, click Environment variables.
Add the following three environment variables:
CLOUDSDK_CORE_PROJECTin the Type variable field. Input your Cloud Platform project ID in the Type value field. Click the Add button.
GOOGLE_API_KEYin the Type variable field. Input the value of the API key you created earlier in the Type value field. Click the Add button.
GOOGLE_CLIENT_SECRETin the Type variable field. Open the JSON file you downloaded in the Creating an App Engine service account section, and paste the file's contents into the Type value field. Click the Add button.
Testing the pipeline
Now that your pipeline is fully configured, test that the pipeline triggers as expected when changing the source code.
Click Source in the left navigation.
README.mdfile name, then click the Edit button to edit the file.
Change the text "This repo" to "This repository" on line 5.
Click the Commit button, then click the Commit button in the dialog.
Click Pipelines in the left navigation. You will see a pipeline entry associated with the latest commit.
Click the pipeline entry to see details about the pipeline status.
Wait until the pipeline status string changes to Successful. This indicates the application changes deployed successfully.
To manually verify that the application deployed, navigate to the following URL
in a web browser. Replace
[YOUR_PROJECT_ID] with your project ID.
The text "James Joyce" displays.
You can test the app further by replacing the word "ulysses" in the URL with a different book title.
To avoid incurring charges to your Google Cloud Platform account for the resources used in this tutorial:
Deleting the project
The easiest way to eliminate billing is to delete the project you created for the tutorial.
To delete the project:
- In the GCP Console, go to the Projects page.
- In the project list, select the project you want to delete and click Delete project.
- In the dialog, type the project ID, and then click Shut down to delete the project.