Brief introduction: Code is updated in other scenarios, we need to be aware of the current, this is actually very important, and the code is safe to release the secret. This can be done with Serverless Devs.

The author | Anycodes

Since I started working on Serverless tools, I have often been asked the question of how to ensure the consistency of Serverless business deployment updates.

The so-called consistency here refers to: if we deploy the project locally through tools, and then someone updates the project through other channels (such as console, etc.), will it be directly overwritten if I deploy the project locally again?

For example, when user A updates services locally, an online exception “X” occurs due to some special circumstances. At this time, user B updates again and fixes the content. However, user B fails to synchronize the information to user A in time, and user A updates new functions, directly covering the content of user B. At this time, the previous exception “X” appears again. If at this time, the online resources can be perceived to have changed when A is updated, then this kind of thing will not happen again.

At present, Alicloud function computing component based on Serverless Devs has supported the awareness of online “abnormal movement”, including the following cases:

  • Create and deploy a resource that does not exist online
  • After the local deployment is complete, update online and deploy again locally
  • Create and deploy an existing online resource locally

The experiment to prepare

Create a Function with s init (select Aibaba Cloud Serverless, select HTTP function-python3 Example) :

At this point let’s look at S.yAML:

After the project is deployed online, it will create an FC-deploy-service service and http-trigger-function in cn-Hangzhou district.

The experimental process

Create and deploy a resource that does not exist online

At this point, we make sure that there are no corresponding resources on the line, so we deploy:

The deployment is complete and goes smoothly:

Open the browser and view the custom address feedback to us:

At this point, we can update this function locally:

Save the deployment:

Once you’re done, check out the online resources:

The whole process is still close to the traditional basic process, and there is no abnormal movement on the line, so it is an ideal process in the normal manner.

After the local deployment is complete, update online and deploy again locally

At this point, we make changes to the online resource, first find the function in the console:

Modify the code, and deploy it.

When the deployment is complete, let’s refresh the address:

You can see that it has been updated. At this point, we deploy again from the local:

As you can see, the system is aware of our code change. At this point, we select Yes and look at the online resources when we are done:

An additional note here is that any changes to services, functions, and triggers that are evaluated by functions can be sensed here, both in configuration and code.

Create and deploy an existing online resource locally

At this point, we proceed to the final experiment. We delete the local project and rebuild it. Then we deploy, and because we just experimented, we already have these resources online, so we’re deploying an online resource.

As you can see, the system senses that this resource has not been deployed locally, is online and already exists, so it needs to determine whether to override it.

conclusion

The code is updated in other scenarios, and we need to be aware of it at the moment, which is actually very important, and it is essential to secure the release of code. This can be done with Serverless Devs.

So what if I already have a project that I want to integrate into the CD process and I don’t want to have interactive operations?

In this case, we provide a –ues-local parameter to force the online configuration to be overwritten. With this directive, we can achieve non-interactive, local first.

Every tool has a growth process, and Serverless Devs is growing. Expect more and better features.

The original link

This article is ali Cloud original content, shall not be reproduced without permission.