Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
- Added the missing documentation for `urchin_config.toml`.
- Updated name in MIT license.
- Minor changes due to feedback.
  • Loading branch information
AlDu2407 committed Mar 17, 2024
1 parent 8cdef66 commit 9393f7b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 27 deletions.
18 changes: 10 additions & 8 deletions .dev.env
Original file line number Diff line number Diff line change
@@ -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
# 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
**/__debug*
**/*_templ.go
tmp/
**/main
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2024 Matheus Gomes Garcia <[email protected]>
Copyright 2024 Matheus Gomes <[email protected]>

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:

Expand Down
44 changes: 31 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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.
However, the [Go-Extension](https://marketplace.visualstudio.com/items?itemName=golang.Go) must be installed before you can use these launch configurations.
2 changes: 1 addition & 1 deletion docker/mysqldb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ services:
ports:
- 3306:3306
env_file:
- ../.dev.env
- ../.dev.env
9 changes: 6 additions & 3 deletions urchin_config.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

0 comments on commit 9393f7b

Please sign in to comment.