diff --git a/.dev.env b/.dev.env index 349e193..ba1e823 100644 --- a/.dev.env +++ b/.dev.env @@ -1,14 +1,16 @@ # MySQL environment variables +MYSQL_ADDRESS=localhost +MYSQL_PORT=3306 MYSQL_ROOT_PASSWORD=password MYSQL_DATABASE=urchin MYSQL_USER=urchin MYSQL_PASSWORD=urchinpw -# Urchin environment variables -URCHIN_DATABASE_ADDRESS=localhost -URCHIN_DATABASE_PORT=3306 -URCHIN_DATABASE_USER=urchin -URCHIN_DATABASE_PASSWORD=urchinpw -URCHIN_DATABASE_NAME=urchin -URCHIN_WEBSERVER_PORT=8081 -URCHIN_IMAGE_DIRECTORY=./images \ No newline at end of file +# Urchin environment variables, can be used as fallback for starting the application +# URCHIN_DATABASE_ADDRESS=localhost +# URCHIN_DATABASE_PORT=3306 +# URCHIN_DATABASE_USER=urchin +# URCHIN_DATABASE_PASSWORD=urchinpw +# URCHIN_DATABASE_NAME=urchin +# URCHIN_WEBSERVER_PORT=8081 +# URCHIN_IMAGE_DIRECTORY=./images diff --git a/.gitignore b/.gitignore index 4f94bd5..e215f7a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ **/__debug* **/*_templ.go tmp/ -**/main diff --git a/LICENSE b/LICENSE index 2aaf691..e7407f8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2024 Matheus Gomes Garcia +Copyright 2024 Matheus Gomes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index e8a1b84..5c49b2d 100644 --- a/README.md +++ b/README.md @@ -102,11 +102,27 @@ Urchin relies on the following Golang dependencies: ## Configuration -The runtime configuration is handled through reading the -necessary environment variables. This approach was chosen as -it makes integrating `envfile`s quite easy. +The runtime configuration can be done through a [toml](https://toml.io/en/) configuration file or by setting the mandatory environment variables (*fallback*). This approach was chosen because configuration via toml supports advanced features (i.e. *relationships*, *arrays*, etc.). The `.dev.env`-file is used to configure the development database through `docker-compose`. -The following list outlines the environment variables needed. +### toml configuration + +The application can be started by providing the `config` flag which has to be set to a toml configuration file. The file has to contain the following mandatory values: + +```toml +database_address = "localhost" # Address to the MariaDB database +database_user = "urchin" # User to access database +database_password = "urchinpw" # Password for the database user +database_port = 3306 # The port to use for the application +database_name = "urchin" # The database to use for Urchin +webserver_port = 8080 # The application port Urchin should use +image_dir = "./images" # Directory to use for storing uploaded images. +``` + +**Important**: The configuration values above are used to start-up the local development database. + +### Environment variables configuration (fallback) + +If chosen, by setting the following environment variables the application can be started without providing a toml configuration file. - `URCHIN_DATABASE_ADDRESS` should contain the database addres, e.g. `localhost`. @@ -120,16 +136,12 @@ The following list outlines the environment variables needed. ## Development -To ease up the development process, Docker is highly recommended. This way you can use the `docker/mysqldb.yml` to set up a predefined MySQL database server. The docker-compose file references the [`.dev.env`](#env-file) and creates the Urchin database and an application user. +To ease up the development process, Docker is highly recommended. This way you can use the `docker/mysqldb.yml` to set up a predefined MySQL database server. The docker-compose file references the `.dev.env` and creates the Urchin database and an application user. ```bash $ docker-compose -f docker/mysqldb.yml up -d ``` -### .env-file - -As described under [configuration section](#configuration), specific environment variables have to be defined for Urchin to run properly. For this an `.dev.env` file is pre-configured to set the required variables with some dummy values. This .env-file includes variables for the database and Urchin and can be used for the launch configuration in VSCode. - ### Dependencies For the development of Urchin, you require additional dependecies, that can easily be installed with go. @@ -153,7 +165,7 @@ After installing the required dependecies and starting the pre-configured databa ```bash $ source .dev.env # sets the environment variable for the goose command. $ cd migrations/ -$ GOOSE_DRIVER="mysql" GOOSE_DBSTRING="$URCHIN_DATABASE_USER:$URCHIN_DATABASE_PASSWORD@tcp($URCHIN_DATABASE_ADDRESS:$URCHIN_DATABASE_PORT)/$URCHIN_DATABASE_NAME" goose up +$ GOOSE_DRIVER="mysql" GOOSE_DBSTRING="$MYSQL_USER:$MYSQL_PASSWORD@tcp($MYSQL_ADDRESS:$MYSQL_PORT)/$MYSQL_DATABASE" goose up ``` ### Launching & Debugging @@ -171,7 +183,10 @@ To debug the application or simply running it from within VSCode create a `launc "mode": "auto", "program": "${workspaceFolder}/cmd/urchin/main.go", "cwd": "${workspaceFolder}", - "envFile": "${workspaceFolder}/.dev.env", + "args": [ + "--config", + "urchin_config.toml" + ] }, { "name": "Urchin Admin", @@ -180,9 +195,12 @@ To debug the application or simply running it from within VSCode create a `launc "mode": "auto", "program": "${workspaceFolder}/cmd/urchin-admin/main.go", "cwd": "${workspaceFolder}", - "envFile": "${workspaceFolder}/.dev.env", + "args": [ + "--config", + "urchin_config.toml" + ] } ] } ``` -However, the [Go-Extension](https://marketplace.visualstudio.com/items?itemName=golang.Go) must be installed before you can use these launch configurations. \ No newline at end of file +However, the [Go-Extension](https://marketplace.visualstudio.com/items?itemName=golang.Go) must be installed before you can use these launch configurations. diff --git a/docker/mysqldb.yml b/docker/mysqldb.yml index 2df1ab7..370df75 100644 --- a/docker/mysqldb.yml +++ b/docker/mysqldb.yml @@ -7,4 +7,4 @@ services: ports: - 3306:3306 env_file: - - ../.dev.env \ No newline at end of file + - ../.dev.env diff --git a/urchin_config.toml b/urchin_config.toml index 06f6a96..057879c 100644 --- a/urchin_config.toml +++ b/urchin_config.toml @@ -1,11 +1,11 @@ # Address to the MariaDB database -database_address = "mariadb" +database_address = "localhost" # User to access datbaase -database_user = "root" +database_user = "urchin" # Password for the database user -database_password = "root" +database_password = "urchinpw" # port database_port = 3306 @@ -16,3 +16,6 @@ database_name = "urchin" # port to run the webserver on webserver_port = 8080 + +# Directory to use for storing uploaded images. +image_dir = "./images" \ No newline at end of file