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: prepare build script and compose files for many environments #240

Merged
merged 1 commit into from
May 23, 2024
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
41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,29 @@ If you would like to contribute, please have a look at our [contribution guideli

- Clone the repository
- `cp backend/.env.example backend/.env && cp frontend/.env.example frontend/.env`
- Run `./build up`
- To migrate the database to a fresh state, run `./build migrate-fresh` (you can do this while docker is running with all the services)
- If you do not need hot reloading for the client, you can set `APP_ENV=produdction` in the `.env` files, and you will not need to run the frontend server (`yarn run dev`),
simply go to `localhost:8080` in your browser and the Go server will serve the frontend as well (it builds the js in docker).

- If you are working on the backend, you may wish to comment out the `server` service (1st) in the `docker-compose.yml` file,
and run `./build up`, then you can simply run `./build` to start the backend server, and when making changes you will not have
to wait for docker to rebuild the frontend, the middleware, and start the other 4 containers each time you wish to test out
a change. If you are developing the middleware, simply comment it out and run it separately with `go run provider-middleware/.`

**If you need hot reloading for the client:**
- Change directory to the frontend directory
- Run `yarn install`
- Run `yarn run dev`
- Open `http://localhost:5173` in your browser

- Login with `SuperAdmin` and password: `ChangeMe!`
- You will be prompted immediately to set a new password, and then you will be redirected to the dashboard.

**For frontend development:**
- Run `./build dev -f`

This will build everything but the client, which you can then run separately with `yarn run dev` in the frontend directory.

**For backend development:**

- Run `./build dev`

This will build only the Auth and run Postgres. You are responsible for building and running the server and middleware.

**For Production:**

- Run `./build prod` to build the entire project in docker. You can then go to `localhost` in your browser.


Login with `SuperAdmin` and password: `ChangeMe!`

You will be prompted immediately to set a new password, and then you will be redirected to the dashboard.

### To migrate the database to a fresh state, run `./build migrate-fresh` (you can do this while docker is running with all the services)


## Style/Linting

Expand Down
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Go-Prototype
module UnlockEdv2

go 1.22.2

Expand Down
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
server "Go-Prototype/src/handlers"
server "UnlockEdv2/src/handlers"
"fmt"
"net/http"
"os"
Expand Down
4 changes: 2 additions & 2 deletions backend/migrations/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"Go-Prototype/src/database"
"Go-Prototype/src/models"
"UnlockEdv2/src/database"
"UnlockEdv2/src/models"
"fmt"
"log"
"os"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/DB.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"fmt"
"log"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/activity.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"fmt"
"time"

Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/leftmenulinks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"log"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/milestones.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
)

func IsValidOrderBy(orderBy string) bool {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/oidc_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package database

import "Go-Prototype/src/models"
import "UnlockEdv2/src/models"

func (db *DB) GetClientForProvider(provID uint) (*models.OidcClient, error) {
client := models.OidcClient{}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/outcomes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
)

func (db *DB) GetOutcomesForUser(id uint, page, perPage int) (int64, []models.Outcome, error) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/programs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
)

func (db *DB) GetProgramByID(id int) (*models.Program, error) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/provider_platforms.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"fmt"
"log"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/provider_user_mappings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"errors"
)

Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/user_activity.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
)

type UserAcitivityJoin struct {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/database/users.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"errors"

log "github.com/sirupsen/logrus"
Expand Down
4 changes: 2 additions & 2 deletions backend/src/handlers/actions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package handlers

import (
"Go-Prototype/src"
"Go-Prototype/src/models"
"UnlockEdv2/src"
"UnlockEdv2/src/models"
"net/http"
"strconv"

Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/activity_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/left_menu_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"

Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/milestones_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/oidc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"os"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/outcomes_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/programs_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/provider_platform_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/provider_user_mapping_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"net/http"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
database "Go-Prototype/src/database"
database "UnlockEdv2/src/database"
"context"
"encoding/json"
"math"
Expand Down
4 changes: 2 additions & 2 deletions backend/src/handlers/user_activity_handler.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package handlers

import (
"Go-Prototype/src/database"
"Go-Prototype/src/models"
"UnlockEdv2/src/database"
"UnlockEdv2/src/models"
"net/http"
"strconv"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/user_handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package handlers

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"encoding/json"
"fmt"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package src

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"bytes"
"encoding/json"
"errors"
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tests

import (
"Go-Prototype/src/handlers"
"UnlockEdv2/src/handlers"
"os"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/provider_platform_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tests

import (
"Go-Prototype/src/models"
"UnlockEdv2/src/models"
"bytes"
"encoding/json"
"net/http"
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/user_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tests

import (
"Go-Prototype/src/handlers"
"Go-Prototype/src/models"
"UnlockEdv2/src/handlers"
"UnlockEdv2/src/models"
"bytes"
"encoding/json"
"fmt"
Expand Down
19 changes: 9 additions & 10 deletions build
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#!/bin/bash

help="Usage: ./build up | migrate-fresh | server"
help="Usage: ./build prod | dev [-f] | migrate-fresh"

if [[ "$1" == "-h" ]]; then
echo "$help"
if [[ "$1" == "prod" ]]; then
docker compose -f docker-compose.yml -f config/docker-compose.prod.yml up --build
exit 0
fi

if [[ "$1" == "up" ]]; then
docker-compose up -d --build
echo "Building backend..."
if [[ "$1" == "dev" ]]; then
if [[ "$2" == "-f" ]]; then
docker compose -f docker-compose.yml -f config/docker-compose.fe-dev.yml up --build
else
docker compose up
fi
fi

if [[ "$1" == "migrate-fresh" ]]; then
go run backend/migrations/main.go
fi

if [[ "$1" == "server" ]]; then
go run backend/main.go
fi

exit 0
43 changes: 43 additions & 0 deletions config/docker-compose.fe-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
server:
build:
context: .
dockerfile: ./backend/Dockerfile
environment:
- APP_ENV=production
- DB_HOST=postgres
- DB_PORT=5432
- DB_USER=unlocked
- DB_PASSWORD=dev
- DB_NAME=unlocked
- PROVIDER_SERVICE_URL=http://provider-service:8081
- HYDRA_ADMIN_URL=http://hydra:4445
- HYDRA_PUBLIC_URL=http://hydra:4444
ports:
- "8080:8080"
depends_on:
postgres:
condition: service_healthy
env_file:
- "./backend/.env"
command: >
./backend
volumes:
- ./logs:/logs/
networks:
- intranet

# Provider middleware
provider-service:
build:
context: ./provider-middleware
dockerfile: Dockerfile
env_file: "./backend/.env"
command: ./provider-service
networks:
- intranet
volumes:
- ./logs:/logs
depends_on:
postgres:
condition: service_healthy
Loading
Loading