Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerise for '21 #346

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
frontend
bots
public
docker-compose.yml
Dockerfile
*.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ protoc-3.2.0rc2-linux-x86_64.zip*
protobuf/

tls_keys/prod/*
!tls_keys/docker

# config.json contains database credentials
config.json
mocks/
sendgrid.env
sendgrid.env

dumps
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.10
FROM golang:1.13

RUN apt-get update && \
apt-get install -y apt-utils \
Expand All @@ -8,7 +8,16 @@ RUN apt-get update && \
curl \
netcat

WORKDIR /go/src/github.com/delta/dalal-street-server
ENV PATH $PATH:/root/protobuf/bin

RUN mkdir -p /go/src/github.com/delta/dalal-street-server

WORKDIR /go/src/github.com/delta/dalal-street-server

RUN mkdir logs

COPY . .

RUN bash docker-build.sh

CMD ["./docker-entry.sh"]
14 changes: 0 additions & 14 deletions build-server-img.sh

This file was deleted.

5 changes: 4 additions & 1 deletion config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"EventId": "19",
"EventSecret": "5881add25851d3051e96a6b0be4bcaf1",

"LogFileName": "./dalalstreet_docker.log",
"LogFileName": "./logs/dalalstreet_docker.log",
"LogMaxSize": 50,
"LogLevel": "info",

Expand All @@ -56,6 +56,9 @@
"CacheSize": 1000,
"BotSecret":"hellobots",
"SendgridKey":"",
"PushNotificationVAPIDPublicKey": "",
"PushNotificationVAPIDPrivateKey": "",
"PushNotificationEmail": "mailto:[email protected]",
"PlivoAuthId": "",
"PlivoAuthToken": "",
"MaxOTPRequestCount":100,
Expand Down
21 changes: 21 additions & 0 deletions docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x
#tail -f /dev/null

wget --tries=3 https://github.com/google/protobuf/releases/download/v3.2.0rc2/protoc-3.2.0rc2-linux-x86_64.zip -O protoc-3.2.0rc2-linux-x86_64.zip

echo "######## Unzipping protoc compiler ##########"
unzip protoc-3.2.0rc2-linux-x86_64.zip -d /root/protobuf

echo "######## Fetching Go dependencies ##########"
cd ../
go get -v github.com/gemnasium/migrate
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
cd $GOPATH/src/github.com/golang/protobuf/protoc-gen-go/
git reset --hard ed6926b37a637426117ccab59282c3839528a700
go install github.com/golang/protobuf/protoc-gen-go
cd $GOPATH/src/github.com/delta/dalal-street-server/
go get

git submodule update --init --recursive
56 changes: 30 additions & 26 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
version: '2'
version: "2"
services:
web:
container_name: dalalstreet_web_1
image: nginx:latest
build:
container_name: dalalstreet_frontend
restart: always
build:
context: ./frontend
volumes:
volumes:
- ./frontend/conf:/etc/nginx/conf.d
- ./frontend:/var/www/dalalstreet
ports:
- "80:80"
- "443:443"

- "8080:80"
dalalserver:
container_name: dalalstreet_server_1
container_name: dalalstreet_backend
build: .
volumes:
- $GOPATH:/go
- ./:/go/src/github.com/delta/dalal-street-server
restart: always
volumes:
- ./docker/logs:/go/src/github.com/delta/dalal-street-server/logs
# - ${GOPATH}:/go
# - ./:/go/src/github.com/delta/dalal-street-server
- ./frontend:/go/src/github.com/delta/dalal-street-server/frontend
ports:
- "8000:8000"
depends_on:
Expand All @@ -29,34 +30,37 @@ services:
DALAL_ENV: Docker

db:
container_name: dalalstreet_db_1
container_name: dalalstreet_db
image: mysql:5.7
restart: always
volumes:
- ./docker/mysql:/var/lib/mysql
env_file:
- .env
ports:
- "3306:3306"
- "3307:3306"
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_ROOT_PASSWORD: ${DB_PASS}

phpmyadmin:
container_name: dalalstreet_pma_1
container_name: dalalstreet_pma
image: phpmyadmin/phpmyadmin
restart: always
env_file:
- .env
ports:
- "9040:80"
depends_on:
- db
bots:
container_name: dalalstreet_bots_1
build:
context: ./bots
volumes:
- ./bots/dalalstreetbots:/var/www/dalalstreet/bots
ports:
- "7050:5000"
depends_on:
- dalalserver
# dalal_bots:
# container_name: dalalstreet_bots
# restart: always
# build:
# context: ./bots
# volumes:
# - ./bots/dalalstreetbots:/var/www/dalalstreet/bots
# ports:
# - "7050:5000"
# depends_on:
# - dalalserver
29 changes: 2 additions & 27 deletions docker-entry.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
#!/bin/sh

set -x

#tail -f /dev/null


wget --tries=3 https://github.com/google/protobuf/releases/download/v3.2.0rc2/protoc-3.2.0rc2-linux-x86_64.zip -O protoc-3.2.0rc2-linux-x86_64.zip

echo "######## Unzipping protoc compiler ##########"
unzip protoc-3.2.0rc2-linux-x86_64.zip -d /root/protobuf

echo "######## Fetching Go dependencies ##########"
go get -v github.com/golang/protobuf/proto
go get -v github.com/golang/protobuf/protoc-gen-go
go get -v golang.org/x/net/context
go get -v google.golang.org/grpc
go get -v github.com/gemnasium/migrate
go get -v github.com/sendgrid/sendgrid-go



echo "######## Adding to path ##########"
export PATH=$PATH:/root/protobuf/bin



# Run the migrations
echo "########## Building proto files ###########"
bash build_proto.sh
Expand All @@ -49,7 +24,7 @@ while [ $maxtry -gt 0 ]; do
done

echo "######### Running migrations ##########"
migrate -url "mysql://root:$dbPass@tcp(db:3306)/dalalstreet_docker" -path ./migrations up
migrate -url "mysql://root:$dbPass@tcp(db)/dalalstreet_docker" -path ./migrations up

echo "################## Starting server ##################"
go run main.go
go run main.go
33 changes: 0 additions & 33 deletions docker-web-entry.sh

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ require (
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/text v0.3.5 // indirect
google.golang.org/grpc v1.34.1
google.golang.org/protobuf v1.25.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd h1:GGJVjV8waZKRHrgwvtH66z
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
Expand All @@ -144,6 +145,7 @@ golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3Xzgoqa
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
6 changes: 4 additions & 2 deletions grpcapi/grpcapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"
"net/http"
"strings"
"time"

"github.com/sirupsen/logrus"
"golang.org/x/net/context"
Expand Down Expand Up @@ -192,7 +193,7 @@ func Init(conf *utils.Config, matchingEngine matchingengine.MatchingEngine, dsm
creds, err := credentials.NewServerTLSFromFile(config.TLSCert, config.TLSKey)
if err != nil {
log.Fatalf("Failed while obtaining TLS certificates. Error: %+v", err)
}
}

grpcServer = grpc.NewServer(
grpc.Creds(creds),
Expand Down Expand Up @@ -220,7 +221,8 @@ func Init(conf *utils.Config, matchingEngine matchingengine.MatchingEngine, dsm
// Checks the request type and calls the appropriate handler
func GrpcHandlerFunc(resp http.ResponseWriter, req *http.Request) {
if wrappedServer.IsGrpcWebRequest(req) {
log.Printf("Got grpc web request")
now := time.Now()
log.Printf("Got grpc web request at %s",now)
wrappedServer.ServeHTTP(resp, req)
} else {
grpcServer.ServeHTTP(resp, req)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func RealMain() {
},
),
}

models.InspectComponents()
utils.Logger.Fatal(httpServer.ListenAndServeTLS(config.TLSCert, config.TLSKey))
}
Expand Down
8 changes: 8 additions & 0 deletions sql_create_dump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if [[ $(docker ps --filter status=running |grep dalalstreet_db) ]]
then
mkdir -p dumps
time=$(date +%d-%m-%Y-%H-%M-%S)
docker exec dalalstreet_db /usr/bin/mysqldump -u root --password=root dalalstreet_docker > ./dumps/dump-$time.sql
fi
1 change: 1 addition & 0 deletions sql_restore_dump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cat /home/deathblade/go/src/github.com/delta/dalal-street-server/dumps/dump-11-03-2021-21-03-07.sql | docker exec -i dalalstreet_db /usr/bin/mysql -u root --password=root dalalstreet_docker
22 changes: 22 additions & 0 deletions tls_keys/docker/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDjzCCAnegAwIBAgIJAON0T+GsNoM0MA0GCSqGSIb3DQEBCwUAMF4xCzAJBgNV
BAYTAklOMQ8wDQYDVQQHDAZUcmljaHkxDjAMBgNVBAoMBURlbHRhMRowGAYDVQQL
DBFEYWxhbCBTdHJlZXQgVGVhbTESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTE3MTIy
NjIwMzIwNVoXDTI3MTIyNDIwMzIwNVowXjELMAkGA1UEBhMCSU4xDzANBgNVBAcM
BlRyaWNoeTEOMAwGA1UECgwFRGVsdGExGjAYBgNVBAsMEURhbGFsIFN0cmVldCBU
ZWFtMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQCyfpFvDTbonf0U5dwhEQ2yCMvj6gFyq7gEYD0Ch9S2WcO9zo70uVBI
zvKc+gJ4/OHzmlEP33+x2Q9LC9H6pTwWO+ZltM6/u7z7IuI3BAv2O5a7KqAh0B16
nEv6C+47S9eATUgbtalNpbpCEqBJB/zr+vfoAv4k76G840wHA3NJYyGRJ/sfOrPs
ks8TnMCpUIn2HKAaihXBDjx91HCKdkf1RIqBGADN1s6Q75xJq+VjO39BEKs1Wh+C
cg3l8rQ9FotKlVYnfgfpEL5qouY9BgneXsb+ixMBkSCoZlaiJpaEYUZQ9CjbIECy
KL34JEDkNQlGFHI4dnxs8RJtBcVVaYs9AgMBAAGjUDBOMB0GA1UdDgQWBBS9CU6m
LHaqYFG9rvpl1aTwZyvnzzAfBgNVHSMEGDAWgBS9CU6mLHaqYFG9rvpl1aTwZyvn
zzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBp8GM4Ne4sPtDBb6QZ
IWO+fKQkFvSCvD0TXTUxU88QGWzOMyVlCskQo0P1/vjPIylRTVAJWC9J164PnKW2
U7RYgKFVGIfdQmkD6Ul2ip2XVJ7awoXjQO51nNp1uN9UzsHaIoswPe5KcJ/TOZ75
8BByY+l/L8EOXdk+DTq2kPS1mcv6a500Q9JTDAfAM6uUVnwiF4fWtfSUyyRpWl6s
xY01aSxRMQud7e8h/FDMPdTvcFpcnWUB2byRdw7gv5kIjfRsZZSwy/8zODZx/biR
n8lG/ZKeivbUai547FHqdI2qJwv2mElxojG2hLV7sImSg26fuaTyy5+ftP3GH8Yj
5+8T
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions tls_keys/docker/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAsn6Rbw026J39FOXcIRENsgjL4+oBcqu4BGA9AofUtlnDvc6O
9LlQSM7ynPoCePzh85pRD99/sdkPSwvR+qU8FjvmZbTOv7u8+yLiNwQL9juWuyqg
IdAdepxL+gvuO0vXgE1IG7WpTaW6QhKgSQf86/r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