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

[feat] added cicd and better env mgmt #107

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
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", "")
Loading