Skip to content

Commit

Permalink
Merge pull request #101 from kiloutyg/100-updating-stuff-for-deployme…
Browse files Browse the repository at this point in the history
…nt-outside-initial-plant

100 updating stuff for deployment outside initial plant
  • Loading branch information
kiloutyg authored Sep 3, 2024
2 parents 61338d6 + 6813cac commit b6450fd
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 37 deletions.
10 changes: 2 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3.8'
services:
database:
image: mariadb:latest
image: docker.io/mariadb:latest
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
Expand All @@ -16,15 +15,10 @@ services:
networks:
vpcbr:
ipv4_address: 172.22.0.2
labels:
- "traefik.enable=false"
# - "traefik.http.routers.database-efnc.rule=PathPrefix(`/database-efnc`)"
# - "traefik.http.routers.database-efnc.entrypoints=mariadb"
# - "traefik.tcp.routers.tcp-database-efnc.entrypoints=mariadb"
command: ['--init-file', '/docker-entrypoint-initdb.d/create-power-bi-ronlyuser.sql']

phpmyadmin:
image: phpmyadmin/phpmyadmin
image: docker.iophpmyadmin/phpmyadmin
restart: unless-stopped
environment:
PMA_HOST: database
Expand Down
52 changes: 42 additions & 10 deletions env_create.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
#!/bin/bash

# Get the github user from the argument
GITHUB_USER=$1
echo "GitHub User: $GITHUB_USER"

# Function to check for uppercase characters
contains_uppercase() {
[[ "$1" =~ [A-Z] ]]
}
# function to check if the site name is valid and has the first letter uppercase
is_FACILITY_name_valid() {
[[ "$1" = ^[A-Z] ]]
}

# Prompt for plant trigram
while true; do
read -p "Please enter your plant trigram (example: lan): " PLANT_TRIGRAM
if contains_uppercase "$PLANT_TRIGRAM"; then
echo "The plant trigram should not contain uppercase characters. Please try again."
else
break
fi
done

# Ask the name of the site or plant
while true; do
read -p "Please enter the name of the facility or plant (example: Langres or Andance): " FACILITY_NAME
if is_FACILITY_name_valid "$FACILITY_NAME"; then
echo "The site name should contain the first letter uppercase. Please try again."
else
break
fi
done


# Prompt for database details
read -p "Please enter your MySQL root password: " MYSQL_ROOT_PASSWORD
read -p "Please enter your MySQL username: " MYSQL_USER
Expand Down Expand Up @@ -53,11 +87,9 @@ APP_SECRET=$(openssl rand -hex 16)

# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
webefnc:
image: ghcr.io/polangres/efnc:main
image: ghcr.io/${GITHUB_USER}/efnc:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
environment:
Expand Down Expand Up @@ -113,6 +145,9 @@ MYSQL_DATABASE=${MYSQL_DATABASE}
MYSQL_USER=${MYSQL_USER}
MYSQL_PASSWORD=${MYSQL_PASSWORD}
HOSTNAME=${HOSTNAME}
PLANT_TRIGRAM=${PLANT_TRIGRAM}
GITHUB_USER=${GITHUB_USER}
FACILITY_NAME=${FACILITY_NAME}
###> symfony/framework-bundle ###
APP_ENV=${APP_CONTEXT}
Expand Down Expand Up @@ -143,6 +178,7 @@ DATABASE_URL=mysql://root:\${MYSQL_ROOT_PASSWORD}@database/\${MYSQL_DATABASE}?se
###> symfony/mailer ###
MAILER_DSN=smtp://smtp.corp.ponet:25?verify_peer=0
MAILER_SENDER_EMAIL=${PLANT_TRIGRAM}[email protected]
###< symfony/mailer ###
EOL

Expand All @@ -158,11 +194,9 @@ sed -i "s|^# MAILER_DSN=.*|MAILER_DSN=smtp://smtp.corp.ponet:25?verify_peer=0|"

# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
web:
image: ghcr.io/polangres/efnc:main
image: ghcr.io/${GITHUB_USER}/efnc:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
environment:
Expand All @@ -184,7 +218,7 @@ ${PROXY_ENV}
EOL


sg docker -c "docker compose up --build -d"
sg docker -c "docker compose up --build &"

sleep 90

Expand All @@ -198,11 +232,9 @@ APP_CONTEXT="prod"

# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
web:
image: ghcr.io/polangres/efnc:main
image: ghcr.io/${GITHUB_USER}/efnc:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
environment:
Expand Down
52 changes: 44 additions & 8 deletions env_update.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
#!/bin/bash

# Get the github user from the argument
GITHUB_USER=$1
echo "GitHub User: $GITHUB_USER"

# function to check if the site name is valid and has the first letter uppercase
is_FACILITY_name_valid() {
[[ "$1" = ^[A-Z] ]]
}

# Ask the name of the site or plant
while true; do
read -p "Please enter the name of the facility or plant (example: Langres or Andance): " FACILITY_NAME
if is_FACILITY_name_valid "$FACILITY_NAME"; then
echo "The site name should contain the first letter uppercase. Please try again."
else
break
fi
done

# Function to check for uppercase characters
contains_uppercase() {
[[ "$1" =~ [A-Z] ]]
}

# Prompt for plant trigram
while true; do
read -p "Please enter your plant trigram (example: lan): " PLANT_TRIGRAM
if contains_uppercase "$PLANT_TRIGRAM"; then
echo "The plant trigram should not contain uppercase characters. Please try again."
else
break
fi
done

# Load the environment variables from the .env file
set -a # automatically export all variables
source .env
Expand Down Expand Up @@ -49,7 +83,13 @@ fi
APP_CONTEXT="dev"
sed -i "s|^APP_ENV=prod.*|APP_ENV=dev|" .env
sed -i "s|^# MAILER_DSN=.*|MAILER_DSN=smtp://smtp.corp.ponet:25?verify_peer=0|" .env
sed -i "s|^# MAILER_SENDER_EMAIL=.* |[email protected]|" .env
sed -i "s|^# MAILER_SENDER_EMAIL=.* |MAILER_SENDER_EMAIL=${PLANT_TRIGRAM}[email protected]|" .env
sed -i '/^MYSQL_PASSWORD=/a\
HOSTNAME='"$HOSTNAME"'\
PLANT_TRIGRAM='"$PLANT_TRIGRAM"'\
GITHUB_USER='"$GITHUB_USER"'\
FACILITY_NAME='"$FACILITY_NAME"'' .env

cat > src/Kernel.php <<EOL
<?php
Expand All @@ -73,11 +113,9 @@ EOL

# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
web:
image: ghcr.io/polangres/efnc:main
image: ghcr.io/${GITHUB_USER}/efnc:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
environment:
Expand All @@ -99,7 +137,7 @@ ${PROXY_ENV}
EOL


sg docker -c "docker compose up --build -d"
sg docker -c "docker compose up --build &"

sleep 90

Expand All @@ -113,11 +151,9 @@ APP_CONTEXT="prod"

# Create docker-compose.override.yml file to use the good entrypoint
cat > docker-compose.override.yml <<EOL
version: '3.8'
services:
web:
image: ghcr.io/polangres/efnc:main
image: ghcr.io/${GITHUB_USER}/efnc:main
restart: unless-stopped
entrypoint: "./${APP_CONTEXT}-entrypoint.sh"
environment:
Expand Down
59 changes: 48 additions & 11 deletions install-eFNC2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if [ "${ANSWER}" == "yes" ]
then

# Install git and PlasticOmnium docker repo
sudo yum install -y git;
sudo subscription-manager repo-override --repo=PlasticOmnium_Docker_Docker_CE_Stable --add=enabled:1;
sudo yum install -y git yum-utils;
sudo yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo;

# Remove old docker version and install docker-ce
sudo yum remove docker \
Expand All @@ -30,7 +30,7 @@ then
podman \
runc;

sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y;
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y;

# Add the user to the docker group
sudo groupadd docker;
Expand All @@ -43,23 +43,39 @@ sg docker -c "
sudo systemctl enable docker.service;
sudo systemctl enable containerd.service;"

# Function to check for uppercase characters
contains_uppercase() {
[[ "$1" =~ [A-Z] ]]
}

# Ask the user for name of its github user
while true; do
read -p "Name of your github user (example: polangres) : " GITHUB_USER
if contains_uppercase "$GITHUB_USER"; then
echo "The github user name should not contain uppercase characters. Please try again."
else
break
fi
done

# Ask the user for the git repository address either in ssh or http
read -p "Address of the git repository (ssh or http // default: https://github.com/polangres/efnc ) : " GIT_ADDRESS;
read -p "Address of the git repository (ssh or http // default: https://github.com/${GITHUB_USER}/efnc ) : " GIT_ADDRESS;
if [ -z "${GIT_ADDRESS}" ]
then
GIT_ADDRESS="https://github.com/polangres/efnc"
GIT_ADDRESS="https://github.com/${GITHUB_USER}/efnc"
fi

# Clone the git repository and run the env_create.sh script
git clone ${GIT_ADDRESS};

cd efnc;

bash ./env_create.sh;
bash ./env_create.sh ${GITHUB_USER};

# Build the docker containers
sg docker -c "docker compose up --build -d"
sg docker -c "docker compose up --build &"
else

# If the user answered no, we will ask if he wants to launch the app or if he wants to update it
while true; do
read -p "Do you wish to launch the app ? (yes/no) " LAUNCH_ANSWER;
Expand All @@ -69,6 +85,7 @@ while true; do
echo "Please answer by yes or no";
fi
done

# If the user answered yes, we launch the app
if [ "${LAUNCH_ANSWER}" == "yes" ]; then
cd efnc;
Expand All @@ -82,21 +99,41 @@ done
echo "Please answer by yes or no";
fi
done

if [ "${UPDATE_ANSWER}" == "yes" ]; then

# Function to check for uppercase characters
contains_uppercase() {
[[ "$1" =~ [A-Z] ]]
}

# Ask the user for name of its github user
while true; do
read -p "Name of your github user (example: polangres) : " GITHUB_USER
if contains_uppercase "$GITHUB_USER"; then
echo "The github user name should not contain uppercase characters. Please try again."
else
break
fi
done

# Ask the user for the git repository address either in ssh or http
read -p "Address of the git repository (ssh or http // default: https://github.com/polangres/efnc ) : " GIT_ADDRESS;
read -p "Address of the git repository (ssh or http // default: https://github.com/${GITHUB_USER}/efnc ) : " GIT_ADDRESS;
if [ -z "${GIT_ADDRESS}" ]
then
GIT_ADDRESS="https://github.com/polangres/efnc"
then
GIT_ADDRESS="https://github.com/${GITHUB_USER}/efnc"
fi
cd efnc;
sg docker -c "docker compose stop";
sg docker -c "docker system prune -fa";
git remote remove origin;
# Remove everything before https in the GIT_ADDRESS
GIT_ADDRESS=$(echo ${GIT_ADDRESS} | sed 's|.*\(https\)|\1|')
git remote add origin ${GIT_ADDRESS};
git fetch origin --force;
git reset --hard origin/main;
git pull --rebase origin main;
bash ./env_update.sh;
bash ./env_update.sh ${GITHUB_USER};
sg docker -c "docker compose up --build -d"
fi
fi
Expand Down

0 comments on commit b6450fd

Please sign in to comment.