Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPPSF-1150 Refactored project #35

Merged
merged 13 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 80 additions & 48 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,113 @@
version: 2
version: 2.1

orbs:
snyk: snyk/snyk@0.0.8
MiroslavGatsanoga marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
working_directory: /go/src/github.com/Financial-Times/content-rw-elasticsearch
docker:
- image: golang:1
environment:
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_COVERAGE_REPORT: /tmp/coverage-results
- image: golang:1
environment:
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_COVERAGE_REPORT: /tmp/coverage-results
steps:
- checkout
- run:
name: External dependencies
command: |
go get -u github.com/mattn/goveralls
go get -u github.com/jstemmer/go-junit-report
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- run:
name: Make result folders
command: |
mkdir -p ${CIRCLE_TEST_REPORTS}
mkdir -p ${CIRCLE_COVERAGE_REPORT}
- run:
name: Download vendored dependencies
command: dep ensure -v -vendor-only
- run:
name: Go build
command: go build -v
- run:
name: Run tests
command: go test -race -cover -coverprofile=${CIRCLE_COVERAGE_REPORT}/coverage.out ./... | go-junit-report > ${CIRCLE_TEST_REPORTS}/junit.xml
- run:
name: Upload coverage
command: goveralls -coverprofile=${CIRCLE_COVERAGE_REPORT}/coverage.out -service=circle-ci -repotoken=${COVERALLS_TOKEN}
- store_test_results:
path: /tmp/test-results
- checkout
- run:
name: External dependencies
command: |
GO111MODULE=off go get -u github.com/mattn/goveralls
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
GO111MODULE=off go get -u github.com/myitcv/gobin
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0
wget https://raw.githubusercontent.com/Financial-Times/upp-coding-standard/v1.0.0/golangci-config/.golangci.yml
STATIK_VERSION=$(go list -mod=readonly -m all | grep statik | cut -d ' ' -f2)
gobin github.com/rakyll/statik@${STATIK_VERSION}
- run:
name: Make result folders
command: |
mkdir -p ${CIRCLE_TEST_REPORTS}
mkdir -p ${CIRCLE_COVERAGE_REPORT}
- run:
name: Go build
command: |
go generate ./cmd/content-rw-elasticsearch
go build -mod=readonly -v ./cmd/content-rw-elasticsearch
- run:
name: Run Linters
command: golangci-lint run --config=.golangci.yml --new-from-rev=master
- run:
name: Run tests
command: go test -race -mod=readonly -cover -coverprofile=${CIRCLE_COVERAGE_REPORT}/coverage.out ./... | go-junit-report > ${CIRCLE_TEST_REPORTS}/junit.xml
- run:
name: Upload coverage
command: goveralls -coverprofile=${CIRCLE_COVERAGE_REPORT}/coverage.out -service=circle-ci -repotoken=${COVERALLS_TOKEN}
- store_test_results:
path: /tmp/test-results
dockerfile:
working_directory: /content-rw-elasticsearch
docker:
- image: docker:18.03
- image: docker:18.03
steps:
- checkout
- setup_docker_engine
- run:
name: Build Dockerfile
command: docker build .
- checkout
- setup_remote_docker
- run:
name: Build Dockerfile
command: docker build .
dredd:
working_directory: /go/src/github.com/Financial-Times/content-rw-elasticsearch
docker:
- image: bankrs/golang-dredd:go1.10.0-dredd5.1.5
- image: golang:1
environment:
GOPATH: /go
ELASTICSEARCH_SAPI_ENDPOINT: http://localhost:9000
- image: peteclarkft/ersatz:stable
steps:
- checkout
- run:
name: Load ersatz-fixtures.yml to ersatz image
command: "curl -X POST --data-binary @_ft/ersatz-fixtures.yml -H \"Content-type: text/x-yaml\" http://localhost:9000/__configure"
- run:
name: External Dependencies
name: Download dredd
command: |
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
curl -sL https://deb.nodesource.com/setup_11.x | bash -
DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs=11.\*
npm install -g --unsafe-perm --loglevel warn --user 0 --no-progress dredd@11.2.19
rm -rf /var/lib/apt/lists/*
GO111MODULE=off go get -u github.com/myitcv/gobin
STATIK_VERSION=$(go list -mod=readonly -m all | grep statik | cut -d ' ' -f2)
gobin github.com/rakyll/statik@${STATIK_VERSION}
- run:
name: Download vendored dependencies
command: dep ensure -v -vendor-only
name: Load ersatz-fixtures.yml to ersatz image
command: "curl -X POST --data-binary @_ft/ersatz-fixtures.yml -H \"Content-type: text/x-yaml\" http://localhost:9000/__configure"
- run:
name: Go Build
command: go build -v
command: |
go generate ./cmd/content-rw-elasticsearch
go build -mod=readonly -v ./cmd/content-rw-elasticsearch
- run:
name: Dredd API Testing
command: dredd
snykscan:
working_directory: /go/src/github.com/Financial-Times/content-rw-elasticsearch
docker:
- image: circleci/golang:1
steps:
- checkout
- snyk/scan:
monitor-on-build: false
severity-threshold: medium
fail-on-issues: true

workflows:
version: 2
test-and-build-docker:
jobs:
- build
- dredd
- dockerfile:
requires:
- build
- build
scanning:
jobs:
- build
- snykscan:
context: cm-team-snyk
requires:
- build
21 changes: 19 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
*.iml
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# IntelliJ files
*.iml
.idea

/content-rw-elasticsearch
vendor/*/
statik
19 changes: 9 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ ENV PROJECT=content-rw-elasticsearch

ENV ORG_PATH="github.com/Financial-Times"
ENV SRC_FOLDER="${GOPATH}/src/${ORG_PATH}/${PROJECT}"
ENV BUILDINFO_PACKAGE="${ORG_PATH}/${PROJECT}/vendor/${ORG_PATH}/service-status-go/buildinfo."
ENV BUILDINFO_PACKAGE="${ORG_PATH}/service-status-go/buildinfo."

COPY . ${SRC_FOLDER}
WORKDIR ${SRC_FOLDER}

# Set up our extra bits in the image
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

# Install dependancies
RUN $GOPATH/bin/dep ensure -vendor-only
# Install statik cli tool in GOPATH in order to successfully execute the go generate command
RUN GO111MODULE=off go get -u github.com/myitcv/gobin \
# Get statik version from go.mod of the project
&& STATIK_VERSION="$(go list -mod=readonly -m all | grep statik | cut -d ' ' -f2)" \
&& gobin github.com/rakyll/statik@${STATIK_VERSION} \
&& go generate ./cmd/${PROJECT}

# Build app
RUN VERSION="version=$(git describe --tag --always 2> /dev/null)" \
Expand All @@ -22,15 +23,13 @@ RUN VERSION="version=$(git describe --tag --always 2> /dev/null)" \
&& REVISION="revision=$(git rev-parse HEAD)" \
&& BUILDER="builder=$(go version)" \
&& LDFLAGS="-X '"${BUILDINFO_PACKAGE}$VERSION"' -X '"${BUILDINFO_PACKAGE}$DATETIME"' -X '"${BUILDINFO_PACKAGE}$REPOSITORY"' -X '"${BUILDINFO_PACKAGE}$REVISION"' -X '"${BUILDINFO_PACKAGE}$BUILDER"'" \
&& CGO_ENABLED=0 go build -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}" \
&& CGO_ENABLED=0 go build -mod=readonly -a -o /artifacts/${PROJECT}/${PROJECT} -ldflags="${LDFLAGS}" ./cmd/${PROJECT} \
&& echo "Build flags: ${LDFLAGS}"

# Multi-stage build - copy only the certs and the binary into the image
FROM scratch
WORKDIR /
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=0 /artifacts/* /

# Copy things specific for this service
COPY ./runtime/referenceSchema.json /

CMD [ "/content-rw-elasticsearch" ]
Loading