diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..5ce3f43 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,43 @@ +name: Build and Push to Registry + +on: + push: + branches: [ cicd ] + +env: + REGISTRY: git.4nkweb.com + IMAGE_NAME: 4nk/ihm_client + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up SSH agent + uses: webfactory/ssh-agent@v0.9.1 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.USER }} + password: ${{ secrets.TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + ssh: default + build-args: | + ENV_VARS=${{ secrets.ENV_VARS }} + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8925bd5..cefaff8 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,61 @@ -FROM node:20 - -ENV TZ=Europe/Paris -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -# use this user because he have uid et gid 1000 like theradia -USER node - -WORKDIR /app - -CMD ["npm", "start"] -# "--disable-host-check", "--host", "0.0.0.0", "--ssl", "--ssl-cert", "/ssl/certs/site.crt", "--ssl-key", "/ssl/private/site.dec.key"] - +# syntax=docker/dockerfile:1.4 +FROM rust:1.82-alpine AS wasm-builder +WORKDIR /build + +# Installation des dépendances nécessaires pour la compilation +RUN apk update && apk add --no-cache \ + git \ + openssh-client \ + curl \ + nodejs \ + npm \ + build-base \ + pkgconfig \ + clang \ + llvm \ + musl-dev \ + nginx + +# Installation de wasm-pack +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + +# Configuration SSH basique +RUN mkdir -p /root/.ssh && \ + ssh-keyscan git.4nkweb.com >> /root/.ssh/known_hosts + +# On se place dans le bon répertoire parent +WORKDIR /build +# Copie du projet ihm_client +COPY . ihm_client/ + +# Clonage du sdk_client au même niveau que ihm_client en utilisant la clé SSH montée +RUN --mount=type=ssh git clone -b cicd ssh://git@git.4nkweb.com/4nk/sdk_client.git + +# Build du WebAssembly avec accès SSH pour les dépendances +WORKDIR /build/sdk_client +RUN --mount=type=ssh wasm-pack build --out-dir ../ihm_client/pkg --target bundler --dev + +FROM node:20-alpine +WORKDIR /app + +# Installation des dépendances nécessaires +RUN apk update && apk add --no-cache git nginx + +# Copie des fichiers du projet +COPY --from=wasm-builder /build/ihm_client/pkg ./pkg +COPY . . + +# Installation des dépendances Node.js +RUN npm install + +# Copie de la configuration nginx +COPY nginx.dev.conf /etc/nginx/http.d/default.conf + +# Script de démarrage +COPY start-dev.sh /start-dev.sh +RUN chmod +x /start-dev.sh + +EXPOSE 3003 80 + +CMD ["/start-dev.sh"] + diff --git a/nginx.dev.conf b/nginx.dev.conf new file mode 100644 index 0000000..c125de3 --- /dev/null +++ b/nginx.dev.conf @@ -0,0 +1,48 @@ +server { + listen 80; + server_name localhost; + + # Redirection des requêtes HTTP vers Vite + location / { + proxy_pass http://localhost:3003; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + + location /ws/ { + proxy_pass http://localhost:8090; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-NginX-Proxy true; + proxy_read_timeout 86400; + } + + location /storage/ { + rewrite ^/storage(/.*)$ $1 break; + proxy_pass http://localhost:8080; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + + location /api/ { + proxy_pass http://localhost:8091; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # CORS headers + add_header Access-Control-Allow-Origin "*" always; + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE" always; + add_header Access-Control-Allow-Headers "Authorization,Content-Type,Accept,X-Requested-With" always; + } +} \ No newline at end of file diff --git a/package.json b/package.json index e9bc61e..076150b 100755 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build_wasm": "wasm-pack build --out-dir ../ihm_client_dev3/pkg ../sdk_client --target bundler --dev", + "build_wasm": "wasm-pack build --out-dir ../ihm_client/pkg ../sdk_client --target bundler --dev", "start": "vite --host 0.0.0.0", "build": "tsc && vite build", "deploy": "sudo cp -r dist/* /var/www/html/", diff --git a/start-dev.sh b/start-dev.sh new file mode 100644 index 0000000..40ba375 --- /dev/null +++ b/start-dev.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Démarrer nginx en arrière-plan +nginx + +# Démarrer le serveur de développement Vite +npm run start \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index bd73a52..e842295 100755 --- a/vite.config.ts +++ b/vite.config.ts @@ -57,7 +57,7 @@ export default defineConfig({ fs: { cachedChecks: false, }, - port: 3004, + port: 3003, proxy: { '/storage': { target: 'https://demo.4nkweb.com',