Introduction
Private Git storage is known as Cloud Source Repositories and is hosted on Google Cloud. These repositories enable the creation and deployment of apps. Also, provide services in an environment that supports code collaboration and version control.
This article will discuss the Overview of Cloud Source Repositories. It includes creating a code repository in the Cloud Source Repositories, App Engine Deployment, and many more.
Creating a code repository in Cloud Source Repositories
In the series of "Overview of Cloud Source Repositories," our first topic is to create a code repository in the Cloud Source Repositories.
Before you start
-
Create an account if you are totally new to Google Cloud.
-
Go to the Project Selector page and click on Create a Google Cloud Project.
-
Ensure if the billing is enabled in your project or not.
-
Install and initialize Google Cloud CLI.
-
Verify if you are using the latest version.
- Enable the Cloud Source Repositories.
Create a Repository
Create a Google Cloud repository called hello-world in a terminal window using the gcloud source repos create command:
gcloud source repos create hello-world
Clone a Repository
The Google Cloud repository's contents can be cloned into a local Git repository using the gcloud source repos clone command:
gcloud source repos clone hello-world
Create a "Hello, World!" script
In a browser window, print Hello, World! using a Python script.
Step 1: Go to the hello-world repository.
Step 2: Create a file named main.py using a text editor, then paste the following code:
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
Create an app.yaml file
Build an app.yaml file with the configuration details needed to deploy your code to App Engine.
Step 1: Go to the hello-world repository.
Step 2: Create a file called app.yaml in a text editor, and then paste the following configuration details into it:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
Push to Cloud Source Repositories
Upload your recently created files to cloud source repositories.
Step 1: Go to your hello-world directory in a terminal window.
cd hello-world
Step 2: Add the files
git add .
Step 3: Files should be added to the repository along with a comment outlining the history of this action:
git commit -m "Add Hello World app to Cloud Source Repositories"
Step 4: Add the local Git repository's contents to cloud source repositories by using the git push command:
git push origin master
Step 5: The files from the master branch are pushed by Git to the remote origin. The output looks like this:
Counting objects: 21, done.
Delta compression using up to 6 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (21/21), 9.76 KiB | 0 bytes/s, done.
Total 21 (delta 5), reused 0 (delta 0)
remote: Storing objects: 100% (21/21), done.
remote: Processing commits: 100% (6/6), done.
To https://source.developers.google.com/p/example-project-1244/r/repo-name
* [new branch] master -> master
View files in the repository
-
Open Cloud Source Repositories in the Google Cloud console.
-
Select the repository you created called hello-world by clicking its name.
-
Go to the files you uploaded to the repository.
The master branch files as the most recent commit are displayed in the GCP Console.
-
Click a file to view its contents in the Files list.
Using Cloud Shell, you can view the files also.
Clean up
You can also delete all these after finishing by following the below steps:
-
Open the All repositories page for Cloud Source Repositories in the GCP Console.
-
Hold the cursor over the repository you want to remove/delete and click Settings.
The General setting will open after this step.
-
Click on Delete this repository.
After this step, the Remove repository will open.
-
Type the repository name that you want to delete.
- Click on Delete.