Skip to content

Commit

Permalink
Allowing the Admin app to run at the same time
Browse files Browse the repository at this point in the history
* Added a configuration for the port used for admin app only.
* Changed the tests to include the newly added settings fields.
* Added a third container to run the admin app alongside the main one.
  • Loading branch information
matheusgomes28 committed May 14, 2024
1 parent 81eff9c commit aaeec68
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/urchin-admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
}

r := admin_app.SetupRoutes(app_settings, database)
err = r.Run(fmt.Sprintf(":%d", app_settings.WebserverPort))
err = r.Run(fmt.Sprintf(":%d", app_settings.AdminPort))
if err != nil {
log.Error().Msgf("could not run app: %v", err)
os.Exit(-1)
Expand Down
1 change: 1 addition & 0 deletions common/app_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type AppSettings struct {
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort int `toml:"webserver_port"`
AdminPort int `toml:"admin_port"`
ImageDirectory string `toml:"image_dir"`
AppNavbar Navbar `toml:"navbar"`
}
Expand Down
20 changes: 18 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
urchin_app:
image: mattgomes28/urchin-golang:0.3
Expand All @@ -19,6 +17,24 @@ services:
networks:
- common-net

urchin_admin_app:
image: mattgomes28/urchin-golang:0.3
ports:
- "8081:8081"
volumes:
- type: bind
source: ..
target: /urchin
volume:
nocopy: true
command: /urchin/docker/start-admin-app.sh
depends_on:
mariadb:
condition: service_healthy
restart: always
networks:
- common-net

mariadb:
image: mariadb:11.2.3-jammy
container_name: mariadb
Expand Down
3 changes: 3 additions & 0 deletions docker/urchin_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ database_name = "urchin"
# port to run the webserver on
webserver_port = 8080

# port to run the admin app on
admin_port = 8081

# Directory to use for storing uploaded images.
image_dir = "./images"

Expand Down
14 changes: 14 additions & 0 deletions tests/app_tests/app_settings/app_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ func TestMissingDatabaseAddress(t *testing.T) {
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort string `toml:"webserver_port"`
AdminPort string `toml:"admin_port"`
DatabasePort string `toml:"database_port"`
}{
DatabaseUser: "test_database_user",
DatabasePassword: "test_database_password",
DatabaseName: "test_database_name",
WebserverPort: "99999",
AdminPort: "99998",
DatabasePort: "666",
}

Expand All @@ -90,12 +92,14 @@ func TestMissingDatabaseUser(t *testing.T) {
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort string `toml:"webserver_port"`
AdminPort string `toml:"admin_port"`
DatabasePort string `toml:"database_port"`
}{
DatabaseAddress: "test_database_address",
DatabasePassword: "test_database_password",
DatabaseName: "test_database_name",
WebserverPort: "99999",
AdminPort: "99998",
DatabasePort: "666",
}

Expand All @@ -115,12 +119,14 @@ func TestMissingDatabasePassword(t *testing.T) {
DatabaseUser string `toml:"database_user"`
DatabaseName string `toml:"database_name"`
WebserverPort string `toml:"webserver_port"`
AdminPort string `toml:"admin_port"`
DatabasePort string `toml:"database_port"`
}{
DatabaseAddress: "test_database_address",
DatabaseUser: "test_database_user",
DatabaseName: "test_database_name",
WebserverPort: "99999",
AdminPort: "99998",
DatabasePort: "666",
}

Expand All @@ -140,12 +146,14 @@ func TestMissingDatabaseName(t *testing.T) {
DatabaseUser string `toml:"database_user"`
DatabasePassword string `toml:"database_password"`
WebserverPort string `toml:"webserver_port"`
AdminPort string `toml:"webserver_port"`
DatabasePort string `toml:"database_port"`
}{
DatabaseAddress: "test_database_address",
DatabaseUser: "test_database_user",
DatabasePassword: "test_database_password",
WebserverPort: "99999",
AdminPort: "99998",
DatabasePort: "666",
}

Expand Down Expand Up @@ -191,12 +199,14 @@ func TestMissingDatabasePort(t *testing.T) {
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort string `toml:"webserver_port"`
AdminPort string `toml:"admin_port"`
}{
DatabaseAddress: "test_database_address",
DatabaseUser: "test_database_user",
DatabasePassword: "test_database_password",
DatabaseName: "test_database_name",
WebserverPort: "99999",
AdminPort: "99998",
}

bytes, err := toml.Marshal(missing_database_address)
Expand All @@ -217,13 +227,15 @@ func TestWrongDatabasePortValueType(t *testing.T) {
DatabaseName string `toml:"database_name"`
DatabasePort string `toml:"database_port"`
WebserverPort int `toml:"webserver_port"`
AdminPort int `toml:"admin_port"`
}{
DatabaseAddress: "test_database_address",
DatabaseUser: "test_database_user",
DatabasePassword: "test_database_password",
DatabaseName: "test_database_name",
DatabasePort: "String Should Not Work",
WebserverPort: 99999,
AdminPort: 99998,
}

bytes, err := toml.Marshal(missing_database_address)
Expand All @@ -244,13 +256,15 @@ func TestWrongwebserverPortValueType(t *testing.T) {
DatabaseName string `toml:"database_name"`
DatabasePort int `toml:"database_port"`
WebserverPort string `toml:"webserver_port"`
AdminPort string `toml:"admin_port"`
}{
DatabaseAddress: "test_database_address",
DatabaseUser: "test_database_user",
DatabasePassword: "test_database_password",
DatabaseName: "test_database_name",
DatabasePort: 10,
WebserverPort: "99999",
AdminPort: "99998",
}

bytes, err := toml.Marshal(missing_database_address)
Expand Down
3 changes: 3 additions & 0 deletions urchin_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ database_name = "urchin"
# port to run the webserver on
webserver_port = 8080

# port to run the admin app on
admin_port = 8081

# Directory to use for storing uploaded images.
image_dir = "./images"

Expand Down

0 comments on commit aaeec68

Please sign in to comment.