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

Commit

Permalink
UPPSF-666 Testing orb
Browse files Browse the repository at this point in the history
  • Loading branch information
elizhuh committed Feb 10, 2020
1 parent e1eb76d commit 51d5077
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 83 deletions.
89 changes: 18 additions & 71 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,20 @@
version: 2
version: 2.1

orbs:
ft-golang-ci: financial-times/golang-ci@1.0.0

workflows:
version: 2
test-and-build-docker:
tests_and_docker:
jobs:
- build
- dockerfile:
filters:
tags:
only: /.*/
jobs:
build:
working_directory: /go/src/github.com/Financial-Times/mongo-hot-backup
docker:
- image: golang:1
environment:
GOPATH: /go
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_COVERAGE_REPORT: /tmp/coverage-results
steps:
- 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
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
- run:
name: Test Results
command: |
mkdir -p ${CIRCLE_TEST_REPORTS}
mkdir -p ${CIRCLE_COVERAGE_REPORT}
- run:
name: Go Build
command: go build -mod=readonly -v
- run:
name: Run Tests
command: go test -mod=readonly -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
dockerfile:
working_directory: /mongo-hot-backup
docker:
- image: docker:18
steps:
- checkout
- setup_remote_docker
- run:
name: Set Docker image tag based on branch or git tag
command: |
if [ ! -z "${CIRCLE_TAG}" ] ; then
echo 'export DOCKER_TAG=${CIRCLE_TAG}' >> $BASH_ENV
elif [ "${CIRCLE_BRANCH}" == "master" ] ; then
echo 'export DOCKER_TAG=latest' >> $BASH_ENV
else
echo 'export DOCKER_TAG=$( echo ${CIRCLE_BRANCH} | cut -f 2 -d / )' >> $BASH_ENV
fi
- run:
name: Build Dockerfile
command: |
source ${BASH_ENV}
docker build \
--tag nexus.in.ft.com:5000/coco/${CIRCLE_PROJECT_REPONAME}:${DOCKER_TAG} .
- deploy:
name: Push Docker image
command: |
source ${BASH_ENV}
docker login nexus.in.ft.com:5000 -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
docker push nexus.in.ft.com:5000/coco/${CIRCLE_PROJECT_REPONAME}:${DOCKER_TAG}
- ft-golang-ci/build-and-test:
name: build-and-test-project

- ft-golang-ci/docker-build:
name: build-docker-image
requires:
- build-and-test-project
snyk-scanning:
jobs:
- ft-golang-ci/scan:
name: scan-dependencies
context: org-global
27 changes: 16 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
FROM golang:1

ENV PROJECT=mongo-hot-backup
ENV BUILDINFO_PACKAGE="github.com/Financial-Times/service-status-go/buildinfo."

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

COPY . ${SRC_FOLDER}
WORKDIR ${SRC_FOLDER}

# Install dependancies and build app
RUN VERSION="version=$(git describe --tag --always 2> /dev/null)" \
&& DATETIME="dateTime=$(date -u +%Y%m%d%H%M%S)" \
&& REPOSITORY="repository=$(git config --get remote.origin.url)" \
&& REVISION="revision=$(git rev-parse HEAD)" \
&& BUILDER="builder=$(go version)" \
&& LDFLAGS="-s -w -X '"${BUILDINFO_PACKAGE}$VERSION"' -X '"${BUILDINFO_PACKAGE}$DATETIME"' -X '"${BUILDINFO_PACKAGE}$REPOSITORY"' -X '"${BUILDINFO_PACKAGE}$REVISION"' -X '"${BUILDINFO_PACKAGE}$BUILDER"'" \
&& echo "Build flags: $LDFLAGS" \
&& CGO_ENABLED=0 go build -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}"
&& DATETIME="dateTime=$(date -u +%Y%m%d%H%M%S)" \
&& REPOSITORY="repository=$(git config --get remote.origin.url)" \
&& 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 -mod=readonly -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}" \
&& echo "Build flags: ${LDFLAGS}"

EXPOSE 8080

# Multi-stage build - copy certs and the binary into the image
# 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/
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ You can deploy a docker container that will run backups on schedule. Or you can

For the schedule option, the state of backups is kept in a boltdb file at `/var/data/mongo-hot-backup/state.db` or where you set it.

A health endpoint is available at `0.0.0.0:8080/__health` and will report healthy if there was a successful backup for each configured collection in the last X hours, also configurable. Good-to-go `/__gtg` endpoint available as well, and `/build-info`.
A health endpoint is available at `0.0.0.0:8080/__health` and will report healthy if there was a successful backup
for each configured collection in the last X hours, also configurable. Good-to-go `/__gtg` endpoint available as
well, and `/__build-info`.

An initial backup to be run upon startup can be enabled.

Expand Down

0 comments on commit 51d5077

Please sign in to comment.