From b062500d08f96d3f8c1cc09edae64d7ad7ab4f80 Mon Sep 17 00:00:00 2001 From: Gary Date: Sat, 13 Jun 2020 11:51:31 +0100 Subject: [PATCH 1/6] Update config.yml added working directory --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6845aa00..2791aefe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ 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/invoicer-chapter2 + working_directory: /go/src/github.com/am-i-heisenberg/invoicer-chapter2 docker: - image: circleci/golang:1.10 steps: From 7a32ea7d0ca28aa847270303206649cc73566071 Mon Sep 17 00:00:00 2001 From: Gary Date: Sat, 13 Jun 2020 11:52:29 +0100 Subject: [PATCH 2/6] Add .circleci/config.yml --- .circleci/config.yml | 61 ++++++++++---------------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2791aefe..01c267cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,48 +1,13 @@ -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/am-i-heisenberg/invoicer-chapter2 - docker: - - image: circleci/golang:1.10 - steps: - - checkout - - setup_remote_docker - - - run: - name: Setup environment - command: | - gb="/src/github.com/${CIRCLE_PROJECT_USERNAME}"; - if [ ${CIRCLE_PROJECT_USERNAME} == 'Securing-DevOps' ]; then - dr="securingdevops" - else - dr=$DOCKER_USER - fi - cat >> $BASH_ENV << EOF - export GOPATH_HEAD="$(echo ${GOPATH}|cut -d ':' -f 1)" - export GOPATH_BASE="$(echo ${GOPATH}|cut -d ':' -f 1)${gb}" - export DOCKER_REPO="$dr" - EOF - - run: mkdir -p "${GOPATH_BASE}" - - run: mkdir -p "${GOPATH_HEAD}/bin" - - - run: - name: Testing application - command: | - go test \ - github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} - - - deploy: - command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}; - go install --ldflags '-extldflags "-static"' \ - github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}; - mkdir bin; - cp "$GOPATH_HEAD/bin/${CIRCLE_PROJECT_REPONAME}" bin/invoicer; - docker build -t ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME} .; - docker images --no-trunc | awk '/^app/ {print $3}' | \ - sudo tee $CIRCLE_ARTIFACTS/docker-image-shasum256.txt; - docker push ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME}; - fi +# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 +# Use a package of configuration called an orb. +orbs: + # Declare a dependency on the welcome-orb + welcome: circleci/welcome-orb@0.4.1 +# Orchestrate or schedule a set of jobs +workflows: + # Name the workflow "welcome" + welcome: + # Run the welcome/run job in its own container + jobs: + - welcome/run \ No newline at end of file From 0a58cb88f4beaf1188a002cb8e8ea30847e0785e Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 14 Jun 2020 09:51:12 +0100 Subject: [PATCH 3/6] Add .circleci/config.yml --- .circleci/config.yml | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 01c267cc..af257f09 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,13 +1,26 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference -version: 2.1 -# Use a package of configuration called an orb. -orbs: - # Declare a dependency on the welcome-orb - welcome: circleci/welcome-orb@0.4.1 -# Orchestrate or schedule a set of jobs -workflows: - # Name the workflow "welcome" - welcome: - # Run the welcome/run job in its own container - jobs: - - welcome/run \ No newline at end of file +# Golang CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-go/ for more details +version: 2 +jobs: + build: + docker: + # specify the version + - image: circleci/golang:1.9 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/postgres:9.4 + + #### TEMPLATE_NOTE: go expects specific checkout path representing url + #### expecting it in the form of + #### /go/src/github.com/circleci/go-tool + #### /go/src/bitbucket.org/circleci/go-tool + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + steps: + - checkout + + # specify any bash command here prefixed with `run: ` + - run: go get -v -t -d ./... + - run: go test -v ./... \ No newline at end of file From 44b0f07c2e0945ef5d31f4e18533524bba8f6186 Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 14 Jun 2020 12:08:46 +0100 Subject: [PATCH 4/6] Add .circleci/config.yml From 59dbbaec1049f33edb7e427ceda957accbaca6a4 Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 14 Jun 2020 12:08:59 +0100 Subject: [PATCH 5/6] Add .circleci/config.yml From c80f3cf0affbd6dbb046a548bbf731783964230a Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 14 Jun 2020 12:14:38 +0100 Subject: [PATCH 6/6] Update config.yml --- .circleci/config.yml | 66 +++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index af257f09..2791aefe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,26 +1,48 @@ -# Golang CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-go/ for more details version: 2 jobs: - build: - docker: - # specify the version - - image: circleci/golang:1.9 + 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/am-i-heisenberg/invoicer-chapter2 + docker: + - image: circleci/golang:1.10 + steps: + - checkout + - setup_remote_docker - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/postgres:9.4 + - run: + name: Setup environment + command: | + gb="/src/github.com/${CIRCLE_PROJECT_USERNAME}"; + if [ ${CIRCLE_PROJECT_USERNAME} == 'Securing-DevOps' ]; then + dr="securingdevops" + else + dr=$DOCKER_USER + fi + cat >> $BASH_ENV << EOF + export GOPATH_HEAD="$(echo ${GOPATH}|cut -d ':' -f 1)" + export GOPATH_BASE="$(echo ${GOPATH}|cut -d ':' -f 1)${gb}" + export DOCKER_REPO="$dr" + EOF + - run: mkdir -p "${GOPATH_BASE}" + - run: mkdir -p "${GOPATH_HEAD}/bin" + + - run: + name: Testing application + command: | + go test \ + github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} - #### TEMPLATE_NOTE: go expects specific checkout path representing url - #### expecting it in the form of - #### /go/src/github.com/circleci/go-tool - #### /go/src/bitbucket.org/circleci/go-tool - working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} - steps: - - checkout - - # specify any bash command here prefixed with `run: ` - - run: go get -v -t -d ./... - - run: go test -v ./... \ No newline at end of file + - deploy: + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}; + go install --ldflags '-extldflags "-static"' \ + github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}; + mkdir bin; + cp "$GOPATH_HEAD/bin/${CIRCLE_PROJECT_REPONAME}" bin/invoicer; + docker build -t ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME} .; + docker images --no-trunc | awk '/^app/ {print $3}' | \ + sudo tee $CIRCLE_ARTIFACTS/docker-image-shasum256.txt; + docker push ${DOCKER_REPO}/${CIRCLE_PROJECT_REPONAME}; + fi