Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use CodeBuild to build Cloud in AWS

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Many novices are not very clear about how to use CodeBuild to build the cloud in AWS. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

The authority system of AWS is based on the role of IAM, and CodeBuild is no exception. You need to specify the role of CodeBuild and give it the appropriate access rights.

Such as:

{"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Resource": "arn:aws:logs:*", "Action": ["logs:CreateLogGroup", "logs:CreateLogStream" "logs:PutLogEvents"]}, {"Effect": "Allow", "Resource": ["arn:aws:codecommit:*"], "Action": ["codecommit:GitPull"]} {"Effect": "Allow", "Resource": ["arn:aws:s3:*"], "Action": ["s3:PutObject"]}]}

This will allow you to create log groups, log streams, write log events to CloudWatch Logs, fetch source code from CodeCommit, and write objects to S3.

The permissions of the role will be different according to your needs.

Input source

You can choose from one of the CodeCommit code repositories, zip packages on S3 buckets, and GitHub code repositories as input sources.

The compressed package is automatically unzipped. The root directory entered is the current directory at the time of the build.

Environment

CodeBuild uses Docker image. For more information, please see the Docker image provided by CodeBuild.

Externally provided environment variables

The externally provided environment variables will override the preconfigured environment variables in the following order:

The value of the variable provided when the build operation is initiated

Build the variable value defined by the project

Variable values defined in the buildspec file

Do not name environment variables starting with CODEBUILD_, which is reserved for use internally by AWS.

Do not use the environment variable itself in the environment variable. If you cannot assign a value of $PATH:/path to PATH, because the environment variable will not be expanded, the value of PATH will be a literal amount of $PATH:/path. However, you can use other alternative symbols, such as assigning / usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/tools:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools to PATH, because it will be expanded when used.

Construction phase (Parse)

The life cycle of a CodeBuild build is divided into several phases:

SUBMITTED build request has been submitted

! PROVISIONING prepares to build the environment

DOWNLOAD_SOURCE download input source

* INSTALL installs build tools

* before PRE_BUILD is built

* BUILD construction

* after POST_BUILD is built

! UPLOAD_ARTIFACTS upload widget

FINALIZING finally decided

COMPLETED completed

Among them, the * marked can be customized! What is marked can be configured.

As shown in the figure:

Buildspec file

The buildspec file contains a series of configurations and commands to process input and get output. The file must be in the root directory of the input, named buildspec.yml, and formatted as YAML.

Version: 0.1environment_variables: plaintext: key: "value" key: "value" phases: install: commands:-command-command pre_build: commands:-command-command build: commands:-command-command post_build: commands:-command-commandartifacts: files:-file # current directory (root of input Files under the dir/file # subdirectory-all files under the dir/* # subdirectory-all folders and files under the recursive-dir/**/* # subdirectory discard-paths: no

Note that the YAML format is very strict, and carefully check your grammar, especially indentation.

Environment_variables specifies the environment variable.

Phases specifies the commands to be executed by each build process.

Artifacts specifies the file to export (files) and whether to discard the path structure (discard-paths). If discard-paths is yes, all files from the subdirectory will be moved to the root of the output directory.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report