Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
Codebuild (#4)
Browse files Browse the repository at this point in the history
* updating with correct vars

* updating project name

* updating vars

* updating tag info
  • Loading branch information
brentley authored Sep 18, 2018
1 parent 3aa99cb commit dcd5544
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions buildspec-dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,42 @@ env:
phases:
install:
commands:
- export IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- export IMAGE_TAG=$(echo $CODEBUILD_SOURCE_VERSION | cut -c 1-7)
- export ACCOUNT=$(echo $CODEBUILD_BUILD_ARN |cut -f5 -d:)
- export PROJECT_NAME=$(echo $CODEBUILD_BUILD_ID | sed -e 's/.*pipeline-\(.*\)-artifact.*/\1/')
- export IMAGE_REPO_NAME="${docker_hub_username}/$PROJECT_NAME"
- export PROJECT_NAME=$(basename $PWD)
- export CODEBUILD_GIT_BRANCH="$(git symbolic-ref HEAD --short 2>/dev/null)"
- if [ "$CODEBUILD_GIT_BRANCH" = "" ] ; then
CODEBUILD_GIT_BRANCH="$(git branch -a --contains HEAD | sed -n 2p | awk '{ printf $1 }')";
export CODEBUILD_GIT_BRANCH=${CODEBUILD_GIT_BRANCH#remotes/origin/};
fi
- export CODEBUILD_GIT_CLEAN_BRANCH="$(echo $CODEBUILD_GIT_BRANCH | tr '/' '.')"
- export CODEBUILD_GIT_ESCAPED_BRANCH="$(echo $CODEBUILD_GIT_CLEAN_BRANCH | sed -e 's/[]\/$*.^[]/\\\\&/g')"
- if [ "$CODEBUILD_GIT_CLEAN_BRANCH" = "master" ] ; then
export IMAGE_WORD_TAG='latest';
else
export IMAGE_WORD_TAG=${CODEBUILD_GIT_CLEAN_BRANCH};
fi
- echo '***** This is the current env:'
- printenv
pre_build:
commands:
- echo Logging in to Docker Hub...
- docker login -u ${docker_hub_username} -p ${docker_hub_password}
- docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PASSWORD}
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- echo $IMAGE_TAG > code_hash.txt
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker build -t $DOCKER_HUB_USERNAME/$PROJECT_NAME:$IMAGE_TAG .
- docker tag $DOCKER_HUB_USERNAME/$PROJECT_NAME:$IMAGE_TAG $DOCKER_HUB_USERNAME/$PROJECT_NAME:$IMAGE_WORD_TAG
# - docker build -t myimage .
post_build:
commands:
- printf '[{"name":"example-backend","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $IMAGE_REPO_NAME:$IMAGE_TAG
- docker push $DOCKER_HUB_USERNAME/$PROJECT_NAME:$IMAGE_TAG
- docker push $DOCKER_HUB_USERNAME/$PROJECT_NAME:$IMAGE_WORD_TAG
# - docker pull anchore/cli
# - docker run -d -v $(pwd):/source-dir -v /var/run/docker.sock:/var/run/docker.sock --name anchore anchore/cli:latest
# - docker exec anchore anchore feeds sync
Expand Down

0 comments on commit dcd5544

Please sign in to comment.