Compare commits

4 Commits

Author SHA1 Message Date
Florian THIERRY
1b92fd269e Fix config. 2024-09-19 22:24:39 +02:00
Florian THIERRY
23025e3606 Fix fucking MIME types of javascript files. 2024-09-19 22:13:10 +02:00
Florian THIERRY
38c11e2d9f gitignore. 2024-09-19 18:03:33 +02:00
Florian THIERRY
610723c561 CI/CD drafting. 2024-09-19 18:03:23 +02:00
10 changed files with 186 additions and 8 deletions

4
.gitignore vendored
View File

@@ -81,4 +81,6 @@ testem.log
# System files
.DS_Store
Thumbs.db
Thumbs.db
**/ci/bin/

View File

@@ -41,6 +41,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -3,6 +3,10 @@ application:
path: /home/florian/Developpement/codiki-hexagonal/backend/pictures-folder/
temp-path : /home/florian/Developpement/codiki-hexagonal/backend/pictures-folder/temp/
logging:
level:
org.springframework.security: DEBUG
server:
port: 8987

View File

@@ -0,0 +1,13 @@
application:
pictures:
path: /opt/codiki/pictures/
temp-path: /opt/codiki/pictures/temp/
server:
port: 8080
spring:
datasource:
url: jdbc:postgresql://codiki-database:5432/codiki_db
username: codiki_user
password: password

View File

@@ -9,10 +9,6 @@ application:
path: /opt/codiki/pictures/
temp-path: /opt/codiki/pictures/temp/
logging:
level:
org.springframework.security: DEBUG
server:
http2:
enabled: true

95
ci.bash Normal file
View File

@@ -0,0 +1,95 @@
#!/bin/bash
SERVER_CODIKI_ROOT_FOLDER='/home/florian/codiki-hexagonal'
SERVER_ADDRESS='192.168.0.153'
SERVER_USER='florian'
SERVER_PORT='22'
function handle_error() {
local resultCode=$1
if [[ $resultCode -ne 0 ]]
then
echo "$errorMessage"
echo
exit 1
else
echo 'Operation succeded.'
echo
fi
}
function change_configuration_files() {
echo 'Copy production configuration file of backend...'
cp ./ci/configuration/backend/application-prod.yml ./backend/codiki-launcher/src/main/resources/application-prod.yml
handle_error $?
}
function build_backend() {
echo 'Backend docker image building...'
docker build -t codiki-backend -f ./Dockerfile-backend . --no-cache
handle_error $?
}
function build_frontend() {
echo 'Frontend docker image building...'
docker build -t codiki-frontend -f ./Dockerfile-frontend . --no-cache
handle_error $?
}
function extract_docker_images() {
echo 'Extraction of backend docker image into an archive...'
docker save codiki-backend:latest -o ./ci/bin/codiki-backend.tar
handle_error $?
echo 'Extraction of frontend docker image into an archive...'
docker save codiki-frontend:latest -o ./ci/bin/codiki-frontend.tar
handle_error $?
}
function copy_docker_compose_file_in_bin_folder() {
echo 'Copy of docker compose file in bin folder...'
cp ./docker-compose.yml ./ci/bin/docker-compose.yml
handle_error $?
}
function upload_files_on_server() {
echo 'Sending of docker images on server'
scp -P $SERVER_PORT ./ci/bin/* $SERVER_USER@$SERVER_ADDRESS:$SERVER_CODIKI_ROOT_FOLDER/
handle_error $?
}
# execute_remote_command_on_server
function ercos() {
local command=$1
ssh -p $SERVER_PORT -l $SERVER_USER $SERVER_ADDRESS $command
handle_error $1
}
function deploy_docker_images_on_server() {
echo 'Import backend docker image archive on server...'
ercos "docker load < $SERVER_CODIKI_ROOT_FOLDER/codiki-backend.tar"
echo 'Import frontend docker image archive on server...'
ercos "docker load < $SERVER_CODIKI_ROOT_FOLDER/codiki-frontend.tar"
}
function restart_services() {
echo 'Stop services on server...'
ercos "cd $SERVER_CODIKI_ROOT_FOLDER && docker compose down"
echo 'Start services on server...'
ercos "cd $SERVER_CODIKI_ROOT_FOLDER && docker compose up --detach"
}
function main() {
change_configuration_files
build_backend
build_frontend
extract_docker_images
copy_docker_compose_file_in_bin_folder
upload_files_on_server
deploy_docker_images_on_server
restart_services
}
main

View File

@@ -0,0 +1,13 @@
application:
pictures:
path: /opt/codiki/pictures/
temp-path: /opt/codiki/pictures/temp/
server:
port: 8080
spring:
datasource:
url: jdbc:postgresql://codiki-database:5432/codiki_db
username: codiki_user
password: password

38
docker-compose.yml Normal file
View File

@@ -0,0 +1,38 @@
services:
codiki-database:
image: "postgres:16"
container_name: "codiki-database"
ports:
- "50010:5432"
networks:
- "codiki-network"
environment:
POSTGRES_DB: codiki_db
POSTGRES_USER: codiki_admin
POSTGRES_PASSWORD: password
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- "./docker/postgresql/pgdata:/var/lib/postgresql/data/pgdata"
codiki-backend:
image: codiki-backend:latest
container_name: "codiki-backend"
environment:
- "SPRING_PROFILES_ACTIVE=prod"
ports:
- "50011:8080"
volumes:
- "/opt/codiki/pictures:/opt/codiki/pictures"
networks:
- "codiki-network"
codiki-frontend:
image: codiki-frontend:latest
container_name: "codiki-frontend"
ports:
- "50012:80"
networks:
- "codiki-network"
networks:
codiki-network:

View File

@@ -9,6 +9,12 @@ http {
~*^en en;
}
types {
module js;
}
include /etc/nginx/mime.types;
server {
listen 80;
server_name codiki.org;
@@ -38,7 +44,7 @@ http {
}
location ~ ^/api {
proxy_pass http://codiki-backend:8080;
proxy_pass http://192.168.0.153:50011;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;

View File

@@ -7,8 +7,8 @@
"start-en": "ng serve --port 4201 --configuration=en --proxy-config proxy.conf.json",
"start-fr": "ng serve --port 4201 --configuration=fr --proxy-config proxy.conf.json",
"build": "ng build",
"build-prod-en": "ng build --configuration=production-en --base-href",
"build-prod-fr": "ng build --configuration=production-fr --base-href",
"build-prod-en": "ng build --configuration=production-en --base-href /en/",
"build-prod-fr": "ng build --configuration=production-fr --base-href /fr/",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"i18n": "ng extract-i18n --output-path src/locale --format=json"