From a3294a496b4b8c3abffab0f25661d320e1f50de8 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Wed, 6 Sep 2017 17:11:05 +0100 Subject: [PATCH 1/3] Migrate to micro container --- Dockerfile | 12 ++++++------ Makefile | 1 + entrypoint.sh | 7 ------- setup.go | 10 +++------- 4 files changed, 10 insertions(+), 20 deletions(-) delete mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 8599c6d..f7d3263 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM golang:1.8.2-alpine - +FROM golang:1.9.0-alpine3.6 as compiler RUN apk add --update git && apk add --update make && rm -rf /var/cache/apk/* - ADD . /go/src/github.com/${GITHUB_ORG:-ernestio}/monit WORKDIR /go/src/github.com/${GITHUB_ORG:-ernestio}/monit +RUN make deps && CGO_ENABLED=0 go install -a -ldflags '-s' . -RUN make deps && go install - -ENTRYPOINT ./entrypoint.sh +FROM scratch +COPY --from=compiler /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=compiler /go/bin/monit . +ENTRYPOINT ["./monit"] diff --git a/Makefile b/Makefile index 48201f7..bd19e63 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ deps: go get github.com/nats-io/nats go get github.com/dgrijalva/jwt-go go get github.com/r3labs/pattern + go get github.com/ernestio/ernest-config-client dev-deps: deps go get github.com/smartystreets/goconvey/convey diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 7aed913..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env sh - -echo "Waiting for NATS" -while ! echo exit | nc nats 4222; do sleep 1; done - -echo "Starting monit" -/go/bin/monit diff --git a/setup.go b/setup.go index 53ff013..e64912e 100644 --- a/setup.go +++ b/setup.go @@ -6,11 +6,10 @@ package main import ( "encoding/json" - "log" "os" "time" - "github.com/nats-io/nats" + ecc "github.com/ernestio/ernest-config-client" ) type monitorConfig struct { @@ -21,11 +20,8 @@ type monitorConfig struct { func setup() { var err error // Open Nats connection - nc, err = nats.Connect(os.Getenv("NATS_URI")) - if err != nil { - log.Println("Could not connect to nats") - return - } + ec := ecc.NewConfig(os.Getenv("NATS_URI")) + nc = ec.Nats() secret = os.Getenv("JWT_SECRET") if secret == "" { From a6ddee9b5df36a701fe9f7d2a38cc797d271ba82 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Thu, 14 Sep 2017 15:26:22 +0100 Subject: [PATCH 2/3] Migrate to CircleCI 2.0 --- .circleci/config.yml | 37 +++++++++++++++++++++++++++++++++++++ .ernest-ci | 3 ++- README.md | 9 +++------ circle.yml | 35 ----------------------------------- 4 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 circle.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..0f8c4c5 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,37 @@ +version: 2 +jobs: + build: + machine: + image: circleci/classic:201709-01 + environment: + NATS_URI: nats://127.0.0.1:4222 + ROOTPATH: /home/circleci/.go_workspace/src/github.com/ernestio + NATS_URI_TEST: nats://127.0.0.1:4222 + GOBIN: /home/circleci/.go_workspace/bin + CURRENT_INSTANCE: http://ernest.local:80/ + JWT_SECRET: test + IMPORT_PATH: "github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" + ERNEST_LOG_FILE: '/tmp/ernest.log' + ERNEST_APPLY_DELAY: 1 + ERNEST_CRYPTO_KEY: mMYlPIvI11z20H1BnBmB223355667788 + working_directory: /home/circleci/.go_workspace/src/github.com/ernestio/monit + steps: + - checkout + - run: + name: Setup Hosts File + command: echo 127.0.0.1 ernest.local | sudo tee -a /etc/hosts + - run: + name: Install Dependencies + command: make dev-deps + - run: + name: Code Analysis + command: make lint + - run: + name: Unit Tests + command: make test + - run: + name: Integration Tests + command: | + git clone -b f-circleci-v2-680 git@github.com:ernestio/toolset.git /tmp/toolset/ + cd /tmp/toolset/ernestci/ && bundle install + ruby /tmp/toolset/ernestci/run.rb $CIRCLE_WORKING_DIRECTORY/.ernest-ci diff --git a/.ernest-ci b/.ernest-ci index 8b13789..40b959f 100644 --- a/.ernest-ci +++ b/.ernest-ci @@ -1 +1,2 @@ - +ernest:f-micro-container-671 +config-store:f-micro-container-671 diff --git a/README.md b/README.md index 051a0d6..f11cdb8 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,14 @@ # Monit +master: [![CircleCI](https://circleci.com/gh/ernestio/monit/tree/master.svg?style=shield)](https://circleci.com/gh/ernestio/monit/tree/master) +develop: [![CircleCI](https://circleci.com/gh/ernestio/monit/tree/develop.svg?style=shield)](https://circleci.com/gh/ernestio/monit/tree/develop) + ## Synopsis This microservice listens to all `monitor.user` events that are fired off by the FSM. It allows users to listen to the event stream over SSE (Server Side Events) These events are collected into an inbox based on the monitor id passed by the user on an action. The inbox is opened on `service.create`, `service.delete` and closed on `service.create.done` and `service.delete.done`. If no inbox with the given ID exists when a user connects, one will be created. -## Build status - -* Master: [![CircleCI Master](https://circleci.com/gh/ernestio/monit/tree/master.svg?style=svg)](https://circleci.com/gh/ernestio/monit/tree/master) -* Develop: [![CircleCI Develop](https://circleci.com/gh/ernestio/monit/tree/develop.svg?style=svg)](https://circleci.com/gh/ernestio/monit/tree/develop) - - ## Installation ``` diff --git a/circle.yml b/circle.yml deleted file mode 100644 index b57cc2c..0000000 --- a/circle.yml +++ /dev/null @@ -1,35 +0,0 @@ -machine: - pre: - - curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0 - - touch /tmp/ernest.log && chmod 666 /tmp/ernest.log - - curl -L https://github.com/docker/compose/releases/download/1.10.0/docker-compose-`uname -s`-`uname -m` > /home/ubuntu/bin/docker-compose - - chmod +x /home/ubuntu/bin/docker-compose - services: - - docker - environment: - NATS_URI: nats://127.0.0.1:4222 - NATS_URI_TEST: nats://127.0.0.1:4222 - GOBIN: /home/ubuntu/.go_workspace/bin - CURRENT_INSTANCE: http://ernest.local:80/ - JWT_SECRET: test - IMPORT_PATH: "github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME" - ERNEST_LOG_FILE: '/tmp/ernest.log' - ROOTPATH: /home/ubuntu/.go_workspace/src/github.com/ernestio/ - ERNEST_CRYPTO_KEY: mMYlPIvI11z20H1BnBmB223355667788 - - hosts: - ernest.local: 127.0.0.1 - - -dependencies: - pre: - - make dev-deps - - mkdir -p $ROOTPATH/ - - rm -rf $ROOTPATH/toolset/ && git clone git@github.com:ernestio/toolset.git $ROOTPATH/toolset/ - - cd $ROOTPATH/toolset/ernestci/ && bundle install - -test: - override: - - make test - - ruby $ROOTPATH/toolset/ernestci/run.rb .ernest-ci - - make lint From 28d63a8bb2318722835dd7011c53149f01fe176c Mon Sep 17 00:00:00 2001 From: Tom Bevan Date: Mon, 18 Sep 2017 12:19:39 +0100 Subject: [PATCH 3/3] Update .ernest-ci --- .ernest-ci | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.ernest-ci b/.ernest-ci index 40b959f..8b13789 100644 --- a/.ernest-ci +++ b/.ernest-ci @@ -1,2 +1 @@ -ernest:f-micro-container-671 -config-store:f-micro-container-671 +