Skip to content

Commit

Permalink
Merge pull request #5 from safe-distance/interaction_symmetry
Browse files Browse the repository at this point in the history
implemented symmetric interactions and split dev and prod envs
  • Loading branch information
mattbonnell authored May 21, 2020
2 parents 718623a + 21487ef commit 1f2b344
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ build-deps:
docker build -t ${GOOGLE_GCR_HOSTNAME}/${GOOGLE_PROJECT_ID}/deps:latest -f ./deps.Dockerfile .
start:
docker-compose run --rm start_dependencies
docker-compose up -d ${service}
docker-compose -f docker-compose.yml -f docker-compose.${env}.yml up -d ${service}
@echo "Service(s) up and running!"
@echo Jaeger tracing dashboard available at http://${DOCKERHOST}:16686
@echo Traefik load balancer dashboard available at http://${DOCKERHOST}:8080
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.7'
services:
reverse_proxy:
circle:
labels:
- "traefik.enable=true"
- "traefik.http.routers.circle_app.rule=PathPrefix(`/circle`)"
- "traefik.http.routers.circle_app.entrypoints=web"
proximity:
labels:
- "traefik.enable=true"
- "traefik.http.routers.proximity_app.rule=PathPrefix(`/proximity`)"
- "traefik.http.routers.proximity_app.entrypoints=web"
scoring:
labels:
- "traefik.enable=true"
- "traefik.http.routers.scoring_app.rule=PathPrefix(`/scores`)"
- "traefik.http.routers.scoring_app.entrypoints=web"
location:
labels:
- "traefik.enable=true"
- "traefik.http.routers.location_app.rule=PathPrefix(`/location`)"
- "traefik.http.routers.location_app.entrypoints=web"
49 changes: 49 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3.7'
services:
reverse_proxy:
# The official v2 Traefik docker image
image: traefik:v2.2
# Enables the web UI and tells Traefik to listen to docker
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.watch=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--accesslog=true"
# tracing
- "--tracing.jaeger=true"
- "--tracing.jaeger.samplingServerURL=http://jaeger:5778/sampling"
- "--tracing.jaeger.localAgentHostPort=jaeger:6831"
- "--tracing.jaeger.samplingType=const"
# TLS
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.storage=/secrets/letsencrypt/acme.json"
- "--certificatesresolvers.myresolver.acme.email=matt@axial.technology"
- "--certificatesresolvers.myersolver.acme.caServer=https://acme-v02.api.letsencrypt.org/directory"
circle:
labels:
- "traefik.enable=true"
- "traefik.http.routers.circle_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/circle`)"
- "traefik.http.routers.circle_app.entrypoints=websecure"
- "traefik.http.routers.circle_app.tls.certresolver=myresolver"
proximity:
labels:
- "traefik.enable=true"
- "traefik.http.routers.proximity_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/proximity`)"
- "traefik.http.routers.proximity_app.entrypoints=websecure"
- "traefik.http.routers.proximity_app.tls.certresolver=myresolver"
scoring:
labels:
- "traefik.enable=true"
- "traefik.http.routers.scoring_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/scores`)"
- "traefik.http.routers.scoring_app.entrypoints=websecure"
- "traefik.http.routers.scoring_app.tls.certresolver=myresolver"
location:
labels:
- "traefik.enable=true"
- "traefik.http.routers.location_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/location`)"
- "traefik.http.routers.location_app.entrypoints=websecure"
- "traefik.http.routers.location_app.tls.certresolver=myresolver"
28 changes: 1 addition & 27 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ services:
- "--tracing.jaeger.samplingServerURL=http://jaeger:5778/sampling"
- "--tracing.jaeger.localAgentHostPort=jaeger:6831"
- "--tracing.jaeger.samplingType=const"
# TLS
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
- "--certificatesresolvers.myresolver.acme.email=matt@axial.technology"
- "--certificatesresolvers.myersolver.acme.caServer=https://acme-v02.api.letsencrypt.org/directory"
ports:
# The HTTPS port
- "443:443"
Expand All @@ -48,7 +42,7 @@ services:
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "./secrets/letsencrypt:/secrets/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
# labels:
# - "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^(.*):80/traefik"
Expand Down Expand Up @@ -89,11 +83,6 @@ services:
- $PORT
secrets:
- google_application_credentials
labels:
- "traefik.enable=true"
- "traefik.http.routers.circle_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/circle`)"
- "traefik.http.routers.circle_app.entrypoints=websecure"
- "traefik.http.routers.circle_app.tls.certresolver=myresolver"
proximity:
image: ${GOOGLE_GCR_HOSTNAME}/${GOOGLE_PROJECT_ID}/proximity:latest
environment:
Expand All @@ -106,11 +95,6 @@ services:
- $PORT
secrets:
- google_application_credentials
labels:
- "traefik.enable=true"
- "traefik.http.routers.proximity_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/proximity`)"
- "traefik.http.routers.proximity_app.entrypoints=websecure"
- "traefik.http.routers.proximity_app.tls.certresolver=myresolver"
proximity_consumer:
image: ${GOOGLE_GCR_HOSTNAME}/${GOOGLE_PROJECT_ID}/proximity_consumer:latest
environment:
Expand All @@ -133,11 +117,6 @@ services:
- $PORT
secrets:
- google_application_credentials
labels:
- "traefik.enable=true"
- "traefik.http.routers.scoring_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/scores`)"
- "traefik.http.routers.scoring_app.entrypoints=websecure"
- "traefik.http.routers.scoring_app.tls.certresolver=myresolver"
scoring_consumer:
image: ${GOOGLE_GCR_HOSTNAME}/${GOOGLE_PROJECT_ID}/scoring_consumer:latest
environment:
Expand Down Expand Up @@ -165,11 +144,6 @@ services:
- $PORT
secrets:
- google_application_credentials
labels:
- "traefik.enable=true"
- "traefik.http.routers.location_app.rule=Host(`spatiumsocialis.com`) && PathPrefix(`/location`)"
- "traefik.http.routers.location_app.entrypoints=websecure"
- "traefik.http.routers.location_app.tls.certresolver=myresolver"
db:
image: postgres:latest
environment:
Expand Down
Empty file removed letsencrypt/acme.json
Empty file.
7 changes: 6 additions & 1 deletion proximity/pkg/handlers/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func AddInteraction(s *common.Service) http.Handler {
}
// Add the user's UID from the auth token to the interaction
interaction.UID = user.ID
interaction.OtherUID = otherUserUID
s.DB.Create(&interaction)
json.NewEncoder(w).Encode(&interaction)
fmt.Printf("created interaction: %+v\n", interaction)
Expand All @@ -62,7 +63,11 @@ func GetInteractions(s *common.Service) http.Handler {
}
// Find the user's interactions and write them to the response
interactions := make([]models.Interaction, 0)
s.DB.Find(&interactions, models.Interaction{UID: user.ID})
s.DB.Where(models.Interaction{UID: user.ID}).Or(models.Interaction{OtherUID: user.ID}).Find(&interactions)
// Set all interactions UID field to the current uid for the response so no one else's UID gets leaked
for i := 0; i < len(interactions); i++ {
interactions[i].UID = user.ID
}
json.NewEncoder(w).Encode(interactions)

})
Expand Down
2 changes: 2 additions & 0 deletions proximity/pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Interaction struct {
ID uint `gorm:"primary_key" json:"id"`
// Firebase UID of the user
UID string `json:"uid"`
// Firebase UID of the other user
OtherUID string `json:"-"`
// Average distance between the user and the other party in centimeters
Distance float32 `json:"distance"`
// Duration of the interaction in nanoseconds
Expand Down

0 comments on commit 1f2b344

Please sign in to comment.