Skip to content

Commit 0622582

Browse files
committed
Update template structure to enable grouping functions into separate microservices
1 parent 30e8681 commit 0622582

File tree

8 files changed

+126
-42
lines changed

8 files changed

+126
-42
lines changed

.gitignore

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,71 @@
1-
# Binaries for programs and plugins
2-
*.exe
3-
*.exe~
4-
*.dll
5-
*.so
6-
*.dylib
7-
8-
# Test binary, built with `go test -c`
9-
*.test
10-
11-
# Output of the go coverage tool, specifically when used with LiteIDE
12-
*.out
13-
14-
# Dependency directories (remove the comment below to include it)
15-
# vendor/
16-
17-
# Other
18-
.DS_Store
19-
node_modules
20-
.serverless
1+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
2+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3+
4+
# User-specific stuff
5+
.idea/**/workspace.xml
6+
.idea/**/tasks.xml
7+
.idea/**/usage.statistics.xml
8+
.idea/**/dictionaries
9+
.idea/**/shelf
10+
11+
# Generated files
12+
.idea/**/contentModel.xml
13+
14+
# Sensitive or high-churn files
15+
.idea/**/dataSources/
16+
.idea/**/dataSources.ids
17+
.idea/**/dataSources.local.xml
18+
.idea/**/sqlDataSources.xml
19+
.idea/**/dynamic.xml
20+
.idea/**/uiDesigner.xml
21+
.idea/**/dbnavigator.xml
22+
23+
# Gradle
24+
.idea/**/gradle.xml
25+
.idea/**/libraries
26+
27+
# Gradle and Maven with auto-import
28+
# When using Gradle or Maven with auto-import, you should exclude module files,
29+
# since they will be recreated, and may cause churn. Uncomment if using
30+
# auto-import.
31+
# .idea/artifacts
32+
# .idea/compiler.xml
33+
# .idea/jarRepositories.xml
34+
# .idea/modules.xml
35+
# .idea/*.iml
36+
# .idea/modules
37+
# *.iml
38+
# *.ipr
39+
40+
# CMake
41+
cmake-build-*/
42+
43+
# Mongo Explorer plugin
44+
.idea/**/mongoSettings.xml
45+
46+
# File-based project format
47+
*.iws
48+
49+
# IntelliJ
50+
out/
51+
52+
# mpeltonen/sbt-idea plugin
53+
.idea_modules/
54+
55+
# JIRA plugin
56+
atlassian-ide-plugin.xml
57+
58+
# Cursive Clojure plugin
59+
.idea/replstate.xml
60+
61+
# Crashlytics plugin (for Android Studio and IntelliJ)
62+
com_crashlytics_export_strings.xml
63+
crashlytics.properties
64+
crashlytics-build.properties
65+
fabric.properties
66+
67+
# Editor-based Rest Client
68+
.idea/httpRequests
69+
70+
# Android studio 3.1+ serialized cache file
71+
.idea/caches/build_file_checksums.ser

README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,59 @@ This template project is designed to be used as a starting point for a Google Cl
44

55
## Requirements
66

7-
- Install [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/)
8-
- Setup you serverless environment to work with GCP by working you way through the Serverless Framework [GCP guides](https://www.serverless.com/framework/docs/providers/google/guide/intro/)
7+
- You have the [Serverless Framework](https://www.serverless.com/framework/docs/getting-started/) installed.
8+
- You have a project already created and configured in Google Cloud. You can follow [this guide](https://www.serverless.com/framework/docs/providers/google/guide/credentials/) to make sure its setup to work with Severless.
9+
- You've setup your overall environment to work with GCP and the Serverless Framework. You should follow [these guides](https://www.serverless.com/framework/docs/providers/google/guide/intro/) if not.
910

10-
## Usage
11+
## Project structure
1112

12-
Create a new service for each logical microservice you intend to deploy.
13+
The root directory contains a folder for each of your microservices (i.e. Go package).
1314

14-
Each microservice could be made up of a single or several cloud functions.
15+
The `go.mod` file also resides in the root directory.
1516

16-
### Create a new service
17+
## Start a new project from the template
1718

18-
Use the `serverless create` command to download the template into a new project folder:
19+
1. Clone the template repo into a new local project folder:
1920

2021
<pre>
21-
serverless create --template-url https://github.com/cgossain/serverless-google-cloud-functions-golang-template.git --path <b>mynewservice</b>
22+
git clone https://github.com/cgossain/serverless-google-cloud-functions-golang-template.git <b>my-gcp-project-name</b>
2223
</pre>
2324

24-
### Configure the template
25-
26-
1. Navigate to the template directory and install the Google Cloud Functions Provider Plugin:
25+
2. Update `go.mod` in the root directory with your project name. For example:
2726

2827
<pre>
29-
cd <b>mynewservice</b> && serverless plugin install --name serverless-google-cloudfunctions
28+
module github.com/<b>my-gcp-project-name</b>
29+
30+
go 1.13
3031
</pre>
3132

32-
2. Update `go.mod` with your module name. For example:
33+
## Create a new micoservice/package
34+
35+
Create a directory (i.e. package) for each logical microservice you intend to deploy. Each microservice could be made up of a single or several cloud functions.
36+
37+
### TL;DR:
38+
39+
1. From the root directory, make a copy of the `templateservice` directory and rename it to match your microservice/package name:
3340

3441
<pre>
35-
module github.com/<b>my-gcp-project-name</b>/<b>mynewservice</b>
42+
cp -R templateservice <b>mynewservice</b>
43+
</pre>
3644

37-
go 1.13
45+
2. Navigate to the new directory and install the Google Cloud Functions Provider Plugin:
46+
47+
<pre>
48+
cd <b>mynewservice</b> && serverless plugin install --name serverless-google-cloudfunctions
3849
</pre>
3950

40-
3. Change the root package name in both `fn.go` adn `fn_test.go` to match you service name:
51+
3. Update the package name in both `fn.go` and `fn_test.go` to match your microservice/package name:
4152

4253
<pre>
4354
package <b>mynewservice</b>
4455

4556
...
4657
</pre>
4758

48-
4. Open `serverless.yml` and update the configuration (i.e. service name, provider details, etc.):
59+
4. Open `serverless.yml` and update the configuration (i.e. service name, GCP project name, GCP credentials keyfile, etc.):
4960

5061
<pre>
5162
service: <b>mynewservice</b>
@@ -54,7 +65,7 @@ provider:
5465
name: google
5566
runtime: go113
5667
project: <b>my-gcp-project-name</b>
57-
credentials: ~/.gcloud/keyfile.json # https://www.serverless.com/framework/docs/providers/google/guide/credentials/
68+
credentials: <b>~/.gcloud/keyfile.json</b> # https://www.serverless.com/framework/docs/providers/google/guide/credentials/
5869

5970
plugins:
6071
- serverless-google-cloudfunctions
@@ -73,19 +84,21 @@ functions:
7384
...
7485
</pre>
7586

76-
5. Take a look at [this guide](https://cloud.google.com/functions/docs/writing#structuring_source_code) for ideas on how to structure your source code for different scenarios:
87+
### Additional info
88+
89+
Take a look at [this guide](https://cloud.google.com/functions/docs/writing#structuring_source_code) for ideas on how to structure your source code for different scenarios:
7790

7891
## Deploy
7992

80-
Run the following command from your service directory to build and deploy all functions:
93+
Run the following command from within your microservice/package directory to build and deploy all functions:
8194

8295
<pre>
8396
cd <b>mynewservice</b> && serverless deploy
8497
</pre>
8598

8699
## Remove Deployment
87100

88-
Run the following command from your service directory to remove the deployment of all functions:
101+
Run the following command from within your microservice/package directory to remove the deployment of all functions:
89102

90103
<pre>
91104
cd <b>mynewservice</b> && serverless remove

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/project-m45/gcp-golang/myNewService
1+
module github.com/my-gcp-project-name
22

33
go 1.13
File renamed without changes.

templateservice/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# Other
18+
.DS_Store
19+
node_modules
20+
.serverless
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)