Skip to content

1. Setup development environment

Alexander Hansson edited this page Mar 26, 2023 · 16 revisions

The main configuration methods for setting up the development environment

  • Choose a method that suits you best:
  1. runBackend.sh
    • (Recommended for Unix systems - also works for WSL)
  2. Docker & Visual Studio
    • (Recommended for Unix systems)
  3. Stand Alone
    • (Recommended for Unix systems, if the the bash script does not work - for example due to issues with WSL)
    • (no Docker, and you can choose any IDE you like, for example Visual Studio Code)

runBackend.sh

  • Recommended for Unix systems
  1. Install Docker

  2. Install .NET SDK

    1. It is available here
  3. Give the script execution permissions

    1. Run the following command to give the script execution permissions:
chmod +x runBackend.sh
  1. Run the script:
sudo ./runBackend.sh

Common causes of errors with ./runBackend.sh

(Note, much of these solutions are also relevant to the standalone solution

  • You are not using sudo in front of sudo ./runBackend.sh
    • Alternativly you are not using sudo in front of docker commands
  • Dotnet or Docker is not installed (correctly)
    • To test this, try if the following commands give a version
docker -v
dotnet --version
  • The configured dotnet version of the backend is not the same as your downloaded dotnet version

    • A quick way to temporarily fix this is to simply change what version the backend uses:
    1. Run the following command and note your dotnet version:
    dotnet --version
    
    1. Change the TargetFramework in Nexpo/Nexpo.csproj to match your dotnet version
      • For example if you have dotnet version 6.0.113, change to dotnet 6 in Nexpo/Nexpo.csproj, meaning replace with the following line:
    <TargetFramework>net6.0</TargetFramework>
    
    1. WSL1 causes some complications with docker. Use the following command to test your WSL version, and update if you still can not get Docker to work
    wsl -v
    
    Help regarding runBackend.sh

    The command ./runBackend -h is useful for receiving help regarding the bash script.

    Stand Alone

    1. Install Docker Desktop
      1. You can get it for Windows and Mac here
    2. Containerize the database, by running:
    sudo docker run -d --name nexpo_database -p 5432:5432 -e POSTGRES_USER=nexpo -e POSTGRES_PASSWORD=nexpo postgres:14
    
    Click to Expand for additional information
    1. Note: On windows, simply skip using sudo
    2. The default development database connection tries to access the database nexpo on localhost:5432 using the credentials nexpo:nexpo. The nexpo user of course needs the correct permissions on the database and if you change anything in the setup make sure to update the connection string as well.
    3. It will pull down the correct PostgreSQL server and set it up as we want it. Keep in mind though that no persistent volume is added to the container so don't do this in production.
    1. Install .NET SDK
      1. It is available here
    2. Run the backend
      1. Run the following command to run:
    dotnet run --project Nexpo
    
    Click to Expand for additional information
    To avoid having to specify the project every time, you can also:
    1. Change directories to the `Nexpo` project folder.
    2. run `dotnet run` (without the `--project Nexpo` flag)
    How to visualize DBeaver
    1. Run previous command for running database in docker without Docker Desktop.
    2. Download DBeaver https://dbeaver.io/download/
    3. Connect to open postgres connection with settings Postgresql and default 5432 default port. db_name, user, password as nexpo

    Docker & Visual Studio

    • Recommended for Windows
    1. Install Docker Desktop

      1. You can get it for Windows and Mac here
    2. Install Visual Studio

      1. Use the Community Edition if you don't have a license. During installation, select the "ASP.NET and web development" toolbox when given the choice to enable good support for Docker and the application.
    3. Open the solution (the code) in Visual Studio

      1. Open Visual Studio and open the solution file Nexpo.sln.
    4. Make sure the docker-compose "project" is selected as the startup project

      1. If not already selected as the startup project, right click docker-compose in the Solution Explorer and select "Set as Startup Project".
    5. Run the backend

      1. A database with automatically be created

    Setup Test Environment

    No matter the chosen setup method, it´s required to start an external database server before running the tests for them to pass. This is due to some tests utilizing black-box testing through testing against the controllers. It may take a while for the container to populate the tables with the example data, so if most controller-tests fail during the first run try to run them again.

    NOTE: Running docker-compose in Visual Studio and then the tests do for some reason not work, even though it creates and starts the postgres container. Try instead to run the the shell command which creates a separate container for testing:

    sudo docker run -d --name nexpo_database -p 5432:5432 -e POSTGRES_USER=nexpo -e POSTGRES_PASSWORD=nexpo postgres:14
    
Clone this wiki locally