From 3a7abb9a097add1c61c0aca093414d3286465237 Mon Sep 17 00:00:00 2001 From: Broderick-Sebastian <82418226+BroderickSebastian@users.noreply.github.com> Date: Thu, 2 Sep 2021 21:26:45 -0400 Subject: [PATCH 1/3] Update config.yml Update to file to complete Ch 2 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6845aa00..5e57bccb 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/BroderickSebastian/invoicer-chapter2 docker: - image: circleci/golang:1.10 steps: From 41b2df87d0767c4726aeccb430e1f60874e67660 Mon Sep 17 00:00:00 2001 From: Broderick-Sebastian <82418226+BroderickSebastian@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:42:18 -0400 Subject: [PATCH 2/3] Add .circleci/config.yml --- .circleci/config.yml | 72 +++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5e57bccb..2049bd27 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,48 +1,26 @@ -version: 2 +# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 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/BroderickSebastian/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 + build: + working_directory:/go/src/github.com/BroderickSebastian/invoicer-chapter2 + docker: + - image: circleci/golang:1.15.8 + steps: + - checkout + - restore_cache: + keys: + - go-mod-v4-{{ checksum "go.sum" }} + - run: + name: Install Dependencies + command: go mod download + - save_cache: + key: go-mod-v4-{{ checksum "go.sum" }} + paths: + - "/go/pkg/mod" + - run: + name: Run tests + command: | + mkdir -p /tmp/test-reports + gotestsum --junitfile /tmp/test-reports/unit-tests.xml + - store_test_results: + path: /tmp/test-reports From 44d0d5a04633419ba5bb7e4cfe258f6476a23f5a Mon Sep 17 00:00:00 2001 From: Broderick-Sebastian <82418226+BroderickSebastian@users.noreply.github.com> Date: Sun, 5 Sep 2021 13:40:21 -0400 Subject: [PATCH 3/3] Add .circleci/config.yml --- .circleci/config.yml | 71 ++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2049bd27..7fd1034f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,26 +1,47 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference -version: 2.1 +version: 2 jobs: - build: - working_directory:/go/src/github.com/BroderickSebastian/invoicer-chapter2 - docker: - - image: circleci/golang:1.15.8 - steps: - - checkout - - restore_cache: - keys: - - go-mod-v4-{{ checksum "go.sum" }} - - run: - name: Install Dependencies - command: go mod download - - save_cache: - key: go-mod-v4-{{ checksum "go.sum" }} - paths: - - "/go/pkg/mod" - - run: - name: Run tests - command: | - mkdir -p /tmp/test-reports - gotestsum --junitfile /tmp/test-reports/unit-tests.xml - - store_test_results: - path: /tmp/test-reports + 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/BroderickSebastian/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 \ No newline at end of file