Skip to content

Commit

Permalink
Merge pull request #107 from asetalias/feat/cicd
Browse files Browse the repository at this point in the history
[feat] added cicd and better env mgmt
  • Loading branch information
achintya-7 authored Dec 21, 2023
2 parents f1277e5 + ef4dd46 commit 83cfa06
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/fly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Fly Deploy
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
9 changes: 0 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ def main():

logger = AmibotLogger("AmiBot")


# Sentry, skip for dev mode
if not DEV_MODE and not SENTRY_DSN == "":
logger.info("Starting sentry...")
sentry_sdk.init(
dsn=SENTRY_DSN,
traces_sample_rate=1.0,
)

# Set token according to dev mode
if DEV_MODE == "True":
logger.debug("Running in dev mode...")
Expand Down
31 changes: 17 additions & 14 deletions server/utils/config.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
package utils

import (
"fmt"
"os"

"github.com/fernet/fernet-go"
"github.com/spf13/viper"
)

type Config struct {
MongoUri string `mapstructure:"MONGO_URI"`
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
GrpcAddress string `mapstructure:"GRPC_ADDRESS"`
Key string `mapstructure:"KEY"`
FernetKey []*fernet.Key `mapstructure:"FERNET_KEY"`
MongoUri string `mapstructure:"MONGO_URI"`
Key string `mapstructure:"KEY"`
FernetKey []*fernet.Key `mapstructure:"FERNET_KEY"`
}

func LoadConfig(path string) (config Config, err error) {
viper.AddConfigPath(path)
viper.SetConfigName("app")
viper.AutomaticEnv()

err = viper.ReadInConfig()
config.MongoUri, err = getEnvVar("MONGO_URI")
if err != nil {
return
}

err = viper.Unmarshal(&config)
config.Key, err = getEnvVar("KEY")
if err != nil {
return
}

config.GrpcAddress = "amizone.fly.dev:443"

config.FernetKey = fernet.MustDecodeKeys(config.Key)

return
}

func getEnvVar(key string) (string, error) {
value := os.Getenv(key)
if value == "" {
return "", fmt.Errorf("%s environment variable not set", key)
}
return value, nil
}
5 changes: 1 addition & 4 deletions util/env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import os
from dotenv import load_dotenv

load_dotenv("app.env")

MONGO_URI = os.environ.get("MONGO_URI", "mongodb://localhost:27017/")
MONGO_DATABASE = os.environ.get("MONGO_DATABASE", "users")
Expand All @@ -10,5 +7,5 @@
SENTRY_DSN = os.environ.get("SENTRY_DSN", "")
URL = "amizone.fly.dev:443"
MONGO_COLLECTION = "profile"
DEV_MODE = os.environ.get("DEV_MODE", False)
DEV_MODE = os.environ.get("DEV_MODE", "False")
TEST_TOKEN = os.environ.get("TEST_TOKEN", "")

0 comments on commit 83cfa06

Please sign in to comment.