From a0af95eeebb022ca44a497f13eed4395906a7071 Mon Sep 17 00:00:00 2001
From: Mickael MASQUELIN <mickael.masquelin@univ-lille.fr>
Date: Wed, 7 Jun 2023 09:33:29 +0200
Subject: [PATCH] feat(exemples-packer): Fixes sur les templates Ubuntu jammy

---
 .../ubuntu-jammy-base-shell-prov.pkr.hcl      | 29 ++++++++++++++-----
 exemples-packer/ubuntu-jammy-base.pkr.hcl     |  3 ++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/exemples-packer/ubuntu-jammy-base-shell-prov.pkr.hcl b/exemples-packer/ubuntu-jammy-base-shell-prov.pkr.hcl
index 47c7664..68a4e6f 100644
--- a/exemples-packer/ubuntu-jammy-base-shell-prov.pkr.hcl
+++ b/exemples-packer/ubuntu-jammy-base-shell-prov.pkr.hcl
@@ -2,6 +2,17 @@
 source "docker" "ubu-form-cnrs-nginx" {
     image = "ubuntu:jammy"
     commit = true
+    run_command = [
+      "-d", "-i", "-t", "{{.Image}}", "/bin/bash"
+    ]
+    changes = [
+      "WORKDIR /var/www/html",
+      "ENV HOSTNAME localhost",
+      "EXPOSE 80 443",
+      "LABEL version=1.0.0",
+      "ONBUILD RUN date",
+      "ENTRYPOINT [\"nginx\", \"-g\", \"daemon off;\"]",
+    ]
 }
 
 # Construire l'image "personnalisée"
@@ -16,22 +27,24 @@ build {
       "DEBIAN_FRONTEND=noninteractive apt-get -qq -y install curl nginx",
       "apt-get clean autoclean",
       "apt-get autoremove --yes",
-      "rm -fr /var/lib/apt/lists/*"
+      "rm -fr /var/lib/apt/lists/*",
       # commande à éviter  ci-après : vous  ne  
       # gagnez que  quelques Ko  et plus  rien 
       # ne peut dériver de cette image de base 
       # rm -rf /var/lib/{apt,dpkg,cache,log}/
+      "ln -sf /dev/stdout /var/log/nginx/access.log",
+      "ln -sf /dev/stderr /var/log/nginx/error.log",
     ]
   }
 
-  # Tag de l'image Docker créé
+  # Tag de l'image Docker créé + personnalisation
   post-processors {
-    post-processor "docker-tag" {
-      repository =  "local/ubu-form-cnrs-nginx"
-      tags = [
-        "22.04.2",
-        "latest"
-      ]
+      post-processor "docker-tag" {
+        repository = "local/ubu-form-cnrs-nginx"
+        tags = [
+          "22.04.2",
+          "latest"
+        ]
     }
   }
 }
\ No newline at end of file
diff --git a/exemples-packer/ubuntu-jammy-base.pkr.hcl b/exemples-packer/ubuntu-jammy-base.pkr.hcl
index 36083eb..8c20711 100644
--- a/exemples-packer/ubuntu-jammy-base.pkr.hcl
+++ b/exemples-packer/ubuntu-jammy-base.pkr.hcl
@@ -2,6 +2,9 @@
 source "docker" "ubuntu-formation-cnrs" {
     image = "ubuntu:jammy"
     commit = true
+    run_command = [
+      "-d", "-i", "-t", "{{.Image}}", "/bin/bash"
+    ]
 }
 
 # Construire l'image "personnalisée"
-- 
GitLab