Desarrollo Aplicaciones Nube CodeBuild
Desarrollo Aplicaciones Nube CodeBuild
Desarrollo Aplicaciones Nube CodeBuild
Infrastructure As A Service
Desarrollo de Aplicaciones
en la Nube
Infrastructure As A Service
Table of contents
• Amazon Web Services
• Elastic Cloud Computing
• Simple Storage Server
• Code Star
• CodeBuild
• Code Deploy
• Amazon SDK for Java
• Amazon SDK for Python
AWS Build
• AWS CodeBuild is a fully managed build service in the cloud. AWS CodeBuild
compiles your source code, runs unit tests, and produces artifacts that are ready
to deploy.
• WS CodeBuild eliminates the need to provision, manage, and scale your own
build servers.
• It provides prepackaged build environments for the most popular programming
languages and build tools such as Apache Maven, Gradle, and more.
• A build project defines how AWS CodeBuild runs a build. It includes information such
as where to get the source code, the build environment to use, the build commands
to run, and where to store the build output.
• A build environment represents a combination of operating system, programming
language runtime, and tools that AWS CodeBuild uses to run a build.
• A build spec is a collection of build commands and related settings, in YAML format,
that AWS CodeBuild uses to run a build.
• A build represents a set of actions performed by AWS CodeBuild to create output
artifacts (for example, a JAR file) based on a set of input artifacts (for example, a
collection of Java class files).
M.U. Ingeniería Informática E.T.S.I. Informática 8
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
Before you run your build with AWS CodeBuild, you must answer these questions:
1. Where is the source code located? AWS CodeBuild currently supports building
from the following source code repository providers. The source code must
contain a build specification (build spec) file, or the build spec must be
declared as part of a build project definition.
2. Which build commands do you need to run and in what order? By default,
AWS CodeBuild downloads the build input from the provider you specify and
uploads the build output to the bucket you specify. You use the build spec to
instruct how to turn the downloaded build input into the expected build
output.
3. Which runtimes and tools do you need to run the build? For example, are
you building for Java, Ruby, Python, or Node.js? Does the build need Maven or
Ant or a compiler for Java, Ruby, or Python? Does the build need Git, the AWS
CLI, or other tools?
5. In Source, for Source provider, choose the source code provider type.
• For Amazon S3:
• For Bucket, choose the name of the input bucket that contains the source code.
• For S3 object key or S3 folder, enter the name of the ZIP file or the path to the folder that
contains the source code. Enter a forward slash (/) to download everything in the S3
bucket.
6. In Environment:
• For Environment variables, type the name, value, and type of each environment variable for
builds to use. Use Create additional variable to add an environment variable.
• Note
• AWS CodeBuild sets the environment variable for your AWS Region automatically. If you do not add them to
your buildspec.yml, then the following environment variables must be set:
• AWS_ACCOUNT_ID
• IMAGE_REPO_NAME
• IMAGE_TAG
• Others can see environment variables by using the AWS CodeBuild console and the AWS CLI. If
you have no concerns about the visibility of your environment variable, set the Name and Value
fields, and then set Type to Plaintext.
M.U. Ingeniería Informática E.T.S.I. Informática 17
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
7. In Buildspec:
• For Build specifications, do one of the following:
• If your source code includes a buildspec file, choose Use a buildspec file.
• If your source code does not include a buildspec file, or if you want to run build commands
different from the ones specified for the build phase in the buildspec.yml file in the source
code's root directory, choose Insert build commands.
• For Build commands, enter the commands you want to run in the build phase. For multiple
commands, separate each command by && (for example, mvn test && mvn package). To run
commands in other phases, or if you have a long list of commands for the build phase, add a
buildspec.yml file to the source code root directory, add the commands to the file, and then
choose Use the buildspec.yml in the source code root directory.
M.U. Ingeniería Informática E.T.S.I. Informática 18
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
8. In Artifacts:
• For Artifacts type, do one of the following:
• If you do not want to create any build output artifacts, choose No artifacts. You might want to do
this if you're only running build tests or you want to push a Docker image to an Amazon ECR
repository.
• To store the build output in an Amazon S3 bucket, choose Amazon S3, and then do the following:
• If you want to use your project name for the build output ZIP file or folder, leave Name blank.
Otherwise, type enter the name. (If you want to output a ZIP file, and you want the ZIP file to
have a file extension, be sure to include it after the ZIP file name.)
• Select Use the name specified in the buildspec file if you want a name specified in the buildspec
file to override any name that is specified in the console.
• For Bucket name, choose the name of the output bucket.
M.U. Ingeniería Informática E.T.S.I. Informática 19
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
• You can create a trigger on a project to schedule a build once every hour, day, or
week.
• You can also create a trigger using a custom rule with an Amazon CloudWatch
cron expression. For example, using a cron expression, you can schedule a build
at a specific time every weekday.
• Choose the link for the build project to which you want to add a trigger, and
then choose the Build triggers tab.
• From the Frequency drop-down list, choose the frequency for your trigger. If you
want to create a frequency using a cron expression, choose Custom.
M.U. Ingeniería Informática E.T.S.I. Informática 22
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
• Choose Start build for the Build Project you want to run.
• On the Start build page, do one of the following:
• For Amazon S3, for the optional Source version value, type the version ID for the version
of the input artifact you want to build. If Source version is left blank, the latest version is
used.
• For AWS CodeCommit, for the optional Source version value, for Branch, choose the
name of the branch that contains the version of the source code you want to build. For
Source version, accept the displayed HEAD commit ID or enter a different one. If Source
version is blank, the default branch's HEAD commit ID is used.
• Under the section Advanced build overrides you can change settings for this build only.
The settings in this section are optional.
• Settings include:
• Source,
• Environment,
• Buildspec,
• Build Artifacts,
• Logs,
• Service Role.
• You can use the section Environment variables override if you want to change the
environment variables for this build only.
M.U. Ingeniería Informática E.T.S.I. Informática 25
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
• If you include a build spec as part of the source code, by default, the build spec
file must be named buildspec.yml and placed in the root of your source
directory.
• For S3, the source code in included in a zip file. The build spec file must be in the
root (top level) directory of the zip file.
• For AWS CodeCommit, GitHub, and Bitbucket repositories, by convention, you
must store a build spec file named buildspec.yml in the root (top level) of each
repository or include the build spec declaration as part of the build project
definition. Do not create a ZIP file that contains the repository's source code and
build spec file.
M.U. Ingeniería Informática E.T.S.I. Informática 28
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
phases:
install:
run-as: Linux-user-name
commands:
- command
- command
finally:
- command
- command
M.U. Ingeniería Informática E.T.S.I. Informática 30
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
pre_build:
run-as: Linux-user-name
commands:
- command
- command
finally:
- command
- command
M.U. Ingeniería Informática E.T.S.I. Informática 31
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
build:
run-as: Linux-user-name
commands:
- command
- command
finally:
- command
- command
M.U. Ingeniería Informática E.T.S.I. Informática 32
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
post_build:
run-as: Linux-user-name
commands:
- command
- command
finally:
- command
- command
M.U. Ingeniería Informática E.T.S.I. Informática 33
Desarrollo de Aplicaciones en la Nube
Infrastructure As A Service
artifacts:
files:
- location
- location
- name
discard-paths: yes
base-directory: location
• version: Required mapping. Represents the build spec version. Version 0.2
recommended.
• run-as: Optional sequence. Available to Linux users only. Specifies a Linux user
that runs commands in this buildspec file. If run-as is not specified, then all
commands run as the root.
Exercise
Exercise