Skip to content

Commit

Permalink
Make dockerfile for the build
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaskay committed Mar 30, 2021
1 parent ea81de1 commit 4fc95b3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build

21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ci/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 4fc95b3

Please sign in to comment.