diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..01913ee5 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,44 @@ +version: 2 +jobs: + build: + # Variable expansion in working_directory not supported at this time + # You will need to modify the code below to reflect your github account/repo setup + working_directory: /go/src/github.com/Securing-DevOps/deployer + docker: + - image: circleci/golang:latest + environment: + GO15VENDOREXPERIMENT: 1 + branches: + only: + - master + steps: + - checkout + - setup_remote_docker + + - run: echo 'export GOPATH_HEAD="$(echo ${GOPATH}|cut -d ':' -f 1)"' >> $BASH_ENV + - run: echo 'export GOPATH_BASE="${GOPATH_HEAD}/src/github.com/${CIRCLE_PROJECT_USERNAME}"' >> $BASH_ENV + - run: echo 'export DOCKER_REPO="$(if [ ${CIRCLE_PROJECT_USERNAME} == 'securingdevops' ]; then echo securingdevops; else echo $DOCKER_USER; fi)"' >> $BASH_ENV + - run: mkdir -p "${GOPATH_BASE}" + - run: mkdir -p "${GOPATH_HEAD}/bin" + - run: go get github.com/govend/govend + - run: sudo apt-get -y install awscli + + - run: + name: Build application container + command: | + go install --ldflags '-extldflags "-static"' github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}; + [ ! -e bin ] && mkdir bin; + cp "${GOPATH_HEAD}/bin/${CIRCLE_PROJECT_REPONAME}" bin/deployer; + chmod +x deploymentTests/* + docker build -t ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME} .; + + - deploy: + # Push application container to dockerhub + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + echo ${DOCKER_PASS} | docker login -u ${DOCKER_USER} --password-stdin; + echo ${DOCKER_USER}/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_TAG}; + docker images --no-trunc | awk '/^app/ {print $3}' | sudo tee $CIRCLE_ARTIFACTS/docker-image-shasum256.txt; + docker push ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME}; + fi + aws elasticbeanstalk update-environment --region us-east-1 --application-name invoicer201707071231 --environment-id e-h4vyur8nup --version-label deployer-api diff --git a/circle.yml b/circle.yml deleted file mode 100644 index c380f104..00000000 --- a/circle.yml +++ /dev/null @@ -1,60 +0,0 @@ -# These environment variables must be set in CircleCI UI -# -# DOCKER_EMAIL - login info for docker hub -# DOCKER_USER -# DOCKER_PASS -# -# Read the README for more information. -machine: - environment: - GOPATH_HEAD: "$(echo $GOPATH | cut -d ':' -f 1)" - GOPATH_BASE: "$GOPATH_HEAD/src/github.com/$CIRCLE_PROJECT_USERNAME" - GO15VENDOREXPERIMENT: 1 - DOCKER_REPO: "$(if [ $CIRCLE_PROJECT_USERNAME == 'Securing-DevOps' ]; then echo securingdevops; else echo $DOCKER_USER; fi)" - - services: - - docker - -dependencies: - override: - - rm -rf ${GOPATH_BASE}/ - - mkdir -p "$GOPATH_BASE" - - mkdir -p "$GOPATH/bin" - - cp -r ${HOME}/${CIRCLE_PROJECT_REPONAME} ${GOPATH_BASE}/ - - go get github.com/govend/govend - - sudo pip install awscli - -test: - override: - - > - go test - github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} - # Go applications in the busybox container must be built statically - - > - go install --ldflags '-extldflags "-static"' - github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} - - '[ ! -e bin ] && mkdir bin' - - cp "$GOPATH_HEAD/bin/${CIRCLE_PROJECT_REPONAME}" bin/deployer - - chmod +x deploymentTests/* - - docker build -t ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME} . - - # Run GOVEND to check if outdated dependencies are present - - 'GOPATH="$GOPATH_HEAD"; ( cd ${GOPATH_BASE}/${CIRCLE_PROJECT_REPONAME} && govend -u && git diff --quiet )' - -deployment: - hub_latest: - # appropriately tag and push the container to dockerhub - # only when on the master branch - branch: "master" - commands: - - > - docker login -e ${DOCKER_EMAIL} - -u ${DOCKER_USER} -p ${DOCKER_PASS} - # write the sha256 sum to an artifact to make image verification easier - - > - docker images --no-trunc | awk '/^app/ {print $3}' | - tee $CIRCLE_ARTIFACTS/docker-image-shasum256.txt - - docker push ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME} - - # trigger ebs redeploy - - aws elasticbeanstalk update-environment --region us-east-1 --application-name invoicer201707071231 --environment-id e-h4vyur8nup --version-label deployer-api