From 012342e74763b057a995deaa64644cc11c38c039 Mon Sep 17 00:00:00 2001 From: Yanis HESSINI <yanis@Yanis-LAPTOP> Date: Thu, 17 Nov 2022 17:25:58 +0100 Subject: [PATCH] Dockerfiles et initialisation pgsql --- .gitignore | 4 ++-- docker-compose.yml | 15 ++++++++++----- Dockerfile => dockerfile_php | 0 dockerfile_postgres | 2 ++ pgsql-scripts/datapostgres.sql | 14 ++++++++++++++ www/data/memo.json | 2 +- www/index.php | 2 +- 7 files changed, 30 insertions(+), 9 deletions(-) rename Dockerfile => dockerfile_php (100%) create mode 100644 dockerfile_postgres create mode 100644 pgsql-scripts/datapostgres.sql diff --git a/.gitignore b/.gitignore index 507df56..3d331fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -./log/access.log -./log/error.log +log/access.log +log/error.log diff --git a/docker-compose.yml b/docker-compose.yml index 0fb22a3..937ceab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,8 @@ services: - databases php: - build: . + build: + dockerfile: dockerfile_php container_name: php-memo volumes: - "./www:/script" @@ -23,19 +24,23 @@ services: - databases postgresql-memo: - image: postgres:latest + build: + dockerfile: dockerfile_postgres restart: unless-stopped container_name: postgresql-memo environment: - POSTGRES_USER: user + POSTGRES_USER: admin POSTGRES_PASSWORD: password ports: - published: 5432 target: 5432 volumes: - - postgres_data:/var/lib/postgresdata/data:rw + - "./pgsql-scripts:/docker-entrypoint-initdb.d" + - "postgres_data:/var/lib/postgresql/data" networks: - databases + # command: echo "fuck" & + # command: psql -U user -d postgres -f postgresqldata/data/datapostgres.sql redis-memo: image: redis:latest @@ -45,7 +50,7 @@ services: - published: 6379 target: 6379 volumes: - - redis_data:/var/lib/redisdata/data:rw + - ./www/data/redis_data:/redisdata/data:rw networks: - databases diff --git a/Dockerfile b/dockerfile_php similarity index 100% rename from Dockerfile rename to dockerfile_php diff --git a/dockerfile_postgres b/dockerfile_postgres new file mode 100644 index 0000000..68cd105 --- /dev/null +++ b/dockerfile_postgres @@ -0,0 +1,2 @@ +FROM postgres:latest +USER postgres \ No newline at end of file diff --git a/pgsql-scripts/datapostgres.sql b/pgsql-scripts/datapostgres.sql new file mode 100644 index 0000000..16d2be4 --- /dev/null +++ b/pgsql-scripts/datapostgres.sql @@ -0,0 +1,14 @@ +\c postgres; + +DROP TABLE IF EXISTS "taches"; +CREATE TABLE "public"."taches" ( + "id" text NOT NULL, + "texte" text NOT NULL, + "accomplie" boolean NOT NULL, + "date_ajout" text NOT NULL +) WITH (oids = false); + +INSERT INTO "taches" ("id", "texte", "accomplie", "date_ajout") VALUES +('6376542bcaa53', 'finir le projet de nosql', '0', '2022-11-17 15:32:59'), +('6376543154534', 'apprécier la puissance de docker', '0', '2022-11-17 15:33:05'), +('6376543653b77', 'finir la présentation en anglais', '0', '2022-11-17 15:33:10'); diff --git a/www/data/memo.json b/www/data/memo.json index 8471fbd..7667064 100644 --- a/www/data/memo.json +++ b/www/data/memo.json @@ -1 +1 @@ -{"5defb94651ea3":{"texte":"finir le tp de prog web","accomplie":true,"dateAjout":"2019-12-10T15:27:02.000Z"},"5defb9a88e9a3":{"texte":"finir le tp d'animation ","accomplie":false,"dateAjout":"2019-12-10T15:28:40.000Z"},"5defbc36499e1":{"texte":"finir le tp de design","accomplie":true,"dateAjout":"2019-12-10T15:39:34.000Z"},"5defbc4b20c23":{"texte":"finir le tp de bdd","accomplie":false,"dateAjout":"2019-12-10T15:39:55.000Z"},"5defbc7418ff8":{"texte":"finir le tp de vid\u00e9o ","accomplie":true,"dateAjout":"2019-12-10T15:40:36.000Z"},"63763c41d6d4f":{"texte":"pr\u00e9parer la pr\u00e9sentation d'anglais","accomplie":true,"dateAjout":"2022-11-17 13:50:57"},"63764775e6206":{"texte":"finir projet nosql","accomplie":false,"dateAjout":"2022-11-17 14:38:45"},"637648750c469":{"texte":"finir projet web services","accomplie":false,"dateAjout":"2022-11-17 14:43:01"},"637648842e03f":{"texte":"appr\u00e9cier la puissance de docker","accomplie":false,"dateAjout":"2022-11-17 14:43:16"}} \ No newline at end of file +{"5defb94651ea3":{"texte":"finir le tp de prog web","accomplie":true,"dateAjout":"2019-12-10T15:27:02.000Z"},"5defb9a88e9a3":{"texte":"finir le tp d'animation ","accomplie":false,"dateAjout":"2019-12-10T15:28:40.000Z"},"5defbc36499e1":{"texte":"finir le tp de design","accomplie":true,"dateAjout":"2019-12-10T15:39:34.000Z"},"5defbc4b20c23":{"texte":"finir le tp de bdd","accomplie":false,"dateAjout":"2019-12-10T15:39:55.000Z"},"5defbc7418ff8":{"texte":"finir le tp de vid\u00e9o ","accomplie":true,"dateAjout":"2019-12-10T15:40:36.000Z"},"63763c41d6d4f":{"texte":"pr\u00e9parer la pr\u00e9sentation d'anglais","accomplie":true,"dateAjout":"2022-11-17 13:50:57"},"63764775e6206":{"texte":"finir projet nosql","accomplie":false,"dateAjout":"2022-11-17 14:38:45"},"637648750c469":{"texte":"finir projet web services","accomplie":false,"dateAjout":"2022-11-17 14:43:01"},"637648842e03f":{"texte":"appr\u00e9cier la puissance de docker","accomplie":false,"dateAjout":"2022-11-17 14:43:16"},"637652f339886":{"texte":"finir le projet nosql","accomplie":false,"dateAjout":"2022-11-17 15:27:47"},"6376543653b77":{"texte":"finir la pr\u00e9sentation en anglais","accomplie":false,"dateAjout":"2022-11-17 15:33:10"},"6376587328a8d":{"texte":"test","accomplie":false,"dateAjout":"2022-11-17 15:51:15"},"6376543154534":{"accomplie":true}} \ No newline at end of file diff --git a/www/index.php b/www/index.php index 6459625..48c81d6 100644 --- a/www/index.php +++ b/www/index.php @@ -25,7 +25,7 @@ // Connexion à la base de données PostgreSQL $config = "pgsql:host=postgresql-memo;port=5432;dbname=postgres"; -$username = "user"; +$username = "admin"; $password = "password"; $db_connection = new PDO($config, $username, $password); -- GitLab