MicroServices under Golang-part 9th-Deploy with Circleci

Source: Internet
Author: User
Tags circleci gcloud
Welcome to the [Patreon] (https://www.patreon.com/ewanvalentine) to provide me with more such material. In this section of this series, we will briefly describe the use of [Circleci] (http://circleci.com/) to establish continuous integration with one of our services. [Circleci] (http://circleci.com/) is an incredible tool that has a very useful free platform. This platform is SaaS, so unlike Jenkins, it is fully managed. At the same time its configuration and establishment are very straightforward. In addition, [Circleci] (http://circleci.com/) also uses Docker mirroring (images), so you can have a lot of ideas on how to manage your build. Make sure you have registered and created an account. First, let's create a new project in [Circleci] (http://circleci.com/). In the left menu, click "Add Project". If you have connected your github account to your [Circleci] (http://circleci.com/) account, you should be able to see your microservices git repository appear in the list. Click "Follow Project". You will see a request page where you can choose the operating system and language you prefer to use. Make sure that Linux and Go are selected. Then click Start Build. This will create some default configurations, but we need to add our own configuration to this code repository before the build can start working properly. So in our service (I will use our delegation service for this), create a new folder ' mkdir. Circleci ' in the project root directory, and then create a new file ' touch. Circleci/config.yml ' under this folder. Now let's start adding our build configuration. "' Version:2jobs:build:working_directory:/app Docker: # Here we select the Docker images we wish to use # in order to Build our service. # We ' re using a container I made, which configurs the Google Cloud SDK # Kubernetes, and a few other utils. ThIs are Open-source, and you can find # the repo here Https://github.com/EwanValentine/gcloud-docker-kubernetes # # then we ' Re using the Docker image itself, so that we can build Docker containers. -Image:ewanvalentine/gcdeploy:latest environment:gcloud_project_name:shippy-freight GCLOUD_CLUSTER_NAME: Shippy-freight-cluster Cloudsdk_compute_zone:europe-west2-a # This was a Google service key, which allows us to Authentica TE # Our build process with our cluster. # need to generate a service key, such as the one we generated # in part 7. You can copy the contents of this and encode it using Base64. # then add the Base64 string to your environment variables, in the settings # of this build project. To find this, click on the spanner icon in your build. # then click on Environment variables, click Add Variable, with the name Gcloud_service_key # then paste the Base64 string of your service key into the value and save that. Google_application_credentials: ${home}/gcloud-service-key.Json-image:docker:17.05.0-ce-git environment:docker_tag_prefix: "eu.gcr.io/$GCLOUD _project_name/ Shippy-consignment-service "Docker_tag:" $DOCKER _tag_prefix: $CIRCLE _sha1 "Steps:-Checkout-setup_remote_docker-run : Name:install dependencies # Fetches the Base64 encoded service key content, decodes it into a file again. # then sets the Gcloud project name from the environment variables we set above. # then we set the cluster name, the compute region/zone and then fetch the credentials. Command: | echo $GCLOUD _service_key | Base64--decode-i > ${home}/gcloud-service-key.json && \ gcloud Auth activate-service-account--key-file ${HO Me}/gcloud-service-key.json && \ gcloud config set project $GCLOUD _project_name && \ gcloud--quiet Config Set Container/cluster $GCLOUD _cluster_name && \ gcloud config set compute/zone ${cloudsdk_compute_zone} &&am P \ gcloud--quiet container clusters get-credentials $GCLOUD _cluster_name-deploy:name:push Application Docker Image command: | Make deploy ' ' for this to work we need to do something, I've talked about it in the comments, but it's an important step, so I want to reiterate that part. We need the Google Cloud service key, as we created in [7th Chapter] (https://studygolang.com/articles/12799), and then we need to encrypt this key into Base64 and store it as an environment variable in our build engineering setup. So find your Google Cloud service key and then run ' $ cat <keyname>.json | Base64 ', and copy the resulting string. Go back to [Circleci] (http://circleci.com/) your project, click on the gear at the top right, then select the environment variable in the left column. Create a new environment variable, name ' Gcloud_service_key ', and paste the previously obtained Base64 string as its value, and save it. The above operations can save any security information within the CIRCLECI and make the code warehouse less familiar with any sensitive data impact. It keeps these access keys under the control of the operations team, not just anyone who can access the code warehouse. Now in our build configuration, the variables used to authenticate our group are decoded into a file. It's quite simple. We have CI as one of our services. As a product service, you may run your test cases first before you perform the deployment steps. Check out [This document] (https://circleci.com/docs/2.0/) and see what you can do with circle. Because Circle uses a Docker container, you can even add a database container to allow you to run integration tests. Unleash your creativity and maximize the use of these features. If you think this series of articles is useful to you and you have an ad blocker (no one will blame you), consider giving me the time and effort to write these articles! Thank you! Https://monzo.me/ewanvalentine or, on [Patreon] (https://www.patreon.com/ewanvalentine), give me more stuff like that.

via:https://ewanvalentine.io/microservices-in-golang-part-9/

Author: Ewan Valentine Translator: maxambitious proofreading: polaris1119

This article by GCTT original compilation, go language Chinese network honor launches

This article was originally translated by GCTT and the Go Language Chinese network. Also want to join the ranks of translators, for open source to do some of their own contribution? Welcome to join Gctt!
Translation work and translations are published only for the purpose of learning and communication, translation work in accordance with the provisions of the CC-BY-NC-SA agreement, if our work has violated your interests, please contact us promptly.
Welcome to the CC-BY-NC-SA agreement, please mark and keep the original/translation link and author/translator information in the text.
The article only represents the author's knowledge and views, if there are different points of view, please line up downstairs to spit groove

240 Reads
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.