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

Commit

Permalink
🚀 Created dockerfile for golang api, dockerfile for mysql db and dock…
Browse files Browse the repository at this point in the history
…er-compose.
  • Loading branch information
RiccardoBiosas committed Jul 9, 2020
1 parent e34d8d3 commit c52ba0c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.12

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build

RUN go build -o main .

EXPOSE 8080

CMD ["./main"]
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"log"
"net/http"
"os"
"strings"

helpers "github.com/RiccardoBiosas/golang-ethereum-auth/helpers"
Expand All @@ -30,7 +29,8 @@ func (a *Api) Mount() {
fmt.Println("error loading .env file")
}
var err error
a.DB, err = sql.Open("mysql", os.Getenv("DB_AUTH"))
// a.DB, err = sql.Open("mysql", os.Getenv("DB_AUTH"))
a.DB, err = sql.Open("mysql", "docker:docker@tcp(db:3306)/golang_ethereum_auth")
if err != nil {
log.Fatal(err)
}
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'
services:
db:
build:
context: ./mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: golang_ethereum_auth
MYSQL_USER: docker
MYSQL_PASSWORD: docker
container_name: golang_db
ports:
- '3306:3306'
tty: true
api:
build: .
volumes:
- '.:/go'
container_name: golang_api
ports:
- '8080:8080'
tty: true
depends_on:
- db
2 changes: 2 additions & 0 deletions mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM mysql:5.6
COPY test.sql /docker-entrypoint-initdb.d/golang_ethereum_auth.sql
7 changes: 7 additions & 0 deletions mysql/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
USE golang_ethereum_auth;

Create table `users` (
id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
public_key VARCHAR(42) UNIQUE NOT NULL,
nonce varchar(38) NOT NULL
);

0 comments on commit c52ba0c

Please sign in to comment.