From 4fc95b384542f30b7f54d952bc14433588773460 Mon Sep 17 00:00:00 2001 From: Tadas Krivickas Date: Tue, 30 Mar 2021 12:28:58 +0300 Subject: [PATCH] Make dockerfile for the build --- .dockerignore | 2 ++ Dockerfile | 21 +++++++++++++++++++++ README.md | 16 +++++++++++++++- ci/local/local.go | 2 +- docker-compose.yml | 13 ++++++++++++- magefile.go | 12 ++++++------ 6 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9ef9604 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +build + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ef4043 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.16-alpine AS builder + +WORKDIR /go/src/github.com/mysteriumnetwork/ndiscovery +COPY go.mod go.sum ./ +RUN go mod download + +# Compile application +ADD . . +RUN go run mage.go -v build + +FROM alpine:3 + +# Install packages +RUN apk add --no-cache ca-certificates git + +# Install application +COPY --from=builder /go/src/github.com/mysteriumnetwork/ndiscovery/build/ndiscovery /usr/bin/ndiscovery + +EXPOSE 3000 + +CMD ["/usr/bin/discovery"] diff --git a/README.md b/README.md index 865ed6f..0547233 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,22 @@ mage build ``` +Or using docker: + +``` +docker build -t ndiscovery:local . +``` + ## Run ``` -mage local +mage up ``` + +Or using docker: + +``` +docker-compose up +``` + +API: http://localhost:3000/api/v3 diff --git a/ci/local/local.go b/ci/local/local.go index 4ffcca3..8c66d98 100644 --- a/ci/local/local.go +++ b/ci/local/local.go @@ -6,7 +6,7 @@ import ( "github.com/magefile/mage/sh" ) -func Local() { +func Up() { err := sh.RunV("docker-compose", "up", "-d", "db") if err != nil { return diff --git a/docker-compose.yml b/docker-compose.yml index caa3faf..c9d0909 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,18 @@ version: '3.1' services: + ndiscovery: + build: + context: . + ports: + - 3000:3000 + environment: + - PORT=3000 + - DB_HOST=db:6379 + - DB_PASSWORD= + - QUALITY_ORACLE_URL=https://testnet2-quality.mysterium.network + - BROKER_URL=nats://testnet2-broker.mysterium.network db: image: redis - container_name: 'discovery_cache' + container_name: 'discovery_db' ports: - 6379:6379 diff --git a/magefile.go b/magefile.go index 70299e5..faba5a5 100644 --- a/magefile.go +++ b/magefile.go @@ -9,17 +9,17 @@ import ( "github.com/mysteriumnetwork/discovery/ci/local" ) -// Build builds the project. +// Build builds the app binary. func Build() error { - return sh.Run("go", "build", "-o", path.Join("build", "discovery"), path.Join("cmd", "main.go")) + return sh.Run("go", "build", "-o", path.Join("build", "ndiscovery"), path.Join("cmd", "main.go")) } -// Run runs the project. +// Run runs the app (without the DB). func Run() error { return sh.RunV("go", "run", "./cmd/main.go") } -// Local runs local discovery stack. -func Local() { - local.Local() +// Up runs the discovery stack (app and DB) locally. +func Up() { + local.Up() }