mirror of
https://github.com/Lemonochrme/service-architecture.git
synced 2025-06-08 13:40:50 +02:00
Scripts: Populating database, autocreating .env file. CI/CD: Removed Deployement for now.
This commit is contained in:
parent
5e5c599338
commit
97ede71cf8
5 changed files with 73 additions and 69 deletions
33
.github/workflows/main_helpapp.yml
vendored
33
.github/workflows/main_helpapp.yml
vendored
|
@ -29,35 +29,4 @@ jobs:
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: java-app
|
name: java-app
|
||||||
path: '${{ github.workspace }}/helpapp-backend/*'
|
path: '${{ github.workspace }}/helpapp-backend/*'
|
||||||
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build
|
|
||||||
environment:
|
|
||||||
name: 'Production'
|
|
||||||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
|
||||||
permissions:
|
|
||||||
id-token: write #This is required for requesting the JWT
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download artifact from build job
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: java-app
|
|
||||||
|
|
||||||
- name: Login to Azure
|
|
||||||
uses: azure/login@v2
|
|
||||||
with:
|
|
||||||
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_88F0F141C7084A8789D648390DA913D7 }}
|
|
||||||
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_A84251CAC0104DC8A6709EE1E898E464 }}
|
|
||||||
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_11555886AA084155873A3C256628D2F2 }}
|
|
||||||
|
|
||||||
- name: Run Maven Spring Boot
|
|
||||||
uses: azure/webapps-deploy@v3
|
|
||||||
with:
|
|
||||||
app-name: 'helpapp'
|
|
||||||
slot-name: 'Production'
|
|
||||||
package: '${{ github.workspace }}/helpapp-backend/user-service/target/user-service-1.0-SNAPSHOT.jar'
|
|
||||||
custom-command: 'mvn spring-boot:run -pl user-service'
|
|
||||||
|
|
24
db/README.md
24
db/README.md
|
@ -1,9 +1,20 @@
|
||||||
# Database Initialization
|
# Database Initialization
|
||||||
|
|
||||||
First create a user in the mariadb:
|
### Install mariadb:
|
||||||
|
|
||||||
|
#### On Arch-Linux
|
||||||
|
```
|
||||||
|
pacman -S mariadb
|
||||||
|
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
|
||||||
|
sudo chown -R mysql:mysql /var/lib/mysql
|
||||||
|
sudo systemctl enable mariadb
|
||||||
|
sudo systemctl start mariadb
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create a user
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo mariab -u root -p
|
sudo mariadb -u root -p
|
||||||
```
|
```
|
||||||
```sql
|
```sql
|
||||||
CREATE USER '<user>'@'localhost' IDENTIFIED BY '<password>';
|
CREATE USER '<user>'@'localhost' IDENTIFIED BY '<password>';
|
||||||
|
@ -11,13 +22,6 @@ GRANT ALL PRIVILEGES ON *.* TO '<user>'@'localhost' WITH GRANT OPTION;
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
```
|
```
|
||||||
|
|
||||||
Then modify the `.env` file:
|
### Run the `init.sh` to create the database.
|
||||||
|
|
||||||
```bash
|
|
||||||
SERVICE_ARCHITECTURE_USER=user
|
|
||||||
SERVICE_ARCHITECTURE_PASSWORD=password
|
|
||||||
```
|
|
||||||
|
|
||||||
**And finally run the `init.sh` to create the database.**
|
|
||||||
|
|
||||||
> If you want to update the database, it is recommended to run `remove.sh` before hand.
|
> If you want to update the database, it is recommended to run `remove.sh` before hand.
|
40
db/db.sh
Normal file
40
db/db.sh
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
RESET='\033[0m' # No Color
|
||||||
|
|
||||||
|
source_env_file()
|
||||||
|
{
|
||||||
|
source .env
|
||||||
|
user="$SERVICE_ARCHITECTURE_USER"
|
||||||
|
pwd="$SERVICE_ARCHITECTURE_PASSWORD"
|
||||||
|
}
|
||||||
|
|
||||||
|
create_env_file()
|
||||||
|
{
|
||||||
|
echo -e "SERVICE_ARCHITECTURE_USER=$1\nSERVICE_ARCHITECTURE_PASSWORD=$2" > .env
|
||||||
|
}
|
||||||
|
|
||||||
|
check_env()
|
||||||
|
{
|
||||||
|
if [ -f .env ]; then
|
||||||
|
source_env_file
|
||||||
|
else
|
||||||
|
echo -e $YELLOW"Warning: No '.env' file found."$RESET
|
||||||
|
echo "Enter the db username:"
|
||||||
|
read db_user
|
||||||
|
echo "Enter the db password:"
|
||||||
|
read -s db_pwd
|
||||||
|
if ! mariadb -u"$db_user" -p"$db_pwd" -e "exit" > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
echo -e $RED"Error: Could not connect to MYSQL with the following ids."$RESET
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
create_env_file $db_user $db_pwd
|
||||||
|
source_env_file
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
29
db/init.sh
29
db/init.sh
|
@ -1,28 +1,27 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Checks the .env file
|
source ./db.sh
|
||||||
if [ -f .env ]; then
|
|
||||||
source .env
|
|
||||||
user="$SERVICE_ARCHITECTURE_USER"
|
|
||||||
pwd="$SERVICE_ARCHITECTURE_PASSWORD"
|
|
||||||
else
|
|
||||||
echo ".env file not found. Please create one with USER and PASSWORD variables."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
check_env
|
||||||
echo "Creating database 'service-architecture'..."
|
echo "> Creating database 'service-architecture'..."
|
||||||
if ! mariadb -u "$user" -p"$pwd" -e "CREATE DATABASE IF NOT EXISTS \`service-architecture\`;"
|
if ! mariadb -u "$user" -p"$pwd" -e "CREATE DATABASE IF NOT EXISTS \`service-architecture\`;"
|
||||||
then
|
then
|
||||||
echo "Error: Failed to create database, check your .env"
|
echo -e $RED"Error: Failed to create database, check your .env"$RESET
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Uploading database 'service-architecture'..."
|
echo "> Uploading database 'service-architecture'..."
|
||||||
if ! mariadb -u "$user" -p"$pwd" "service-architecture" < db.sql
|
if ! mariadb -u "$user" -p"$pwd" "service-architecture" < db.sql
|
||||||
then
|
then
|
||||||
echo "Error: Failed to execute db.sql, contact the maintainers."
|
echo -e $RED"Error: Failed to execute db.sql, contact the maintainers."$RESET
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Database setup successful!"
|
echo "> Populating database 'service-architecture'..."
|
||||||
|
if ! mariadb -u "$user" -p"$pwd" "service-architecture" < init.sql
|
||||||
|
then
|
||||||
|
echo -e $RED"Error: Failed to execute init.sql, contact the maintainers."$RESET
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e $GREEN"Database setup successful!"$RESET
|
||||||
|
|
16
db/remove.sh
16
db/remove.sh
|
@ -1,21 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Checks the .env file
|
source ./db.sh
|
||||||
if [ -f .env ]; then
|
|
||||||
source .env
|
|
||||||
user="$SERVICE_ARCHITECTURE_USER"
|
|
||||||
pwd="$SERVICE_ARCHITECTURE_PASSWORD"
|
|
||||||
else
|
|
||||||
echo ".env file not found. Please create one with USER and PASSWORD variables."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
check_env
|
||||||
echo "Removing database 'service-architecture'..."
|
echo "Removing database 'service-architecture'..."
|
||||||
if ! mariadb -u "$user" -p"$pwd" -e "DROP DATABASE \`service-architecture\`;"
|
if ! mariadb -u "$user" -p"$pwd" -e "DROP DATABASE \`service-architecture\`;"
|
||||||
then
|
then
|
||||||
echo "Error: Failed to create database, check your .env"
|
echo -e $RED"Error: Failed to remove database:\n\t- Does the database exists ?\n\t- Have you checked your credentials ?"$RESET
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "Database removed successfully!"
|
echo -e $GREEN"Database removed successfully!"$RESET
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue