The application is built on Go v1.23.4 and PostgreSQL. It uses Fiber as the HTTP framework and pgx as the driver and sqlx as the query builder.
-
Ensure you have Go 1.23 or higher and Task installed on your machine:
go version && task --version -
Create a copy of the
.env.examplefile and rename it to.env:cp ./config/.env.example ./config/.env
Update configuration values as needed.
-
Install all dependencies, run docker compose, create database schema, and run database migrations:
task
-
Run the project in development mode:
task dev
-
Start the Docker containers:
task service:up
-
To stop the Docker containers:
task service:down
-
To build the Docker containers:
task service:build
To check the database connection, use the following command:
task service:db:connect-
Navigate to the folder test and clone the repository:
git clone https://github.com/ProjectSprint/Batch3Project2TestCase.git
-
Install k6 (if you don't have it installed):
Follow the instructions on the k6 installation page to install k6 on your machine.
-
Navigate to the folder where this is extracted/cloned in terminal and run this for :
BASE_URL=http://localhost:8080 make pull-test
-
Make sure that you have Redis installed and exposed on port 6379, then run:
BASE_URL=http://localhost:8080 k6 run load_test.js
Before that, run VPN first:
sudo openvpn --config /path/to/your/config.ovpn
Replace /path/to/your/config.ovpn with the path to the .ovpn configuration file you received.
-
Update Go modules:
Before building the production binary, make sure to update the Go modules by running:
task
-
Build the application for production:
Run the following command to build the production binary:
task build
-
Upload the binary to your EC2 instance using SCP:
Upload the built binary to your EC2 instance:
scp -i /path/to/your-key.pem mybinary ubuntu@<EC2_PUBLIC_IP>:/home/ubuntu/
Replace
/path/to/your-key.pemwith the path to your private key,mybinarywith the name of your binary, and<EC2_PUBLIC_IP>with the public IP of your EC2 instance. -
Upload the config/.env to your EC2 instance using SCP:
Upload the
.envconfiguration file (along with theconfig/directory) to your EC2 instance:scp -i /path/to/your-key.pem -r config ubuntu@<EC2_PUBLIC_IP>:/home/ubuntu/
Replace
/path/to/your-key.pemwith the path to your private key and<EC2_PUBLIC_IP>with the public IP of your EC2 instance. -
Login to your EC2 instance:
SSH into your EC2 instance:
ssh -i /path/to/your-key.pem ubuntu@<EC2_PUBLIC_IP>
-
Make the binary executable:
If the binary isn't executable, run the following command to make it executable:
chmod +x /home/ubuntu/mybinary
-
Run the binary:
Run the binary to start the application:
./mybinary
-
Update Your
.envFile:
Ensure your.envfile contains the correct production database credentials. Update the following values inconfig/.env:DB_HOST=<PRODUCTION_DB_HOST> DB_PORT=<PRODUCTION_DB_PORT> DB_USER=<PRODUCTION_DB_USER> DB_PASS=<PRODUCTION_DB_PASSWORD> DB_NAME=<PRODUCTION_DB_NAME>
-
Connect to the Production Database:
To connect to the production database, use the following task:task db:connect
This command will prompt you to log in to the production database.
-
Run Migrations:
Apply migrations to the production database:task migrate:up
This uses the production database credentials specified in your
.envfile. -
Rollback Migrations (Optional):
To roll back a migration in the production database, use:task migrate:down
Or force a specific migration version:
task migrate:force CLI_ARGS=<VERSION>