From a734c109f3b5aef893b5694d44c516f606096adc Mon Sep 17 00:00:00 2001
From: Matthieu Benoist <matthieu.benoist@randstaddigital.fr>
Date: Wed, 16 Apr 2025 12:24:33 +0200
Subject: [PATCH] Adds dev environnemnt and ci/cd

---
 .env.example       |  4 ++++
 .gitignore         |  2 +-
 .gitlab-ci.yml     | 36 +++++++++++++++++++++++++++++++++++
 Makefile           | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 docker-compose.yml | 21 +++++++++++++++++++++
 5 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 .env.example
 create mode 100644 .gitlab-ci.yml
 create mode 100644 Makefile
 create mode 100644 docker-compose.yml

diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..f76bf0f
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,4 @@
+
+PROJECT_NAME=Jeu
+PROJECT_HOSTNAME=jeu.grandlyon.localhost
+CERT_SIZE=1
diff --git a/.gitignore b/.gitignore
index f996257..ecdc479 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,7 +37,7 @@ package-lock.json
 /libpeerconnection.log
 testem.log
 /typings
-
+/.env
 # System files
 .DS_Store
 Thumbs.db
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..17862bf
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,36 @@
+image: node:20
+
+stages:
+  - build
+  - release
+
+# Build job
+build:
+  stage: build
+  script:
+    - npm install                # install deps
+    - npm run build         # Compile 
+  artifacts:
+    paths:
+      - dist/               # we save the compiled files in an artefact
+    expire_in: 1 day
+  only:
+    - tags                  # triggered with tag 
+
+# Release job
+release:
+  stage: release
+  needs: [build]            
+  image: registry.gitlab.com/gitlab-org/release-cli:latest
+  script:
+    - echo "Création de la release pour le tag $CI_COMMIT_TAG"
+  release:
+    tag_name: $CI_COMMIT_TAG
+    name: "Release $CI_COMMIT_TAG"
+    description: "Release générée automatiquement pour le tag $CI_COMMIT_TAG"
+    assets:
+      links:
+        - name: "Télécharger la version compilée"
+          url: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_TAG}/download?job=build"
+  only:
+    - tags
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..78a4d8d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,47 @@
+
+ifneq (,$(wildcard ./.env))
+	include .env
+endif
+
+.PHONY: config
+config:
+	cp .env.example .env
+
+
+# Docker
+up:
+	docker compose up -d
+
+down:
+	docker compose down
+
+ps:
+	docker compose ps
+
+rebuild:
+	docker compose down --remove-orphans
+	docker compose build --no-cache
+	docker compose up -d
+
+
+# Mkcert
+
+define config_toml
+[[tls.certificates]]
+certFile = "/certs/${PROJECT_HOSTNAME}+${CERT_SIZE}.pem"
+keyFile = "/certs/${PROJECT_HOSTNAME}+${CERT_SIZE}-key.pem"
+endef
+
+export config_toml
+
+npm-install: 
+	docker compose run --rm node npm install
+
+certs:
+	mkdir -p ${HOME}/.dockerdev/traefik/certs ${HOME}/.dockerdev/traefik/conf
+	mkcert ${PROJECT_HOSTNAME} *.${PROJECT_HOSTNAME} ${CERT_ALIASES}
+	mv *.pem ~/.dockerdev/traefik/certs
+	@echo "$$config_toml" > ~/.dockerdev/traefik/conf/${PROJECT_NAME}-certs.toml
+
+install: config certs up
+
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..547c3b6
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,21 @@
+services:
+  node:
+    image: trion/ng-cli:17.2.1
+    restart: unless-stopped
+    volumes:
+      - ./:/app
+    working_dir: /app
+    command: ng serve --host 0.0.0.0 --port 4200
+    networks:
+      - webgateway
+    labels:
+      - "traefik.enable=true"
+      - "traefik.http.routers.${PROJECT_NAME}-front.rule=Host(`${PROJECT_HOSTNAME}`)"
+      - "traefik.http.routers.${PROJECT_NAME}-front.tls=true"
+      - "traefik.http.routers.${PROJECT_NAME}-front.entrypoints=websecure"
+      - "traefik.http.services.${PROJECT_NAME}-front.loadbalancer.server.port=4200"
+
+networks:
+  webgateway:
+    external: true
+
-- 
GitLab