Arturo
Arturo

Reputation: 4180

Codebuild - build project simple hello world

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

Upvotes: 3

Views: 2565

Answers (2)

itnaliv
itnaliv

Reputation: 11

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.

Upvotes: 1

Pacifist
Pacifist

Reputation: 3203

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.

Upvotes: 3

Related Questions