Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

- 8 mins read

Called just “Flow“, this is the long-awaited DevOps tool from Alibaba Cloud. Until now, this cloud provider didn’t have any CI/CD platform to help developers automate pipelines. Automating pipelines is a must nowadays for any software company, as makes deployments easier and more consistent, this reduces significantly human errors as completely removes manual steps of the process.

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

This tutorial assumes you have an ECS Instance with Alibaba Cloud Linux and ready to play with, and nothing important is running on it. If you don’t have one, you can start by creating one.

Prepare the ECS Instance

The idea of this tutorial is to create a pipeline and deploy a small bash script from a GitHub repository on an ECS Instance.

In order to use Flow, you’ll need to be make sure your Alibaba Cloud Linux is running the latest Cloud Assistant client. For this run the following:

wget https://aliyun-client-assist.oss-accelerate.aliyuncs.com/linux/aliyun_assist_latest.rpm

rpm -ivh --force aliyun_assist_latest.rpm

Create A New Organisation/Team

Go to https://flow.alibabacloud.com/ and, if this is the first time you access this tool, the interface will ask you to create a Organisation or Team. You’ll need to tell how big the Team is.

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Create a new Pipeline

The whole point of Flow is to make it easy to deploy by using pipelines. For this, we will just click “Create Pipeline” to continue:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Now, select “Others · Empty Template” and click “Create“, as we will create a Flow Pipeline from scratch:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

This Flow Pipeline will get triggered when new code is available in a GitHub repo. For this step, I created a “Bash Hello World” for you to make it easier:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

We are now in the “Process Configuration” panel, where we will create the steps for our Flow Pipeline, at the end it will look like the next picture:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Step 1: Test Script

Your pipeline will start with an “Empty Task“, click on it and change the name to “Run Script“. Then “Add Step” and select “Build > Execute Command“:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

In the code window, write sh hola-world.sh, as this script exists in the repository we are using and is a good way to test if everything is going well:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Step 2: Pack the Artifact

Now that our repository is being cloned and the bash script successfully executed, it’s time to pack the project as an Artifact so is available for the final step of deployment:

In the “Process Configuration” screen, click “Create Task” under a “New Phase” and select “Empty Template“. As the “Task Name” you can go with “Archive Artifact“. Then, “Add Step” and select “Upload > Artifact Archive“.

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Now, Set the “Step Name” as “Pack Script” and change the “Archive Paths” input to “hola-world.sh“, as this is the script we will deploy to our ECS.

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Step 3: ECS Deployment

This is the moment of truth, when we will see if everything is going okay and our code will finally be shipped.

Back again in the “Process Configuration” screen, click “Create Task” under a “New Phase” and select “ECS Deployment” under the “Deploy” Task Group.

In this step, be sure the checkbox “Download Artifact When Deploy” is checked and select the artefact we created in step 2 under “Artifact“.

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Now, you need to click “Create Deployment Group” to select the ECS Instance you want to use to deploy this script. You’ll probably need to click “Create Service Authorization” in the pop-up you’ll get, but just follow the instructions to give Flow permission on your Alibaba Cloud Account.

Once you selected the servers, edit the “Download Path” and write /opt/package.tgz in it. Now, in the “Deployment Script” write tar zxvf /opt/package.tgz && sh /opt/hola-world.sh, as our bash script will be already available inside the ECS Instance.

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

Step 4: Aaaand… Deploy!

I’m ready if you are ready, let’s go! Go and click on the top-right button “Save and Run“, then click “Run” in the pop-up window:

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

The screen now shows you the process of the Pipeline with all the phases “Run Script“, “Archive Artifacts” and “ECS Deployment“. In each Phase you’ll be able to click and see what is happening with the logs they offer you. If all 3 boxes goes green, then means everything went well and your code is deployed in the ECS!

Using Alibaba Cloud DevOps Flow to automate an ECS Deployment

To verify the script successfully ran in the ECS, click “Deployment Details” in the “ECS Deployment” box and then open the tab called “Logs” at the top of the new pop-up window. There, you’ll see all the details about the deployment and the “Hola World!” string from our script.


Share: Link copied to clipboard

Tags:

Previous: Migrate a WordPress site from Alibaba Cloud SAS to ECS
Next: Alibaba Cloud OSS, More Than Just Storage

Where: Home > Technical > Using Alibaba Cloud DevOps Flow to automate an ECS Deployment