Skip to content

Commit

Permalink
Merge pull request #60 from CAS735-F23/deploy
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
samkithkjain authored Dec 5, 2023
2 parents 9b454cb + 551d088 commit a445c2e
Show file tree
Hide file tree
Showing 40 changed files with 552 additions and 752 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use the official Go image as a parent image
FROM golang:1.21.3-bookworm

# Set the working directory in the container
WORKDIR /app

# Install necessary packages and tools
RUN apt-get update && apt-get install -y \
wget \
curl \
gnupg \
software-properties-common

# Copy the local code to the container's workspace
COPY . /app

# Install Go dependencies (if applicable)
RUN go mod download

# Run the application
CMD ./run_tests.sh


2 changes: 1 addition & 1 deletion challenge/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ RUN go get -d -v ./...

RUN go build -o challenge ./cmd

CMD ["sh", "-c", "./run_tests.sh && ./challenge"]
CMD ["./challenge"]
2 changes: 1 addition & 1 deletion challenge/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
logger.Info("challenge manager is starting...")

// Initialize router
router := gin.Default()
router := gin.New()
router.Use(gin.Recovery())

// Initialize postgres repository
Expand Down
2 changes: 1 addition & 1 deletion challenge/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
Port: getEnv("RABBITMQ_PORT", "5672"),
User: getEnv("RABBITMQ_USER", "guest"),
Password: getEnv("RABBITMQ_PASSWORD", "guest"),
WorkoutStatsConsumer: getEnv("RABBITMQ_WORKOUT_STATS_CONSUMER", "WORKOUT_STATS_QUEUE"),
WorkoutStatsConsumer: getEnv("RABBITMQ_WORKOUT_STATS_CONSUMER", "stats_workout_challenge_queue"),
}

Config = &AppConfiguration{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewWorkoutStatsConsumer(cfg *config.RabbitMQ, challengeSvc *services.Challe

amqpConn, err := amqp.Dial(conn)
if err != nil {
logger.Fatal("unable to dial connection to RabbitMQ")
logger.Fatal("unable to dial connection to RabbitMQ", zap.Error(err), zap.String("conn", conn))
}

return &WorkoutStatsConsumer{
Expand Down
2 changes: 1 addition & 1 deletion challenge/internal/core/services/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ This is a function to monitor active challenges and create badges
- Note: This should be handled by a cron job. When a challenge ends, the badges should be dispatched.
*/
func (svc *ChallengeService) MonitorChallenges() {
ticker := time.NewTicker(10 * time.Second)
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()

for range ticker.C {
Expand Down
4 changes: 2 additions & 2 deletions challenge/internal/core/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestChallengeService_CreateOrUpdateChallengeStats(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.test, func(t *testing.T) {
// 2.1 Create a Challenge
ch, err := domain.NewChallenge(tc.challenge.name+uuid.NewString(), tc.challenge.desc, tc.challenge.badgeURL, domain.Criteria(tc.challenge.criteria), tc.challenge.goal, time.Now(), time.Now().Add(time.Second*30))
ch, err := domain.NewChallenge(tc.challenge.name+uuid.NewString(), tc.challenge.desc, tc.challenge.badgeURL, domain.Criteria(tc.challenge.criteria), tc.challenge.goal, time.Now(), time.Now().Add(time.Millisecond*1500))
if err != nil {
t.Errorf("unable to initialize challenge, got %v", err)
}
Expand All @@ -73,7 +73,7 @@ func TestChallengeService_CreateOrUpdateChallengeStats(t *testing.T) {
}
}
// added a delay for the challenge to end
time.Sleep(40 * time.Second)
time.Sleep(2000 * time.Millisecond)

// 2.3 Check for Badges
badges, err := service.ListBadgesByPlayerID(tc.playerID)
Expand Down
5 changes: 3 additions & 2 deletions challenge/log/logger.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package logger

import (
"github.com/CAS735-F23/macrun-teamvsl/workout/config"
"github.com/CAS735-F23/macrun-teamvsl/challenge/config"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand All @@ -20,6 +20,7 @@ func init() {
config.EncoderConfig.TimeKey = "timestamp"
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
config.Level.SetLevel(zap.InfoLevel)
config.DisableCaller = true
zapLog, err = config.Build()

// production grade logger
Expand All @@ -35,7 +36,7 @@ func init() {
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
config.EncoderConfig.TimeKey = "timestamp"
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
zapLog, err = config.Build()
zapLog, err = config.Build(zap.AddCallerSkip(1))
}

if err != nil {
Expand Down
12 changes: 0 additions & 12 deletions challenge/run_tests.sh

This file was deleted.

178 changes: 178 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
version: "3.8"

services:
# RabbitMQ
rabbitmq:
container_name: rabbitmq
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"
healthcheck:
test: rabbitmq-diagnostics check_port_connectivity
interval: 5s
timeout: 5s
retries: 3

# Database
db:
container_name: db
image: postgres:latest
restart: always
environment:
- POSTGRES_DB=postgres
- POSTGRES_PORT=5432
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_ENCODING=UTF8
healthcheck:
test: pg_isready -U postgres
interval: 5s
timeout: 10s
retries: 3

# User Manager
user:
container_name: user
build: ../user
restart: always
ports:
- "8010:8010"
environment:
- MODE=prod
- PORT=8010
- GIN_MODE=release
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_ENCODING=UTF8
- POSTGRES_LOG_LEVEL=silent
depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy


# Zone Manager
zone:
container_name: zone
build: ../zone
restart: always
ports:
- "8011:8011"
environment:
- MODE=prod
- PORT=8011
- GIN_MODE=release
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_ENCODING=UTF8
- POSTGRES_LOG_LEVEL=silent
- RABBITMQ_HOSTNAME=rabbitmq
- RABBITMQ_PORT=5672
- RABBITMQ_USER=guest
- RABBITMQ_PASSWORD=guest
- RABBIT_LOCATION_CONSUMER=location_peripheral_zone_queue
- RABBITMQ_SHELTER_DISTANCE_PUBLISHER=shelter_zone_workout_queue

depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy

# Peripheral Service
peripheral:
container_name: peripheral
build: ../peripheral
restart: always
ports:
- "8012:8012"
environment:
- MODE=prod
- PORT=8012
- GIN_MODE=release
- RABBITMQ_HOSTNAME=rabbitmq
- RABBITMQ_PORT=5672
- RABBITMQ_USER=guest
- RABBITMQ_PASSWORD=guest
- RABBIT_WORKOUT_LOCATION_PUBLISHER=location_peripheral_workout_queue
- RABBITMQ_ZONE_LOCATION_PUBLISHER=location_peripheral_zone_queue
- ZONE_CLIENT_URL=http://zone:8011
depends_on:
rabbitmq:
condition: service_healthy


# Workout Manager
workout:
container_name: workout
build: ../workout
restart: always
ports:
- "8013:8013"
environment:
- MODE=prod
- PORT=8013
- GIN_MODE=release
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_ENCODING=UTF8
- POSTGRES_LOG_LEVEL=silent
- RABBITMQ_HOSTNAME=rabbitmq
- RABBITMQ_PORT=5672
- RABBITMQ_USER=guest
- RABBITMQ_PASSWORD=guest
- RABBITMQ_SHELTER_DISTANCE_CONSUMER=shelter_zone_workout_queue
- RABBITMQ_LOCATION_CONSUMER=location_peripheral_workout_queue
- RABBITMQ_WORKOUT_STATS_PUBLISHER=stats_workout_challenge_queue
- USER_CLIENT_URL=http://user:8010
- PERIPHERAL_CLIENT_URL=http://peripheral:8012
depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy
peripheral:
condition: service_started
user:
condition: service_started


# Challenge Manager
challenge:
container_name: challenge
build: ../challenge
restart: always
ports:
- "8014:8014"
environment:
- MODE=prod
- PORT=8014
- GIN_MODE=release
- POSTGRES_HOST=db
- POSTGRES_PORT=5432
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_ENCODING=UTF8
- POSTGRES_LOG_LEVEL=silent
- RABBITMQ_HOSTNAME=rabbitmq
- RABBITMQ_PORT=5672
- RABBITMQ_USER=guest
- RABBITMQ_PASSWORD=guest
- RABBITMQ_WORKOUT_STATS_CONSUMER=stats_workout_challenge_queue
depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy
Loading

0 comments on commit a445c2e

Please sign in to comment.