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: deployment additions #1036

Merged
merged 33 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4044f79
setup script
michael-brennan2005 Jun 11, 2024
4e33324
caddy and more compose
michael-brennan2005 Jun 11, 2024
3825678
change to .env.prod
michael-brennan2005 Jun 11, 2024
1bebe61
compose debugging I
michael-brennan2005 Jun 11, 2024
29f6c6f
fix dockerfile
michael-brennan2005 Jun 11, 2024
09af951
Merge branch 'main' into prod-business
michael-brennan2005 Jun 11, 2024
0f05208
Fix dockerfile
michael-brennan2005 Jun 11, 2024
a5a05a6
docker compose
michael-brennan2005 Jun 11, 2024
0207510
Fix dockerifle II
michael-brennan2005 Jun 11, 2024
b7306ac
Fix dockerfile III
michael-brennan2005 Jun 11, 2024
d8e631a
init db script
michael-brennan2005 Jun 11, 2024
2133e08
init db debug I
michael-brennan2005 Jun 11, 2024
ef74111
init db debugging II
michael-brennan2005 Jun 11, 2024
58e32c3
init db debugging III
michael-brennan2005 Jun 11, 2024
2daeab3
iniit db debugging IV
michael-brennan2005 Jun 11, 2024
bac596e
init db debugging V
michael-brennan2005 Jun 11, 2024
c2cff26
Debugging part 267
michael-brennan2005 Jun 11, 2024
b84b7f3
make config path optional
michael-brennan2005 Jun 11, 2024
66a8f74
fix
michael-brennan2005 Jun 11, 2024
772681d
fix caddyfile
michael-brennan2005 Jun 11, 2024
9f82213
fixes
Jun 17, 2024
bc8c1a1
Merge branch 'main' into prod-business
michael-brennan2005 Jun 17, 2024
6a744b7
remove debug prints
michael-brennan2005 Jun 17, 2024
0fb3f96
Merge branch 'main' into prod-business
garrettladley Jun 17, 2024
c5c68ee
Merge branch 'main' into prod-business
michael-brennan2005 Jun 18, 2024
871cd4f
some changes
Jun 18, 2024
96d680c
Merge branch 'prod-business' of https://github.com/GenerateNU/sac int…
Jun 18, 2024
e56330a
fixes and changes
Jun 18, 2024
8510e3d
Merge branch 'main' into prod-business
michael-brennan2005 Jun 18, 2024
2abc3ef
dockerfile mods
Jun 18, 2024
8fcd51c
Merge branch 'prod-business' of https://github.com/GenerateNU/sac int…
Jun 18, 2024
862d4f4
update Dockerfile.server
garrettladley Jun 19, 2024
6b89bd3
Merge branch 'main' into prod-business
garrettladley Jun 19, 2024
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
2 changes: 1 addition & 1 deletion backend/Dockerfile.server
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ COPY --from=builder /app/bin/sac /sac

EXPOSE 8080

ENTRYPOINT [ "/sac" ]
ENTRYPOINT [ "/sac" ]
6 changes: 4 additions & 2 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
)

func GetConfiguration(path string) (*Settings, error) {
if err := godotenv.Load(path); err != nil {
return nil, fmt.Errorf("failed to load environment variables: %s", err.Error())
if path != "" {
if err := godotenv.Load(path); err != nil {
return nil, fmt.Errorf("failed to load environment variables: %s", err.Error())
}
}

intSettings, err := env.ParseAs[intermediateSettings]()
Expand Down
22 changes: 9 additions & 13 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net"
"os"
"os/signal"
"path/filepath"
"syscall"

"github.com/GenerateNU/sac/backend/background"
Expand All @@ -18,13 +17,11 @@ import (
"github.com/GenerateNU/sac/backend/constants"
"github.com/GenerateNU/sac/backend/database"
"github.com/GenerateNU/sac/backend/database/store"

// TODO: disable for prod with build tag
_ "github.com/GenerateNU/sac/backend/docs"
"github.com/GenerateNU/sac/backend/integrations"
"github.com/GenerateNU/sac/backend/integrations/email"
"github.com/GenerateNU/sac/backend/integrations/file"
"github.com/GenerateNU/sac/backend/integrations/oauth/soth/sothic"
"github.com/GenerateNU/sac/backend/search"
"github.com/GenerateNU/sac/backend/server"
"github.com/GenerateNU/sac/backend/telemetry"
"github.com/GenerateNU/sac/backend/utilities"
Expand Down Expand Up @@ -85,7 +82,7 @@ func main() {
func parseFlags() (onlyMigrate, seedSearch *bool, configPath *string) {
onlyMigrate = flag.Bool("only-migrate", false, "Specify if you want to only perform the database migration")
seedSearch = flag.Bool("seed-search", true, "Specify if you want to seed the opensearch nodes.")
configPath = flag.String("config", filepath.Join("..", "config", ".env.dev"), "Specify the path to the config file (.env)")
configPath = flag.String("config", "", "Specify the path to the config file (.env)")
flag.Parse()
return
}
Expand All @@ -101,14 +98,13 @@ func checkServerRunning(host string, port uint16) error {
}

func seedSearchData(db *gorm.DB) {
slog.Info("to appease linter", "seedSearch", true, "db", db)
// if err := search.SeedClubs(db); err != nil {
// return
// }

// if err := search.SeedEvents(db); err != nil {
// return
// }
if err := search.SeedClubs(db); err != nil {
return
}

if err := search.SeedEvents(db); err != nil {
return
}
}

func startBackgroundJobs(ctx context.Context, db *gorm.DB) {
Expand Down
4 changes: 2 additions & 2 deletions backend/redis_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# set up redis configuration directory
mkdir -p /usr/local/etc/redis
Expand All @@ -12,7 +12,7 @@ if [ -n ${REDIS_USERNAME} ] && [ -n ${REDIS_PASSWORD} ]; then
fi

# disable default user
if [ $(echo ${REDIS_DISABLE_DEFAULT_USER}) == "true" ]; then
if [ "$REDIS_DISABLE_DEFAULT_USER" == "true" ]; then
echo "user default off nopass nocommands" >> /usr/local/etc/redis/custom_aclfile.acl
fi

Expand Down
4 changes: 4 additions & 0 deletions backend/search/base/controller.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package base

import (
"log"
"net/http"
"os"

search_types "github.com/GenerateNU/sac/backend/search/types"
"github.com/GenerateNU/sac/backend/utilities"
Expand Down Expand Up @@ -30,6 +32,8 @@ func NewSearchController(searchService SearchServiceInterface) *SearchController
// @Failure 500 {object} error
// @Router /search/clubs [get]
func (s *SearchController) SearchClubs(c *fiber.Ctx) error {
log.SetOutput(os.Stdout)

var searchQuery search_types.ClubSearchRequest

if err := c.BodyParser(&searchQuery); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions backend/search/base/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func doSearchGetRequest[T, V any](url string, requestBody T) (*V, error) {
func Search[T types.Searchable](db *gorm.DB, query types.SearchRequest) (*types.SearchResult[T], error) {
result, err := doSearchGetRequest[types.SearchEndpointRequest, types.SearchEndpointResponse](fmt.Sprintf("/%s/_search", query.Index()), query.ToSearchEndpointRequest())
if err != nil {
return nil, nil
return nil, err
}

ids := make([]string, len(result.Hits.Hits))
Expand All @@ -57,7 +57,7 @@ func Search[T types.Searchable](db *gorm.DB, query types.SearchRequest) (*types.

var results []T
if err = query.Preload(db).Where("id IN ?", ids).Find(&results).Error; err != nil {
return nil, nil
return nil, err
}

return &types.SearchResult[T]{
Expand Down
6 changes: 1 addition & 5 deletions config/.env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SAC_APPLICATION_PORT="8080"
SAC_APPLICATION_HOST="127.0.0.1"
SAC_APPLICATION_BASE_URL="http://127.0.0.1"
SAC_APPLICATION_PUBLIC_URL="http://127.0.0.1"

SAC_DB_USERNAME="postgres"
SAC_DB_PASSWORD="password"
Expand Down Expand Up @@ -36,11 +37,6 @@ SAC_AWS_REGION="SAC_AWS_REGION"

SAC_SUDO_PASSWORD="Password#!1"

SAC_AWS_BUCKET_NAME="SAC_AWS_BUCKET_NAME"
SAC_AWS_ID="SAC_AWS_ID"
SAC_AWS_SECRET="SAC_AWS_SECRET"
SAC_AWS_REGION="SAC_AWS_REGION"

SAC_RESEND_API_KEY="SAC_RESEND_API_KEY"

SAC_CALENDAR_MAX_TERMINATION_DATE="12-31-2024"
Expand Down
3 changes: 3 additions & 0 deletions deployment/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
studentactivitycalendar.xyz {
reverse_proxy sac_webserver:8080
}
74 changes: 74 additions & 0 deletions deployment/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
services:
# WEBSERVER
caddy:
image: caddy:latest
restart: unless-stopped
cap_add:
- NET_ADMIN
ports:
- 80:80
- 443:443
- 443:443/udp
- 8443:8443
- 8443:8443/udp
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
webserver:
container_name: sac_webserver
build:
context: ../backend
dockerfile: ../backend/Dockerfile.server
env_file:
- .env.prod

# REDIS
redis-db-cache:
build:
context: ../backend
dockerfile: ../backend/Dockerfile.redis
container_name: redis_db_cache
ports:
- "6379"
environment:
- REDIS_USERNAME=redis_db_cache
- REDIS_PASSWORD=redis_db_cache!#1
- REDIS_DISABLE_DEFAULT_USER="true"
volumes:
- redis-db-cache-data:/data
redis-session:
build:
context: ../backend
dockerfile: ../backend/Dockerfile.redis
container_name: redis_session
ports:
- "6379"
environment:
- REDIS_USERNAME=${SAC_REDIS_SESSION_USERNAME}
- REDIS_PASSWORD=${SAC_REDIS_SESSION_PASSWORD}
- REDIS_DISABLE_DEFAULT_USER="true"
volumes:
- redis-session-data:/data
redis-limiter:
build:
context: ../backend
dockerfile: ../backend/Dockerfile.redis
container_name: redis_limiter
expose:
- "6379"
environment:
- REDIS_USERNAME=${SAC_REDIS_LIMITER_USERNAME}
- REDIS_PASSWORD=${SAC_REDIS_LIMITER_PASSWORD}
- REDIS_DISABLE_DEFAULT_USER="true"
volumes:
- redis-limiter-data:/data

volumes:
redis-session-data:
redis-limiter-data:
redis-db-cache-data:
opensearch-data1:
caddy_data:
external: true
caddy_config:
2 changes: 2 additions & 0 deletions deployment/init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
~/go/bin/migrate -path ../backend/migrations/ -database postgres://${SAC_DB_USERNAME}:${SAC_DB_PASSWORD}@${SAC_DB_HOST}:${SAC_DB_PORT}/${SAC_DB_NAME}?sslmode=require -verbose up
18 changes: 18 additions & 0 deletions deployment/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sudo yum update -y
sudo yum install -y docker git golang
sudo systemctl enable --now docker
sudo usermod -a -G docker ec2-user

# Install the docker compose plugin for all users
sudo mkdir -p /usr/local/lib/docker/cli-plugins

sudo curl -sL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-"$(uname -m)" \
-o /usr/local/lib/docker/cli-plugins/docker-compose

# Set ownership to root and make executable
test -f /usr/local/lib/docker/cli-plugins/docker-compose \
&& sudo chown root:root /usr/local/lib/docker/cli-plugins/docker-compose
test -f /usr/local/lib/docker/cli-plugins/docker-compose \
&& sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose

git clone -b prod-business https://github.com/GenerateNU/sac
Loading