Skip to content

Commit

Permalink
Dockerize Laika (#178)
Browse files Browse the repository at this point in the history
* convert to go mod

* remove vendor references

* dockerize laika

* fix tests

* update running tests to new go syntax

* update linting script
  • Loading branch information
peterzernia authored Jan 30, 2020
1 parent f39833a commit 226de5b
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 148 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ jobs:
working_directory: /go/src/github.com/MEDIGO/laika
steps:
- checkout
- run: go get -u -v -t github.com/Masterminds/glide
- run: glide install -v
- run: go mod download
- run: touch .env
- run: pwd
- run: ls
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.git
node_modules/
vendor/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ coverage.out
node_modules/
bundle.js
dashboard/public/index.html
vendor/
/data
25 changes: 7 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The command endpoint is for manipulating data.

## Client

Laika contains a polling HTTP client that allows to easily check for enabled/disabled features on Go code. It can be found in the `client` package. While Laika uses the `vendor` directory to store external dependencies, `client` can be imported without any vendoring.
Laika contains a polling HTTP client that allows to easily check for enabled/disabled features on Go code. It can be found in the `client` package.

### Install

Expand Down Expand Up @@ -81,19 +81,9 @@ func main() {

To develop Laika you need to have the following tools installed in your machine:

* [Go](https://golang.org/doc/install)
* [Node.JS](https://nodejs.org/en/download/)
* [Glide](https://github.com/Masterminds/glide)
* [MySQL](https://dev.mysql.com/downloads/installer/)
- [Docker Compose](https://docs.docker.com/compose/install/)

Then install all the Go and Javascript dependencies with:

```sh
$ make install
```


Build continuously the server and UI with:
Build and start the docker contaniers and continuously run/build the server and UI with:

```sh
$ make develop
Expand All @@ -113,15 +103,14 @@ The whole test suite can be executed with:
$ make test
```

Some test require a MySQL instance, you can pass the configuration to them with the following
environment variables:
The docker setup starts with a mysql database. If you would like to connect to your own database, you can pass the configuration to them with the following environment variables:

```
LAIKA_TEST_MYSQL_HOST=localhost
LAIKA_TEST_MYSQL_HOST=db
LAIKA_TEST_MYSQL_PORT=3306
LAIKA_TEST_MYSQL_USERNAME=root
LAIKA_TEST_MYSQL_PASSWORD=root
LAIKA_TEST_MYSQL_DBNAME=test
LAIKA_TEST_MYSQL_DBNAME=laika
```

## Current state of the project
Expand All @@ -139,4 +128,4 @@ In the current release of Laika, it is possible to create feature flags and enab

Copyright © 2019 MEDIGO GmbH.

Laika is licensed under the MIT License. See [LICENSE](LICENSE) for the full license text.
Laika is licensed under the MIT License. See [LICENSE](LICENSE) for the full license text.
12 changes: 12 additions & 0 deletions dashboard/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:12.9.1-alpine

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app/

COPY package.json /usr/src/app/
COPY yarn.lock /usr/src/app/

RUN yarn install

COPY . /usr/src/app/
17 changes: 17 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.13-alpine

# Required for running go tests
RUN apk --no-cache add gcc g++ make ca-certificates

WORKDIR /go/src/github.com/MEDIGO/laika

COPY go.mod /go/src/github.com/MEDIGO/laika
COPY go.sum /go/src/github.com/MEDIGO/laika

RUN go mod download

RUN go get github.com/ivpusic/rerun

COPY . /go/src/github.com/MEDIGO/laika

EXPOSE 8000
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3.3"

services:
laika:
build:
context: ./
dockerfile: dev.Dockerfile
command: rerun -a run -i dashboard,node_modules,bin,public,.git
env_file: .env
volumes:
- .:/go/src/github.com/MEDIGO/laika
ports:
- "8000:8000"
depends_on:
- db
links:
- db
dashboard:
build:
context: ./dashboard
dockerfile: dev.Dockerfile
command: yarn run watch
volumes:
- ./dashboard:/usr/src/app
- node_modules:/usr/src/app/node_modules
db:
hostname: db
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- ./data/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laika
MYSQL_PASSWORD: root
volumes:
node_modules:
79 changes: 0 additions & 79 deletions glide.lock

This file was deleted.

23 changes: 0 additions & 23 deletions glide.yaml

This file was deleted.

29 changes: 29 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module github.com/MEDIGO/laika

go 1.13

require (
github.com/DataDog/datadog-go v0.0.0-20180305115502-72108a55170c
github.com/MEDIGO/go-healthz v0.0.0-20160923151312-9b0725fef657
github.com/Sirupsen/logrus v1.0.6-0.20180315010703-90150a8ed11b
github.com/davecgh/go-spew v1.1.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-sql-driver/mysql v1.3.1-0.20180308100310-1a676ac6e4dc
github.com/labstack/echo v3.3.4+incompatible
github.com/labstack/gommon v0.2.2-0.20180316174944-3bc2d333a4c3
github.com/mattn/go-colorable v0.1.0
github.com/mattn/go-isatty v0.0.4
github.com/pmezard/go-difflib v1.0.0
github.com/rubenv/sql-migrate v0.0.0-20180217203553-081fe17d19ff
github.com/satori/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5
github.com/stretchr/testify v1.2.2-0.20180319223459-c679ae2cc0cb
github.com/urfave/cli v1.20.1-0.20180226030253-8e01ec4cd3e2
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4
github.com/vsco/slackhook v0.0.0-20160714202444-761b10b6951a
golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4
golang.org/x/sys v0.0.0-20180322165403-91ee8cde4354
google.golang.org/appengine v1.0.1-0.20171212223047-5bee14b453b4
gopkg.in/gorp.v1 v1.7.1
gopkg.in/tylerb/graceful.v1 v1.2.15
)
45 changes: 45 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
github.com/DataDog/datadog-go v0.0.0-20180305115502-72108a55170c h1:cH9Dj+Jyw+tIZBVXgM24+DFkQwT/lPXbtSjrPw++5KY=
github.com/DataDog/datadog-go v0.0.0-20180305115502-72108a55170c/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/MEDIGO/go-healthz v0.0.0-20160923151312-9b0725fef657 h1:55rwZWQGzuRxQnnqKBL71MuQjcTNAGw8iE+wNwUakNo=
github.com/MEDIGO/go-healthz v0.0.0-20160923151312-9b0725fef657/go.mod h1:1zcAp3gzKAUb9mYYKLVYSGkWHvTYNVE4XjbFUnJejA4=
github.com/Sirupsen/logrus v1.0.6-0.20180315010703-90150a8ed11b h1:9q4iq4XcIKj6e6U22bvbcy5k/c4JvJjVc6JB+gxiqIU=
github.com/Sirupsen/logrus v1.0.6-0.20180315010703-90150a8ed11b/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/go-sql-driver/mysql v1.3.1-0.20180308100310-1a676ac6e4dc h1:WhgK0tta5yLnKy4x0XbxaxErBoUbEt2ckjRGZGiF7lo=
github.com/go-sql-driver/mysql v1.3.1-0.20180308100310-1a676ac6e4dc/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/labstack/echo v3.3.4+incompatible h1:83oKvzg2Fa6PN1pQfsUxlfR4MiSjsFzyxbEXKzsE0cQ=
github.com/labstack/echo v3.3.4+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
github.com/labstack/gommon v0.2.2-0.20180316174944-3bc2d333a4c3 h1:oaPp0U6xfzrmg9lGhEm1ZkBv6WqTiHkgTPuYM7xhocU=
github.com/labstack/gommon v0.2.2-0.20180316174944-3bc2d333a4c3/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o=
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rubenv/sql-migrate v0.0.0-20180217203553-081fe17d19ff h1:YUL11b9J/H3zmbITsv3RgJfH8H/AniHFZGKVkpcctSE=
github.com/rubenv/sql-migrate v0.0.0-20180217203553-081fe17d19ff/go.mod h1:WS0rl9eEliYI8DPnr3TOwz4439pay+qNgzJoVya/DmY=
github.com/satori/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5 h1:Jw7W4WMfQDxsXvfeFSaS2cHlY7bAF4MGrgnbd0+Uo78=
github.com/satori/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/stretchr/testify v1.2.2-0.20180319223459-c679ae2cc0cb h1:nt7YdN09XZcT7sloqA3JXOxGaxxErL1UMzBKFUlcIxc=
github.com/stretchr/testify v1.2.2-0.20180319223459-c679ae2cc0cb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v1.20.1-0.20180226030253-8e01ec4cd3e2 h1:xAkHCttGHKXIr10OSiFzNt0XOJyHMdng0ylSynT8sMo=
github.com/urfave/cli v1.20.1-0.20180226030253-8e01ec4cd3e2/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8=
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw=
github.com/vsco/slackhook v0.0.0-20160714202444-761b10b6951a h1:Xqrs5xZFoptIvK7+2ValIRLPeix+jtwVI+ZtkJmaA7c=
github.com/vsco/slackhook v0.0.0-20160714202444-761b10b6951a/go.mod h1:HD2kLOOrTKibW4TAOjL8suQjovHJmLeSvpfgSx2h3+U=
golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4 h1:AJCW0rhPjFKEAoValWpqnRKxX8YV0Xvqfw+dOexCTPc=
golang.org/x/crypto v0.0.0-20180322175230-88942b9c40a4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20180322165403-91ee8cde4354 h1:m30AMpZnWY037UcT8SaLDzIVJADUqWyNfqLKjrfyoRg=
golang.org/x/sys v0.0.0-20180322165403-91ee8cde4354/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
google.golang.org/appengine v1.0.1-0.20171212223047-5bee14b453b4/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/gorp.v1 v1.7.1 h1:GBB9KrWRATQZh95HJyVGUZrWwOPswitEYEyqlK8JbAA=
gopkg.in/gorp.v1 v1.7.1/go.mod h1:Wo3h+DBQZIxATwftsglhdD/62zRFPhGhTiu5jUJmCaw=
gopkg.in/tylerb/graceful.v1 v1.2.15 h1:1JmOyhKqAyX3BgTXMI84LwT6FOJ4tP2N9e2kwTCM0nQ=
gopkg.in/tylerb/graceful.v1 v1.2.15/go.mod h1:yBhekWvR20ACXVObSSdD3u6S9DeSylanL2PAbAC/uJ8=
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
},
cli.StringFlag{
Name: "mysql-host",
Value: "localhost",
Value: "db",
Usage: "MySQL host",
EnvVar: "LAIKA_MYSQL_HOST",
},
Expand Down
7 changes: 1 addition & 6 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ set -o errexit
set -o nounset
set -o pipefail

if ! which rerun > /dev/null 2>&1 ; then
go get github.com/ivpusic/rerun
fi

(cd dashboard && yarn run watch) &
rerun -a run -i dashboard,node_modules,bin,public,vendor,.git
docker-compose up
7 changes: 2 additions & 5 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail

if ! which glide > /dev/null 2>&1 ; then
go get github.com/Masterminds/glide
fi

glide install
go mod download
(cd dashboard && sudo apt install curl && curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - && sudo apt-get install -y nodejs && sudo apt-get install -y npm && sudo npm install)

2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -o errexit
set -o nounset
set -o pipefail

go vet $(go list ./... | grep -v vendor)
go vet
10 changes: 1 addition & 9 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,4 @@ set -o errexit
set -o nounset
set -o pipefail

echo "mode: set" > combined_coverage.out

for d in $(go list ./... | grep -v vendor); do
go test -v -cover -coverprofile=coverage.out $d
if [ -f coverage.out ]; then
cat coverage.out | grep -h -v "^mode:" >> combined_coverage.out
rm coverage.out
fi
done
docker-compose run laika go test -v ./... -cover -coverprofile=combined_coverage.out
4 changes: 2 additions & 2 deletions store/mysql_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestMySQLStore(t *testing.T) {

port := getenv("LAIKA_TEST_MYSQL_PORT", "3306")
username := getenv("LAIKA_TEST_MYSQL_USERNAME", "root")
password := getenv("LAIKA_TEST_MYSQL_PASSWORD", "")
database := getenv("LAIKA_TEST_MYSQL_DBNAME", "test")
password := getenv("LAIKA_TEST_MYSQL_PASSWORD", "root")
database := getenv("LAIKA_TEST_MYSQL_DBNAME", "laika")

store, err := NewMySQLStore(username, password, host, port, database)
require.NoError(t, err)
Expand Down

0 comments on commit 226de5b

Please sign in to comment.