Author | zheng cheng

Source |ERDA official account

I recently experienced building and deploying an application on Erda, and I was impressed by the power and agility of its DevOps platform, but I tried to simplify the application to get you up and running quickly, using a simple “Hello, World! Go Web application to illustrate.

Erda DOP

I’m sure there are many developers like me who don’t want to pay much attention to operational tasks (packaging, building, deploying, etc.) after completing new features in an application. I wanted a platform that would shield the complex logic of the underlying infrastructure, allow me to “declare” the process and results of my application as if I were writing code, and allow me to build and deploy my application quickly and easily without worrying about operations. Erda DOP is an application-centric, enterprise one-stop DevOps platform. Let’s write a Go Web application and see how it can help us quickly build and deploy.

Predeployment preparation

  1. Before creating and deploying our Go application, we need to join or create an organization and add the appropriate cluster to the organization for resource management and service deployment.
  2. Create projects in the organization. Project is the main object of R & D operation and maintenance.
  3. Create a new application under the project we just created, which I think is the equivalent of a GitHub Repo, to hold our application and the declaration files we need to build and deploy.

More information about organizations, projects, and applications can be found in the introduction

Now assume that we’ve created a new project under our organization called a base-project and created an application called Go-web within that project. These two names will be referred to in the Git address below.

Prepare the Go Web code

The sample code is just a simple Golang Web service that just needs to be able to output Hello, World! That’s it. Now create a new folder and create a file called main.go.

package main import ( "fmt" "log" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World!" ) } func main() { http.HandleFunc("/", handler) log.Fatal(http.ListenAndServe(":8080", nil)) }

Initialize package management for the Go application:

go mod init github.com/erda/go-web

Of course, this is just the code I wrote to simplify the application, but you can also write your own Go code (the Erda platform can deploy code that runs in any language or framework, not just Go/Java, etc.).

We then initialize the Git repository locally and commit it:

git init
git add .
git commit -m "initialize"

Push the demo code to the Erda platform

The platform is based on the standard Git protocol built-in implementation of a Git code repository, users do not need to rely on external repositories (such as: GitLab, etc.) can complete the whole process from source code development to deployment.

Platform Remote Warehouse Server Address View Entrance at:

DevOps Platform -> Project -> Application -> Code Repository -> Code Browse -> Repository Address

git remote add erda https://erda-org.erda.cloud/wb/base-project/go-web
git push -u erda --all
git push -u erda --tags

Define pipeline

As an application developer, we have completed the development of new features and pushed our code to the Git repository. Then we want to use some declarative files to define how to build our application, the resources and infrastructure our application depends on. Erda DOP provides two declarative files for one-click deployment purposes.

Pipeline. yml describes a pipeline configuration file from code compilation to application deployment. The syntax is relatively simple, and there are only stage/action levels overall. A stage is a stage that controls serialization and parallelism. The Action is the actual executing unit.

Dice. yml is a description file of application deployment, which is composed of basic service information and service arrangement relationship, specifically including the Docker image of micro-services, resource requirements (CPU and Memory, etc.), dependencies between micro-services, environment variables, and AddOn information. Addons, in particular, allow app developers to ignore setups such as MySQL, simply “declare” which Addons their app depends on, and the platform will automatically pull up. (However, since this example is relatively simple, there is no demonstration of Addon, those who are interested can check the official documentation)

Add platform configuration files pipe.yml and dice.yml to the demo code project.

pipeline.yml

To simply complete the deployment, four stages can be set to form pipeline.yml, and the four stages are executed in writing order, respectively:

  1. Pull up the Git source
  2. Based on source code compilation, build, make Docker image
  3. Generated version product
  4. Complete deployment based on release artifacts

The four stages can be executed by the following actions:

  1. git-checkout
  2. golang
  3. release
  4. dice

The complete pipeline.yml for this example:

Version: "1.1" : -stage: -git-checkout: alias: git-checkout - stage: -golang: alias: go-demo params: command: go build -o web-server main.go context: ${git-checkout} service: web-server - stage: - release: alias: release params: dice_yml: ${git-checkout}/dice.yml image: go-demo: ${go-demo:OUTPUT:image} - stage: - dice: alias: dice params: release_id: ${release:OUTPUT:releaseID}

dice.yml

Dice. yml to describe the size of resources and the number of replicas required by our application.

The complete dice.yml for this example:

Version: "2.0" services: go-demo: ports: -port: 8080 Expose: true resources: CPU: 0.2 mem: 512 deployments: replicas: 1

To submit documents

Commit the two new YAML files to the platform’s codebank:

git add .
git commit -m "add pipeline.yml and dice.yml"
git push erda

Executive pipeline

  1. Enter theAssembly line, click on the top right cornerNew assembly line.
  2. After the pipeline task analysis is completed, it is in the state to be executed. Click on the upper right cornerExecuted immediatelyTo start the build.
  3. During the execution of the pipeline task, you can view the execution status of each step of the pipeline in real time, and clickThe logView log information about the performance of the corresponding node.

View application deployment results

After building the source code through the pipeline and successfully deploying, you can see the successfully deployed application example in the Deployment Center.

Click Master to enter application management. You can further configure domain name, expand service instance capacity and other operations.

If you look at the instance IP address and copy it to the browser, add port 8080 to our application service and you can see that “Hello,World!” has been successfully printed. .

The last

The sample code used in this article is hosted directly on GitHub and can be cloned directly for use.

The above is just to build and deploy a Go Web application to experience a few core functions of Erda-DOP, Erda also has micro-service governance, multi-cloud management platform and other powerful functions, and Erda is now open source and released version 1.0, you can download through the link below and start quickly.

  • Erda GitHub: https://github.com/erda-proje…
  • Erda Cloud’s website: https://www.erda.cloud/