Skip to content

Commit

Permalink
Merge d51b463 into 6d2cff5
Browse files Browse the repository at this point in the history
  • Loading branch information
bao1018 committed Mar 31, 2020
2 parents 6d2cff5 + d51b463 commit 4eeb647
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 22 deletions.
68 changes: 68 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Cloud function Migration Reference from v1beta to v1

## Background

> Google Cloud Functions v1beta2 API version will be shut down on April 15, 2020
When you are using serverless to deploy google cloud functions with latest serverless google plugin (support google api v1),
It may face a error like

```shell
Deployment failed: TYPE_MISMATCH
Resource types cannot be changed, previous (cloudfunctions.v1beta2.function) -> updated (gcp-types/cloudfunctions-v1:projects.locations.functions)
```

Which means the former ones deployed used v1beta2 api version and now use v1 in the v2.4.2 of serverless-google-cloudfunctions, thus it failed to deploy.
First please be careful that

## Solutions

If you choose to upgrade to v1 function , and make sure the **package.json** using the latest plugin in nodejs project

```
"devDependencies": {
"serverless-google-cloudfunctions": "*"
},
```

There are at least two options to upgrade the exisingt cloud function that deploy via google api v1beta.

### Option 1

The first is from the devops point of view ,you don't need to change the code at all.

you need to open the [deployment manager](https://cloud.google.com/deployment-manager) in GCP.

- Delete all the functions

you have to delete all the functions and related bucket first ,and then delete the all the related resources from deployment manager

- Delete all the related buckets with cloud functions

By default, each time you you use `serverless deploy` , it would create a bucket for you to store the zip package for the function.

pls delete this bucket first.

- Delete all the function resources in deployment manager

- Redeploy the functions

### Option 2

The second is from the developers' point of view , which means you need to make some changes to the `serverless.yml`.

- Change the service name or change the function name to make sure this function is different from the older one.

- redeploy the functions.

- Once it's done,you may consider delete the old ones.

### Notices

Both the methods have some pros and cons, but it would work at least .

1. If your functions are called by bucket or pubsub, the modification of the function name may not impact your business.

2. If your functions are called by http, the function name would be changed, which means the http url that need to be called may also be changed

3. If you use cloud function to store some important data, pls export these data first and then import them to a new bucket.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ You can spin up a Docker container which mounts this code with the following com
```bash
docker-compose run node bash
```

## Migration

> Google Cloud Functions v1beta2 API version will be shut down on April 15, 2020
You can follow this [document](./MIGRATION_GUIDE.md) to upgrade your v1beta based cloud function( serverless-google-cloudfunctions v2.4.1) to v1
7 changes: 2 additions & 5 deletions package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
const artifactFilePath = this.serverless.service.package.artifact;
const fileName = artifactFilePath.split(path.sep).pop();
const projectName = _.get(this, 'serverless.service.provider.project');

this.serverless.service.provider.region =
this.serverless.service.provider.region || 'us-central1';
this.serverless.service.package.artifactFilePath = `${this.serverless.service.package.artifactDirectoryName}/${fileName}`;

this.serverless.service.getAllFunctions().forEach(functionName => {
Expand All @@ -35,10 +36,6 @@ module.exports = {
_.get(funcObject, 'memorySize') ||
_.get(this, 'serverless.service.provider.memorySize') ||
256;
funcTemplate.properties.location =
_.get(funcObject, 'location') ||
_.get(this, 'serverless.service.provider.region') ||
'us-central1';
funcTemplate.properties.runtime =
_.get(funcObject, 'runtime') ||
_.get(this, 'serverless.service.provider.runtime') ||
Expand Down
17 changes: 0 additions & 17 deletions package/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 1024,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -152,7 +151,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 1024,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -190,7 +188,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '120s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -228,7 +225,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '120s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -268,7 +264,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -310,7 +305,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -356,7 +350,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -402,7 +395,6 @@ describe('CompileFunctions', () => {
TEST_VAR: 'test',
},
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -445,7 +437,6 @@ describe('CompileFunctions', () => {
TEST_VAR: 'test',
},
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -485,7 +476,6 @@ describe('CompileFunctions', () => {
name: 'my-service-dev-func1',
properties: {
parent: 'projects/myProject/locations/us-central1',
location: 'us-central1',
runtime: 'nodejs8',
function: 'my-service-dev-func1',
entryPoint: 'func1',
Expand Down Expand Up @@ -536,7 +526,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
Expand Down Expand Up @@ -592,7 +581,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func1',
availableMemoryMb: 256,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
Expand All @@ -612,7 +600,6 @@ describe('CompileFunctions', () => {
entryPoint: 'func2',
availableMemoryMb: 256,
timeout: '60s',
location: 'us-central1',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
Expand Down Expand Up @@ -648,7 +635,6 @@ describe('CompileFunctions', () => {
name: 'my-service-dev-func1',
properties: {
parent: 'projects/myProject/locations/us-central1',
location: 'us-central1',
runtime: 'nodejs8',
function: 'my-service-dev-func1',
entryPoint: 'func1',
Expand Down Expand Up @@ -690,7 +676,6 @@ describe('CompileFunctions', () => {
name: 'my-service-dev-func1',
properties: {
parent: 'projects/myProject/locations/us-central1',
location: 'us-central1',
runtime: 'nodejs8',
function: 'my-service-dev-func1',
entryPoint: 'func1',
Expand Down Expand Up @@ -740,7 +725,6 @@ describe('CompileFunctions', () => {
name: 'my-service-dev-func1',
properties: {
parent: 'projects/myProject/locations/us-central1',
location: 'us-central1',
runtime: 'nodejs8',
function: 'my-service-dev-func1',
entryPoint: 'func1',
Expand All @@ -759,7 +743,6 @@ describe('CompileFunctions', () => {
name: 'my-service-dev-func2',
properties: {
parent: 'projects/myProject/locations/us-central1',
location: 'us-central1',
runtime: 'nodejs8',
function: 'my-service-dev-func2',
entryPoint: 'func2',
Expand Down

0 comments on commit 4eeb647

Please sign in to comment.