Re-arrange docker-compose files

This commit is contained in:
Andrea Fazzi 2020-01-31 10:50:28 +01:00
parent 2254c30366
commit 2a4b2aaa31
14 changed files with 523 additions and 20 deletions

View file

@ -1,14 +1,21 @@
PHONY: all PHONY: all
dockerized: prod:
docker-compose -f compose/docker-compose.yml down docker-compose -f docker/oef_prod/docker-compose.yml down
docker-compose -f compose/docker-compose.yml up --build -d docker-compose -f docker/oef_prod/docker-compose.yml up --build -d
dev: dev:
killall main || echo "Process was not running." killall main || echo "Process was not running."
docker-compose -f compose/docker-compose_outside_docker.yml down docker-compose -f docker/oef_dev/docker-compose.yaml down
docker-compose -f compose/docker-compose_outside_docker.yml up -d db docker-compose -f docker/oef_dev/docker-compose.yaml up -d db
docker-compose -f compose/docker-compose_outside_docker.yml up -d smtp docker-compose -f docker/oef_dev/docker-compose.yaml up -d smtp
go run -race main.go --config=config/config_dev.yaml & go run -race main.go --config=docker/oef_dev/config/config.yaml &
all: dockerized test:
killall main || echo "Process was not running."
docker-compose -f docker/oef_test/docker-compose.yaml down
docker-compose -f docker/oef_test/docker-compose.yaml up -d db
docker-compose -f docker/oef_test/docker-compose.yaml up -d smtp
go run -race main.go --config=docker/oef_test/config/config.yaml &
all: prod

View file

@ -16,24 +16,30 @@ import (
"github.com/gocarina/gocsv" "github.com/gocarina/gocsv"
) )
type genFunc func(string) error type config struct {
Url string
}
type genFunc func(string, *config) error
var ( var (
generators map[string]genFunc generators map[string]genFunc
templateDir string = "./templates" templateDir string = "./templates"
url string = "https://test.olimpiadi-economiaefinanza.it"
) )
func incr(value int) int { func incr(value int) int {
return value + 1 return value + 1
} }
func genResponseTargets(targetName string) error { func genResponseTargets(targetName string, conf *config) error {
var data struct { var data struct {
Participants []*orm.Participant Participants []*orm.Participant
Tokens map[string]string Tokens map[string]string
Config *config
} }
data.Config = conf
log.Println("Read participants.csv...") log.Println("Read participants.csv...")
input, err := ioutil.ReadFile("./testdata/participants.csv") input, err := ioutil.ReadFile("./testdata/participants.csv")
@ -47,7 +53,7 @@ func genResponseTargets(targetName string) error {
log.Println("Obtaining tokens for each participants...") log.Println("Obtaining tokens for each participants...")
data.Tokens = make(map[string]string, 0) data.Tokens = make(map[string]string, 0)
for _, participant := range data.Participants { for _, participant := range data.Participants {
token, err := client.GetToken(url, participant.FiscalCode, participant.Password) token, err := client.GetToken(data.Config.Url, participant.FiscalCode, participant.Password)
if err != nil { if err != nil {
return err return err
} }
@ -89,7 +95,8 @@ func init() {
} }
func main() { func main() {
target := flag.String("target", "responses", "Generate targets for various API endpoints.") target := flag.String("target", "responses", "Generate targets for participants responses.")
url := flag.String("url", "http://localhost:3000", "The URL of the host.")
flag.Parse() flag.Parse()
fn, ok := generators[*target] fn, ok := generators[*target]
@ -97,7 +104,7 @@ func main() {
log.Fatal(errors.New("Unknown target")) log.Fatal(errors.New("Unknown target"))
} }
err := fn(*target) err := fn(*target, &config{Url: *url})
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -1,4 +1,4 @@
{{range $id, $participant := .Participants -}} {{range $id, $participant := .Participants -}}
{{- $username := $participant.FiscalCode -}} {{- $username := $participant.FiscalCode -}}
GET https://test.olimpiadi-economiaefinanza.it/responses/{{$id|incr}}/update?format=html&tpl_content=responses_add_update&tpl_layout=base&update=true&login_session={{index $.Tokens $username}} GET {{$.Config.Url}}/responses/{{$id|incr}}/update?format=html&tpl_content=responses_add_update&tpl_layout=base&update=true&login_session={{index $.Tokens $username}}
{{end}} {{end}}

View file

@ -0,0 +1,31 @@
url: "http://localhost:3000"
log_level: 2
language: "it"
keys:
cookie_store_key: "something-very-secret"
jwt_signing_key: "secret"
handlers:
allow_session_url_query: true
orm:
connection: "oef:oef@tcp(localhost:3307)/oef_dev"
options: "charset=utf8&parseTime=True&loc=Local"
automigrate: true
regenerate: false
admin:
username: "admin"
password: "admin"
subscriber:
password: "subscribe"
smtp:
host: "localhost"
port: 1025
username: ""
password: ""
from: "no-reply@olimpiadi-economiaefinanza.it"
bcc: "bcc@fake.org"

View file

@ -3,7 +3,7 @@ version: "3.3"
services: services:
app: app:
build: ../ build: ../../
ports: ports:
- 3000:3000 - 3000:3000
environment: environment:
@ -19,7 +19,6 @@ services:
restart: always restart: always
volumes: volumes:
- db:/var/lib/mysql - db:/var/lib/mysql
# - ./sql:/docker-entrypoint-initdb.d
env_file: env_file:
- db.env - db.env
ports: ports:

View file

@ -0,0 +1,17 @@
url: "http://localhost:3000"
log_level: 2
language: "it"
keys:
cookie_store_key: "something-very-secret"
jwt_signing_key: "secret"
orm:
connection: "oef:oef@tcp(db:3306)/oef_dev"
options: "charset=utf8&parseTime=True&loc=Local"
automigrate: true
regenerate: false
admin:
username: "admin"
password: "admin"

10
docker/oef_prod/db.env Normal file
View file

@ -0,0 +1,10 @@
MYSQL_ROOT_PASSWORD=oef
MYSQL_PASSWORD=oef
MYSQL_DATABASE=oef_prod
MYSQL_USER=oef

View file

@ -3,7 +3,7 @@ version: "3.3"
services: services:
app: app:
build: ../ build: ../../
ports: ports:
- 3000:3000 - 3000:3000
environment: environment:
@ -11,7 +11,7 @@ services:
- DB_PORT=3306 - DB_PORT=3306
volumes: volumes:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
- ../config/config.yaml:/src/oef/config/config.yaml - ./config/config.yaml:/src/oef/config/config.yaml
db: db:
image: mariadb image: mariadb

View file

@ -0,0 +1,31 @@
url: "http://localhost:3000"
log_level: 2
language: "it"
keys:
cookie_store_key: "something-very-secret"
jwt_signing_key: "secret"
handlers:
allow_session_url_query: true
orm:
connection: "oef:oef@tcp(localhost:3307)/oef_test"
options: "charset=utf8&parseTime=True&loc=Local"
automigrate: true
regenerate: false
admin:
username: "admin"
password: "admin"
subscriber:
password: "subscribe"
smtp:
host: "localhost"
port: 1025
username: ""
password: ""
from: "no-reply@olimpiadi-economiaefinanza.it"
bcc: "bcc@fake.org"

10
docker/oef_test/db.env Normal file
View file

@ -0,0 +1,10 @@
MYSQL_ROOT_PASSWORD=oef
MYSQL_PASSWORD=oef
MYSQL_DATABASE=oef_test
MYSQL_USER=oef

View file

@ -0,0 +1,37 @@
version: "3.3"
services:
app:
build: ../../
ports:
- 3000:3000
environment:
- DB_HOST=db
- DB_PORT=3306
volumes:
- /etc/localtime:/etc/localtime:ro
- ./config/config.yaml:/src/oef/config/config.yaml
db:
image: mariadb
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- db:/var/lib/mysql
- ./sql:/docker-entrypoint-initdb.d
env_file:
- db.env
ports:
- 3307:3306
smtp:
image: digiplant/fake-smtp
ports:
- "1025:25"
volumes:
db:

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
echo "Executing Makefile... $1" echo "Executing Makefile... $1"
make -k $1 make -k $1