skip to Main Content

I am trying to test locally my build without needing to upload my code all over the time. Therefore, I downloaded the codebuild.sh into my ubuntu machine and places into ~/.local/bin/codebuild_build.

Then I made it executable via:

chmod +x ~/.local/bin/codebuild_build

And with the following buildspec.yml:

version: 0.2
phases:
  install:
    runtime-versions:
      docker: 18
  pre_build:
   commands:
     - docker login -u $USER -p $TOKEN
  build:
    commands:
     - docker build -f ./dockerfiles/7.0.8/Dockerfile -t myapp/php7.0.8:$(cat VERSION_PHP_708) -t myapp/php7.0.8:latest .
     - docker build -f ./dockerfiles/7.0.8/Dockerfile_develop -t myapp/php7.0.8-dev:$(cat VERSION_PHP_708) -t myapp/php7.0.8-dev:latest .
     - docker build -f ./dockerfiles/7.2/Dockerfile -t myapp/php7.0.8:$(cat VERSION_PHP_72) -t myapp/php7.0.8:latest .
     - docker build -f ./dockerfiles/7.2/Dockerfile_develop -t myapp/php7.0.8-dev:$(cat VERSION_PHP_708) -t myapp/php7.0.8-dev:latest .
  post_build:
    commands:
      - docker push etable/php7.2
      - docker push etable/php7.2-dev
      - docker push etable/php7.0.8
      - docker push etable/php7.0.8-dev

I tried to execute my command like that:

codebuild_build -i amazon/aws-codebuild-local -a /tmp/artifacts/docker-php -e .codebuild -c ~/.aws

But I get the following output:

Build Command:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock -e "IMAGE_NAME=amazon/aws-codebuild-local" -e "ARTIFACTS=/tmp/artifacts/docker-php" -e "SOURCE=/home/pcmagas/Kwdikas/docker-php" -v "/home/pcmagas/Kwdikas/docker-php:/LocalBuild/envFile/" -e "ENV_VAR_FILE=.codebuild" -e "AWS_CONFIGURATION=/home/pcmagas/.aws" -e "INITIATOR=pcmagas" amazon/aws-codebuild-local:latest

Removing agent-resources_build_1 ... done
Removing agent-resources_agent_1 ... done
Removing network agent-resources_default
Removing volume agent-resources_source_volume
Removing volume agent-resources_user_volume
Creating network "agent-resources_default" with the default driver
Creating volume "agent-resources_source_volume" with local driver
Creating volume "agent-resources_user_volume" with local driver
Creating agent-resources_agent_1 ... done
Creating agent-resources_build_1 ... done
Attaching to agent-resources_agent_1, agent-resources_build_1
build_1  | 2020/01/16 14:43:58 Unable to initialize (*errors.errorString: AgentAuth was not specified)
agent-resources_build_1 exited with code 10
Stopping agent-resources_agent_1 ... done
Aborting on container exit...

My ~/.aws has the following files:

$ ls -l /home/pcmagas/.aws
σύνολο 8
-rw------- 1 pcmagas pcmagas  32 Αυγ   8 17:29 config
-rw------- 1 pcmagas pcmagas 116 Αυγ   8 17:34 credentials

Whilst the config has the following:

[default]
region = eu-central-1

And ~/.aws/credentials is in the following format:

[default]
aws_access_key_id = ^KEY_ID_CENSORED^
aws_secret_access_key = ^ACCESS_KEY_CENSORED^

Also in the .codebuild I contain the required docker-login params:

USER=^CENCORED^
TOKEN=^CENCORED^

Hence, I can get the params required for docker-login.

Do you have any idea why I the build fails to run locally?

2

Answers


  1. Your pre-build step has a command that logs you in to docker

    docker login -u $USER -p $TOKEN
    

    Make sure that you have included the docker login credentials in your local file environment file.

    Login or Signup to reply.
  2. Change the environment variable name in ‘.codebuild’ file, e.g.:

    DOCKER_USER=^CENCORED^
    DOCKER_TOKEN=^CENCORED^
    

    It seems the CodeBuild agent is interpreting the ‘TOKEN’ environment variable itself.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search