3

I'm trying to build a simple hello world on AWS Codebuild but I can't get the buildspec.yml working... I just want to put a simple html with some css in a folder. That's it.

This is the repo that I'm trying to build from.

If you look inside, the .yml has the following:

version: 0.2

run-as: ec2-user

phases:
  install:
    run-as: ec2-user
    runtime-versions:
      nodejs: 10

artifacts:
  files:
    - /index.html
  name: artifact-name
    - source: /
      destination: /var/www/html
#  base-directory: /var/www/html/

This and this are the doc for the .yml but I don't understand what to write, it's not java, not python, just an html.

EDIT: I forgot to put the error: YAML_FILE_ERROR: mapping values are not allowed in this context at line 14

EDIT2: This is how I have the buildspec.yml:

buildspec.yml

And this is how I have the env (the codedeploy and pipeline I'm using my own ec2 instance, is that a problem?)

Enviroment: enter image description here enter image description here

FINAL EDIT:

The problem was the image! Change it to Ubuntu version 1.0

3
  • Do you want to install this on an EC2 as well? Just asking as you are using run-as: ec2-user. Commented Aug 30, 2019 at 4:31
  • @Pacifist_AWS At this point I just want to install it whatever, I just need to create a deploy, build and pipeline, I can even create a whole instance dedicated to it. All the tutorials are so old that everything changed. Would you know how to do it? Commented Aug 30, 2019 at 14:24
  • as a general rule, relative paths don't start with a forward slash '/'. Have you tried replacing '/index.html' with just 'index.html' or './index.html'? Commented Aug 30, 2019 at 14:57

2 Answers 2

3

You need to build a CodePipeline which will have :

  1. Source: It could be Github, code will be checked out from here.
  2. CodeBuild: It will build your artifact and upload it to the S3 bucket so that it could use it while deploying.
  3. CodeDeploy: It will fetch out the code from S3 bucket and do the deployment on Deployment Group created by you.

Create buildspec.yml for codebuild and put it in root. Similarly, create appspec.yml for codedeploy and put it in root.

Sample buildspec.yml

version: 0.2

phases:
  pre_build:
   commands:
       - echo "creating <path-to-folder> folder"
       - mkdir -p ./<path-to-folder>/
  build:
    commands:
        - echo "Copying the file"
        - cp index.html ./<path-to-folder>/
artifacts:
   files:
      - <path-to-folder>/**/*
      - appspec.yml

buildspec.yml will create a folder and will copy your index.html into it and put it on S3.

sample appspec.yml

version: 0.0
os: linux
files:
  - source: <path-to-folder>/index.html
    destination: /var/www/html/
hooks:
  BeforeInstall:
    - location: <location-of-script-you-want-to-run>
      timeout: 300
      runas: root
    - location: <location-of-script-you-want-to-run>
      timeout: 300
      runas: root
  ApplicationStop:
    - location: <location-of-script-you-want-to-run>
      timeout: 300
      runas: root

appspec.yml will download the artifact from S3 and copy the file from your folder to /var/www/html/ and you can provide other script to start or stop the service.

Sign up to request clarification or add additional context in comments.

9 Comments

Wow that's something! We are getting there. I was able to do the code deploy and also the pipeline but I'm stuck on the build because of the buildspec.yml, if in my root I have a simple html file, and this are my enviroment: user: ec2-user Current environment image: aws/codebuild/amazonlinux2-x86_64-standard:1.0 How can I put that on the file? it always also asks for the run time too
From Docs : runtime-versions: Required if using the Ubuntu standard image 2.0 or later, or the Amazon Linux (AL2) standard image 1.0 or later. A runtime version is not supported with a custom image or the Ubuntu standard image 1.0. Just use OS as ubuntu, image: standard:1.0 and image ver: 1.0 then no runtime version is required.
LOVE YOU!!!! OH my godd!!! FINALLYYYY that ubuntu image worked! THANKS!!!
@Arturo Thanks :)
That is something you need to take care in buildspec.yml like this - <path-to-folder>/**/* . This includes everything in the dir.
|
1

Please remove the leading slash from index.html. Also, can you try updating your artifacts block to the following:

version: 0.2

run-as: ec2-user

phases:
  install:
    run-as: ec2-user
    runtime-versions:
      nodejs: 10

artifacts:
  files:
    - index.html

By default CodeBuild is using the root folder of the source input. If you must, you may specify it as such:

artifacts:
  files:
    - location
    - location
  name: artifact-name
  discard-paths: yes
  base-directory: location        # Look here

Additionally, you also seem to be mixing syntax from appspec.yml, which is a different beast altogether. There is no need to specify destination in buildspec.yml.

3 Comments

If I only put that in the Buildspec.yml it's going to complain, how can I create a .ylm file that only reads the html hello world file? I'm using: user: ec2-user Current environment image: aws/codebuild/amazonlinux2-x86_64-standard:1.0
@Arturo I only said to update the artifacts section, not the entire buildspec.yml. Please see edited answer.
Please check the initial post for EDIT2 and tell me your opinion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.