diff --git a/.env.template b/.env.template index 1771b0ddd7123700a539a873be9ca5d6e5eb230c..6eff757694efae4006cac09ac11dbea8d7642627 100644 --- a/.env.template +++ b/.env.template @@ -5,7 +5,7 @@ ADMIN_ROLE=ADMINS DEBUG_MODE MOCK_OAUTH2 HTTPS_PORT -IMAGE_FOLDER +IMAGE_FOLDER=mnt/image-lib # Needed to user OAuth2 authentication : REDIRECT_URL diff --git a/.gitignore b/.gitignore index 8d832a6f90912a8b03b6949ed96ad8a6630c91a4..d2cb364414f9cf2390d2ef842be9fe3dfc97adcb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ .env backoffice.db -db_data/ \ No newline at end of file +db_data/ +mnt/ +__debug_bin* + +# Swagger documentation +docs/swagger.json +docs/swagger.yaml diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000000000000000000000000000000000..3ab34ffd7cbd31da6326bc575535ca07d690eaff --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Backoffice Server", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/main.go", + "envFile": "${workspaceFolder}/.env", + "showLog": true + } + ] +} diff --git a/Dockerfile b/Dockerfile index 21d3381156fb7154d0b2e9a5609a074f35978c24..f4efa81e01e91845d2e5aa036ec955ad556f9561 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,11 +28,6 @@ WORKDIR /app ADD . . -# Build Swagger documentation -RUN go install github.com/swaggo/swag/cmd/swag@latest -RUN go get github.com/swaggo/swag -RUN swag init -g ./internal/rootmux/rootmux.go - # Get dependencies and run tests RUN go version RUN go get -d -v @@ -43,6 +38,8 @@ RUN CGO_ENABLED=0 go build \ -ldflags='-w -s -extldflags "-static"' -a \ -o /app/backoffice-server . +RUN mkdir -p /app/mnt /app/mnt/configs + RUN chown -Rf "${UID}" ./* # Allow running on ports < 1000 @@ -67,9 +64,6 @@ COPY --from=builder /app/backoffice-server /app/backoffice-server COPY --from=builder /app/dev_certificates /app/dev_certificates COPY --from=builder /app/mnt/configs /app/mnt/configs -# Copy swagger documentation folder -COPY --from=builder /app/docs /app/docs - # Use an unprivileged user. USER appuser:appuser diff --git a/docker-compose.yml b/docker-compose.yml index e4a8d5a610e4fa1c361ea082835329b6ca9defba..374ce59b43dd396bdb72ce1b4dbd08fa215d5f17 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,36 +1,36 @@ -version: '3.1' +version: "3.1" -services: - database: - image: mysql:8 - healthcheck: - test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MYSQL_ROOT_PASSWORD - interval: 5s - timeout: 10s - retries: 60 - volumes: - - ./db_data:/var/lib/mysql - networks: - - ecolyo-agent-network - ports: - - 3306:3306 - environment: - MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} - MYSQL_DATABASE: ${DATABASE_NAME} +services: + database: + image: mysql:8 + healthcheck: + test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MYSQL_ROOT_PASSWORD + interval: 5s + timeout: 10s + retries: 60 + volumes: + - ./db_data:/var/lib/mysql + networks: + - ecolyo-agent-network + ports: + - 3306:3306 + environment: + MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} + MYSQL_DATABASE: ${DATABASE_NAME} - phpmyadmin: - image: phpmyadmin/phpmyadmin:latest - depends_on: - - database - networks: - - ecolyo-agent-network - ports: - - 8008:80 - environment: - PMA_HOST: database + phpmyadmin: + image: phpmyadmin/phpmyadmin:latest + depends_on: + - database + networks: + - ecolyo-agent-network + ports: + - 8008:80 + environment: + PMA_HOST: database volumes: - db_data: + db_data: networks: - ecolyo-agent-network: \ No newline at end of file + ecolyo-agent-network: diff --git a/mnt/configs/tokenskey.json b/mnt/configs/tokenskey.json deleted file mode 100644 index 3920d9ac878d69bc836ee66729cb1d027ed5b498..0000000000000000000000000000000000000000 --- a/mnt/configs/tokenskey.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Key": "2ioa6+gmlILIQcsG/HmBqDSsszPCe4GWKjCfyrtgLek=" -} \ No newline at end of file diff --git a/scripts/import-convert-assets.sh b/scripts/import-convert-assets.sh new file mode 100755 index 0000000000000000000000000000000000000000..6ebfa51ea3dde5594bff81715fd89bd8abfdb4af --- /dev/null +++ b/scripts/import-convert-assets.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# See https://stackoverflow.com/questions/24112727/relative-paths-based-on-file-location-instead-of-current-working-directory +WD=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$WD" + +# Get env variables +source ../.env + +REGISTRY_ID=409 +EMAIL_ASSETS_PATH="src/assets/icons/email" +ECOGESTURE_ASSETS_PATH="src/assets/icons/visu/ecogesture" + +# Clear folder +rm -rf ../$IMAGE_FOLDER + +# Create folder +mkdir -p ../$IMAGE_FOLDER ../$IMAGE_FOLDER/ecogesture + +# Fetch and convert email assets +curl "https://forge.grandlyon.com/api/v4/projects/${REGISTRY_ID}/repository/archive?path=${EMAIL_ASSETS_PATH}" --output email.tar.gz +tar -xf email.tar.gz +find *-email/$EMAIL_ASSETS_PATH -type f -name "*.svg" | while read -r svg_file; do + filename="$(basename "$svg_file" .svg)" + inkscape -h 200 -o ../$IMAGE_FOLDER/$filename.png *-email/$EMAIL_ASSETS_PATH/$filename.svg +done +rm *-email/$EMAIL_ASSETS_PATH/*.svg + +# Fetch and convert ecogesture assets +curl "https://forge.grandlyon.com/api/v4/projects/${REGISTRY_ID}/repository/archive?path=${ECOGESTURE_ASSETS_PATH}" --output ecogesture.tar.gz +tar -xf ecogesture.tar.gz +find *-ecogesture/$ECOGESTURE_ASSETS_PATH -type f -name "*.svg" | while read -r svg_file; do + filename="$(basename "$svg_file" .svg)" + inkscape -h 200 -o ../$IMAGE_FOLDER/ecogesture/$filename.png *-ecogesture/$ECOGESTURE_ASSETS_PATH/$filename.svg +done +rm *-ecogesture/$ECOGESTURE_ASSETS_PATH/*.svg + +# Cleanup +rm -rf email.tar.gz ecogesture.tar.gz *-email *-ecogesture diff --git a/scripts/init-fluidprices.sh b/scripts/init-fluidprices.sh new file mode 100755 index 0000000000000000000000000000000000000000..89e01f52f8026f64ae3117b8b2963c72477b8595 --- /dev/null +++ b/scripts/init-fluidprices.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# See https://stackoverflow.com/questions/24112727/relative-paths-based-on-file-location-instead-of-current-working-directory +WD=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$WD/.." + +source .env + +# REMOVE PRICES TABLE +docker compose exec database mysql -u${DATABASE_USER} -p${DATABASE_PASSWORD} -e "use $DATABASE_NAME; DROP TABLE prices;" +echo "Prices database dropped" + +# CREATE PRICES TABLE +docker compose exec database mysql -u${DATABASE_USER} -p${DATABASE_PASSWORD} -e "use $DATABASE_NAME; CREATE TABLE prices ( + id int(11) NOT NULL, + fluid_type bigint(20) DEFAULT NULL, + price float DEFAULT NULL, + start_date longtext, + end_date longtext, + created_at datetime(3) DEFAULT NULL, + updated_at datetime(3) DEFAULT NULL, + deleted_at datetime(3) DEFAULT NULL +);" +echo "Prices database created" + +# POPULATE PRICES TABLE +docker compose exec database mysql -u${DATABASE_USER} -p${DATABASE_PASSWORD} -e "use $DATABASE_NAME; INSERT INTO prices (id, fluid_type, price, start_date, end_date) VALUES + (1,0,0.1256,'2012-07-23 00:00:00','2013-07-31 23:59:59'), + (2,0,0.1329,'2013-08-01 00:00:00','2014-10-31 23:59:59'), + (3,0,0.1401,'2014-01-11 00:00:00','2015-07-31 23:59:59'), + (4,0,0.1437,'2015-08-01 00:00:00','2016-07-31 23:59:59'), + (5,0,0.1503,'2016-08-01 00:00:00','2017-07-31 23:59:59'), + (6,0,0.1546,'2017-08-01 00:00:00','2018-01-31 23:59:59'), + (7,0,0.1555,'2018-02-01 00:00:00','2018-07-31 23:59:59'), + (8,0,0.145,'2018-08-01 00:00:00','2019-05-31 23:59:59'), + (9,0,0.1531,'2019-02-01 00:00:00','2019-07-31 23:59:59'), + (10,0,0.1524,'2019-08-01 00:00:00','2020-01-31 23:59:59'), + (11,0,0.1546,'2020-02-01 00:00:00','2020-07-31 23:59:59'), + (12,0,0.1557,'2020-08-01 00:00:00','2021-01-31 23:59:59'), + (13,0,0.1582,'2021-02-01 00:00:00','2021-07-31 23:59:59'), + (14,0,0.1558,'2021-08-01 00:00:00','2022-01-31 23:59:59'), + (15,0,0.174,'2022-02-01 00:00:00',NULL), + (16,1,0.0030735,'2012-01-01 00:00:00','2012-12-31 23:59:59'), + (17,1,0.0031483,'2013-01-01 00:00:00','2013-12-31 23:59:59'), + (18,1,0.0031381,'2014-01-01 00:00:00','2014-12-31 23:59:59'), + (19,1,0.00307,'2015-01-01 00:00:00','2015-12-31 23:59:59'), + (20,1,0.0031,'2016-01-01 00:00:00','2016-12-31 23:59:59'), + (21,1,0.00311,'2017-01-01 00:00:00','2017-12-31 23:59:59'), + (22,1,0.00313,'2018-01-01 00:00:00','2018-12-31 23:59:59'), + (23,1,0.00313,'2019-01-01 00:00:00','2019-12-31 23:59:59'), + (24,1,0.00315,'2020-01-01 00:00:00','2020-12-31 23:59:59'), + (25,1,0.00319,'2021-01-01 00:00:00',NULL), + (26,2,0.0919,'2017-01-01 00:00:00','2017-01-31 23:59:59'), + (27,2,0.0915,'2017-02-01 00:00:00','2017-02-28 23:59:59'), + (28,2,0.0932,'2017-03-01 00:00:00','2017-03-31 23:59:59'), + (29,2,0.0927,'2017-04-01 00:00:00','2017-04-30 23:59:59'), + (30,2,0.0906,'2017-05-01 00:00:00','2017-05-31 23:59:59'), + (31,2,0.0906,'2017-06-01 00:00:00','2017-06-30 23:59:59'), + (32,2,0.0788,'2017-07-01 00:00:00','2017-07-31 23:59:59'), + (33,2,0.0783,'2017-08-01 00:00:00','2017-08-31 23:59:59'), + (34,2,0.0783,'2017-09-01 00:00:00','2017-09-30 23:59:59'), + (35,2,0.0791,'2017-10-01 00:00:00','2017-10-31 23:59:59'), + (36,2,0.0806,'2017-11-01 00:00:00','2017-11-30 23:59:59'), + (37,2,0.0812,'2017-12-01 00:00:00','2017-12-31 23:59:59'), + (38,2,0.0857,'2018-01-01 00:00:00','2018-01-31 23:59:59'), + (39,2,0.0866,'2018-02-01 00:00:00','2018-02-28 23:59:59'), + (40,2,0.0847,'2018-03-01 00:00:00','2018-03-31 23:59:59'), + (41,2,0.0839,'2018-04-01 00:00:00','2018-04-30 23:59:59'), + (42,2,0.0842,'2018-05-01 00:00:00','2018-05-31 23:59:59'), + (43,2,0.0855,'2018-06-01 00:00:00','2018-06-30 23:59:59'), + (44,2,0.0959,'2018-07-01 00:00:00','2018-07-31 23:59:59'), + (45,2,0.0961,'2018-08-01 00:00:00','2018-08-31 23:59:59'), + (46,2,0.0967,'2018-09-01 00:00:00','2018-09-30 23:59:59'), + (47,2,0.0989,'2018-10-01 00:00:00','2018-10-31 23:59:59'), + (48,2,0.1031,'2018-11-01 00:00:00','2018-11-30 23:59:59'), + (49,2,0.1013,'2018-12-01 00:00:00','2018-12-31 23:59:59'), + (50,2,0.0999,'2019-01-01 00:00:00','2019-01-31 23:59:59'), + (51,2,0.0993,'2019-02-01 00:00:00','2019-02-28 23:59:59'), + (52,2,0.0993,'2019-03-01 00:00:00','2019-03-31 23:59:59'), + (53,2,0.0977,'2019-04-01 00:00:00','2019-04-30 23:59:59'), + (54,2,0.0973,'2019-05-01 00:00:00','2019-05-31 23:59:59'), + (55,2,0.0969,'2019-06-01 00:00:00','2019-06-30 23:59:59'), + (56,2,0.0795,'2019-07-01 00:00:00','2019-07-31 23:59:59'), + (57,2,0.0791,'2019-08-01 00:00:00','2019-08-31 23:59:59'), + (58,2,0.0785,'2019-09-01 00:00:00','2019-09-30 23:59:59'), + (59,2,0.077,'2019-10-01 00:00:00','2019-10-31 23:59:59'), + (60,2,0.0789,'2019-11-01 00:00:00','2019-11-30 23:59:59'), + (61,2,0.0793,'2019-12-01 00:00:00','2019-12-31 23:59:59'), + (62,2,0.0787,'2020-01-01 00:00:00','2020-01-31 23:59:59'), + (63,2,0.0765,'2020-02-01 00:00:00','2020-02-29 23:59:59'), + (64,2,0.0736,'2020-03-01 00:00:00','2020-03-31 23:59:59'), + (65,2,0.071,'2020-04-01 00:00:00','2020-04-30 23:59:59'), + (66,2,0.0703,'2020-05-01 00:00:00','2020-05-31 23:59:59'), + (67,2,0.0687,'2020-06-01 00:00:00','2020-06-30 23:59:59'), + (68,2,0.0698,'2020-07-01 00:00:00','2020-07-31 23:59:59'), + (69,2,0.0705,'2020-08-01 00:00:00','2020-08-31 23:59:59'), + (70,2,0.0709,'2020-09-01 00:00:00','2020-09-30 23:59:59'), + (71,2,0.0735,'2020-10-01 00:00:00','2020-10-31 23:59:59'), + (72,2,0.0745,'2020-11-01 00:00:00','2020-11-30 23:59:59'), + (73,2,0.0759,'2020-12-01 00:00:00','2020-12-31 23:59:59'), + (74,2,0.076,'2021-01-01 00:00:00','2021-01-31 23:59:59'), + (75,2,0.0782,'2021-02-01 00:00:00','2021-02-28 23:59:59'), + (76,2,0.0818,'2021-03-01 00:00:00','2021-03-31 23:59:59'), + (77,2,0.079,'2021-04-01 00:00:00','2021-04-30 23:59:59'), + (78,2,0.0797,'2021-05-01 00:00:00','2021-05-31 23:59:59'), + (79,2,0.0826,'2021-06-01 00:00:00','2021-06-30 23:59:59'), + (80,2,0.0895,'2021-07-01 00:00:00','2021-07-31 23:59:59'), + (81,2,0.0934,'2021-08-01 00:00:00','2021-08-31 23:59:59'), + (82,2,0.1002,'2021-09-01 00:00:00','2021-09-30 23:59:59'), + (83,2,0.1121,'2021-10-01 00:00:00',NULL) +;" +echo "Prices database populated" diff --git a/scripts/init-swagger-doc.sh b/scripts/init-swagger-doc.sh new file mode 100755 index 0000000000000000000000000000000000000000..e8f11ada3741d307066dd4062202aa204a58dc16 --- /dev/null +++ b/scripts/init-swagger-doc.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# See https://stackoverflow.com/questions/24112727/relative-paths-based-on-file-location-instead-of-current-working-directory +WD=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) +cd "$WD/.." + +source .env + +# Build documentation +swag init -g ./internal/rootmux/rootmux.go + +# Keep only swagger.json and swagger.yaml +rm ./docs/docs.go