This guide provides a comprehensive set of instructions to deploy the RoboCoin application on a fresh Linux server (e.g., Ubuntu 22.04). It covers everything from installing system dependencies to running the application.
Before you can deploy the application, you need to prepare your server with the necessary software.
First, connect to your server via SSH and make sure all system packages are up-to-date.
sudo apt update && sudo apt upgrade -yThe application is built with Node.js. We recommend using Node Version Manager (nvm) to install Node.js, as it allows you to easily manage different Node versions.
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# Source nvm to use it in the current session
source ~/.bashrc
# Install the latest Long-Term Support (LTS) version of Node.js
nvm install --ltsGit is required to clone the application repository from version control.
sudo apt install git -yYou need a database for the application to store user data, balances, etc.
# Install MariaDB server
sudo apt install mariadb-server -y
# Start and enable the MariaDB service
sudo systemctl start mariadb
sudo systemctl enable mariadb
# Run the secure installation script to set the root password and secure your installation
sudo mysql_secure_installationNow, log in to MariaDB to create a database and user for your application.
# Log in as the root user (you will be prompted for the password you just set)
sudo mysql -u root -pOnce logged in, run the following SQL commands:
-- Create the database
CREATE DATABASE robocoin;
-- Create a new user and set their password
CREATE USER 'robocoin_user'@'localhost' IDENTIFIED BY 'your_strong_password';
-- Grant all privileges on the new database to the user
GRANT ALL PRIVILEGES ON robocoin.* TO 'robocoin_user'@'localhost';
-- Apply the changes
FLUSH PRIVILEGES;
-- Exit the MariaDB prompt
EXIT;Note: Remember to replace 'your_strong_password' with a secure password.
With the server set up, you can now deploy the application.
Clone the application code from its Git repository.
git clone git@github.com:RoboticsBrno/RoboCoin.git
cd RoboCoin
git checkout v3The application requires environment variables for the database connection and application secrets. A template is provided in the repository.
# Copy the example environment file
cp .example-env .envNow, open the .env file with a text editor (e.g., vim .env) and fill in the required values:
-
DATABASE_URL: This is the connection string for the MariaDB database you just created. The format is:mysql://robocoin_user:your_strong_password@localhost:3306/robocoin -
NEXTAUTH_SECRET: This is a secret key used to secure user sessions. You can generate a strong secret with the following command:openssl rand -base64 32
Copy the output of this command into your
.envfile.
A deployment script (deploy.sh) is included to automate the installation, migration, and build process.
# First, make the script executable
chmod +x deploy.sh
# Then, run the script
./deploy.shThe script will:
- Install all dependencies using
npm ci. - Run database migrations with
npx prisma migrate deploy. - Build the application for production with
npm run build. - Start the server with
npm start.
Your terminal will be occupied by the running application. To stop the server, you can press Ctrl+C.
Your RoboCoin application is now deployed and running!