changements dans les dockerfiles + ajout de quelques trucs pour svelte en PoC

This commit is contained in:
batche
2022-11-14 16:02:54 +01:00
parent 8b4545f4d6
commit aa3eb111c1
15 changed files with 213 additions and 320 deletions

View File

@@ -17,14 +17,11 @@ prod:
start:
docker compose -f ${DOCKERCOMPOSEPATH} start
docker logs --follow nestjs_api_back_dev
docker logs --follow srcs-backend_dev-1
start_dev:
docker compose -f ${DOCKERCOMPOSEPATH} start dev
docker logs --follow nestjs_api_back_dev
start_debug:
docker compose -f ${DOCKERCOMPOSEPATH} start debug
docker logs --follow srcs-backend_dev-1
start_prod:
docker compose -f ${DOCKERCOMPOSEPATH} start prod

View File

@@ -1,154 +1,77 @@
services:
backend_dev:
container_name: nestjs_api_back_dev
image: nestjs_api_back_dev
build:
context: ./requirements/nestjs
target: development
dockerfile: Dockerfile
command: npm run start:dev
networks:
- transcendance_network
volumes:
- ./requirements/nestjs/api_back:/usr/src/app
- /usr/src/app/node_modules
env_file:
- .env
environment:
NODE_ENV: "${NODE_ENV}"
restart: unless-stopped
depends_on:
- postgresql
- redis
backend_dev:
build:
context: ./requirements/nestjs
target: development
dockerfile: Dockerfile
volumes:
- ./requirements/nestjs/api_back/src:/usr/app/src
- ./requirements/nestjs/api_back/test:/usr/app/test/
env_file:
- .env
environment:
NODE_ENV: "${NODE_ENV}"
restart: unless-stopped
depends_on:
- postgresql
- redis
# backend_prod:
# container_name: nestjs_api_back_prod
# image: nestjs_api_back_prod
# build:
# context: ./requirements/nestjs
# target: production
# dockerfile: Dockerfile
# command: npm run start:prod
# ports:
# - 3000:3000
# networks:
# - transcendance_network
# volumes:
# - data_nest_back:/usr/src/app
# - /usr/src/app/node_modules
# restart: unless-stopped
# env_file:
# - .env
# environment:
# NODE_ENV: "${NODE_ENV}"
# depends_on:
# - postgresql
# - redis
frontend_dev:
build:
context: ./requirements/svelte
target: development
dockerfile: Dockerfile
volumes:
- ./requirements/svelte/api_front/src:/usr/app/src/
- ./requirements/svelte/api_front/public:/usr/app/public/
env_file:
- .env
environment:
NODE_ENV: "${NODE_ENV}"
restart: unless-stopped
depends_on:
- postgresql
- redis
- backend_dev
frontend_dev:
container_name: nestjs_api_front_dev
image: nestjs_api_front_dev
build:
context: ./requirements/svelte
target: development
dockerfile: Dockerfile
command: npm run dev
networks:
- transcendance_network
volumes:
- ./requirements/svelte/api_front:/usr/src/app
- /usr/src/app/node_modules
env_file:
- .env
environment:
NODE_ENV: "${NODE_ENV}"
restart: unless-stopped
depends_on:
- postgresql
- redis
- backend_dev
# t'embete pas a gerer ton propre container nginx
nginx:
image: nginx:alpine
restart: unless-stopped
volumes:
- ./requirements/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf:ro
command: [nginx-debug, "-g", "daemon off;"]
ports:
- "8080:8080"
depends_on:
- backend_dev
- frontend_dev
- postgresql
- redis
nginx:
container_name: nginx
build:
context: ./requirements/nginx
dockerfile: Dockerfile
ports:
- 8080:8080
networks:
- transcendance_network
restart: unless-stopped
depends_on:
- backend_dev
- frontend_dev
- postgresql
- redis
postgresql:
container_name: nestjs_postgresql
image: postgres
volumes:
- data_nest_postgresql:/var/lib/postgresql/data
restart: unless-stopped
environment:
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
POSTGRES_DB: "${POSTGRES_DB}"
POSTGRES_HOST: "${POSTGRES_HOST}"
POSTGRES_PORT: "${POSTGRES_PORT}"
postgresql:
container_name: nestjs_postgresql
image: postgres
# ports:
# - 5432:5432
networks:
- transcendance_network
volumes:
- data_nest_postgresql:/var/lib/postgresql/data
restart: unless-stopped
environment:
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
POSTGRES_DB: "${POSTGRES_DB}"
POSTGRES_HOST: "${POSTGRES_HOST}"
POSTGRES_PORT: "${POSTGRES_PORT}"
redis:
container_name: nestjs_redis
image: redis:alpine
expose:
- "6379"
networks:
- transcendance_network
restart: unless-stopped
environment:
REDIS_HOST: "${REDIS_HOST}"
REDIS_PORT: "${REDIS_PORT}"
networks:
transcendance_network:
driver: bridge
# Je connais pas redis, mais si t'en a besoin que a l'interieur de tes containers, je pense pas que t'as besoin d'un expose.
redis:
container_name: nestjs_redis
image: redis:alpine
expose:
- "6379"
restart: unless-stopped
environment:
REDIS_HOST: "${REDIS_HOST}"
REDIS_PORT: "${REDIS_PORT}"
volumes:
data_nest_back:
data_nest_postgresql:
data_nest_redis:
# debug:
# container_name: nestjs_api_debug
# image: nestjs_api_debug
# build:
# context: ./requirements/nestjs
# target: development
# dockerfile: Dockerfile
# command: run start:dev --debug 0.0.0.0:9229
# ports:
# - 3000:3000
# - 9229:9229
# networks:
# - transcendance_network
# volumes:
# - ./requirements/nestjs/api_back:/usr/src/app
# - /usr/src/app/node_modules
# env_file:
# - .env
# environment:
# NODE_ENV: "${NODE_ENV}"
# DEBUG: "*" # enable all debug logs
# restart: unless-stopped
# depends_on:
# - postgresql
data_nest_postgresql:

View File

@@ -0,0 +1,11 @@
# Ignore everything
*
# Allow files and folders with a pattern starting with !
!api_back/*.js
!api_back/*.ts
!api_back/*.json
!api_back/*.html
!api_back/*.lock
!api_back/.env

View File

@@ -1,42 +1,10 @@
FROM node:alpine AS development
WORKDIR /usr/src/app
WORKDIR /usr/app
COPY --chown=node:node ./api_back/package*.json ./
COPY api_back/* .
COPY api_back/.env .env
RUN npm i
RUN npm ci
COPY --chown=node:node ./api_back/ ./
USER node
# FROM node:19-alpine AS build
# WORKDIR /usr/src/app
# COPY --chown=node:node ./api_back/package*.json ./
# COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
# COPY --chown=node:node ./api_back/ ./
# RUN npm run build
# ENV NODE_ENV production
# RUN npm ci --only=production && npm cache clean --force
# USER node
# FROM node:19-alpine AS production
# WORKDIR /usr/src/app
# COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
# COPY --chown=node:node --from=build /usr/src/app/dist ./dist
# USER node
ENV HOST=0.0.0.0
CMD [ "node", "run", "start:dev" ]
CMD [ "npm", "run", "start:dev" ]

View File

@@ -36,17 +36,6 @@ export class AuthenticationController {
return response.status(200).redirect('http://transcendance:8080');
}
/**
* GET /api/v2/auth/status
* Route pour vérifier si l'utilisateur est connecté
* ou non.
*/
@Get('status')
@UseGuards(AuthenticateGuard)
status() {
return 'status';
}
/**
* GET /api/v2/auth/logout
* Route pour déconnecter l'utilisateur

View File

@@ -24,7 +24,7 @@ export class FriendshipController {
return this.friendshipService.findOneFriend(relationshipId, user.id);
}
// POST http://127.0.0.1:3000/api/v2/network/
// POST http://127.0.0.1:3000/api/v2/network/myfriends
@Post('myfriends')
@HttpCode(HttpStatus.CREATED)
@UseGuards(AuthenticateGuard)

View File

@@ -30,6 +30,9 @@ export class User {
@Column('json', { nullable: true })
status: [string];
// @Column()
// isFirstConnection: boolean;
@Column({ default: false, nullable: true })
isEnabledTwoFactorAuth: boolean;

View File

@@ -31,18 +31,18 @@ export class UsersController {
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
*/
@UseGuards(AuthenticateGuard)
@Get()
findOne(@Req() req) {
return this.usersService.findOne(req.user.id);
}
// @UseGuards(AuthenticateGuard)
// @Get()
// findOne(@Req() req) {
// return this.usersService.findOne(req.user.id);
// }
@UseGuards(AuthenticateGuard)
@Post()
@HttpCode(HttpStatus.CREATED)
create(@Body() createUsersDto : CreateUsersDto ) {
return this.usersService.create(createUsersDto);
}
// @UseGuards(AuthenticateGuard)
// @Post()
// @HttpCode(HttpStatus.CREATED)
// create(@Body() createUsersDto : CreateUsersDto ) {
// return this.usersService.create(createUsersDto);
// }
@UseGuards(AuthenticateGuard)
@Patch()

View File

@@ -0,0 +1,10 @@
# Ignore everything
*
# Allow files and folders with a pattern starting with !
!api_front/*.js
!api_front/*.ts
!api_front/*.json
!api_front/*.html
!api_front/*.lock

View File

@@ -1,42 +1,9 @@
FROM node:alpine AS development
WORKDIR /usr/src/app
WORKDIR /usr/app
COPY --chown=node:node ./api_front/package*.json ./
COPY ./api_front/* .
RUN npm i
RUN npm ci
COPY --chown=node:node ./api_front/ ./
USER node
# FROM node:19-alpine AS build
# WORKDIR /usr/src/app
# COPY --chown=node:node ./api_front/package*.json ./
# COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
# COPY --chown=node:node ./api_front/ ./
# RUN npm run build
# ENV NODE_ENV production
# RUN npm ci --only=production && npm cache clean --force
# USER node
# FROM node:19-alpine AS production
# WORKDIR /usr/src/app
# COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
# COPY --chown=node:node --from=build /usr/src/app/dist ./dist
# USER node
ENV HOST=0.0.0.0
CMD [ "node", "run", "dev"]
CMD [ "npm", "run", "dev" ]

View File

@@ -5,7 +5,7 @@
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear",
"start": "sirv public --no-clear --host",
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {

View File

@@ -2,10 +2,12 @@
import Login from "./pages/auth/login.svelte";
import Home from "./pages/home/home.svelte";
import Router, {link} from 'svelte-spa-router';
import Profil from "./pages/profil/profil.svelte";
const routes = {
"/": Home,
"/login": Login,
"/profil": Profil,
};
</script>
@@ -19,10 +21,12 @@
<li>
<a href="/" type="button" class="btn btn-primary">Home</a>
</li>
<!-- <li>
<a href="/profil" use:link type="button" class="btn btn-primary">Profil</a>
</li> -->
</ul>
<div class="text-end">
<a href="/login" use:link type="button" class="btn btn-warning">Connexion</a>
</div>
</div>

View File

@@ -1,18 +1,23 @@
<script lang="ts">
import axios from 'axios';
import { onMount } from 'svelte';
import {push} from 'svelte-spa-router';
let user = {logedIn: false};
onMount(async () => {
console.log('PROFIL SVELTE');
const {data} = await axios.get('http://transcendance:8080/api/v2/user');
if (data)
user.logedIn = true;
});
$: submit = async() => {
window.location.href = 'http://transcendance:8080/api/v2/auth';
if (document.cookie) {
user.logedIn = true;
}
}
$: logout = async() => {
fetch('http://transcendance:8080/api/v2/auth/logout');
await fetch('http://transcendance:8080/api/v2/auth/logout',);
user.logedIn = false;
}

View File

@@ -1,69 +1,55 @@
<script>
let href =
import Router, { link } from "svelte-spa-router";
import Login from "../auth/login.svelte";
import Profil from "../profil/profil.svelte";
const routes = {
"/login": Login,
"/profil": Profil,
};
</script>
<body>
<main class="d-flex flex-nowrap">
<h1 class="visually-hidden">Sidebars examples</h1>
<main class="d-flex flex-nowrap">
<h1 class="visually-hidden">Sidebars examples</h1>
<div class="d-flex flex-column flex-shrink-0 p-3 text-bg-dark" style="width: 280px;">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<svg class="bi pe-none me-2" width="40" height="32"><use xlink:href="#bootstrap"/></svg>
<span class="fs-4">Sidebar</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="/pouepouet" class="nav-link active" aria-current="page">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#home"/></svg>
Profil
</a>
</li>
<li>
<a href="#" class="nav-link text-white" on:click={color}>
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#speedometer2"/></svg>
Dashboard
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#table"/></svg>
Orders
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#grid"/></svg>
Products
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
<svg class="bi pe-none me-2" width="16" height="16"><use xlink:href="#people-circle"/></svg>
Customers
</a>
</li>
</ul>
<hr>
</div>
</main>
<div
class="d-flex flex-column flex-shrink-0 p-3 text-bg-dark"
style="width: 280px;"
>
<a href="/" use:link class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<span class="fs-4">Sidebar</span>
</a>
<hr />
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a
href="/profil"
use:link
class="nav-link active"
aria-current="page"
>
Profil
</a>
</li>
</ul>
<hr />
</div>
</main>
</body>
<Router {routes} />
<style>
body {
min-height: 100vh;
min-height: -webkit-fill-available;
}
main {
height: 100vh;
height: -webkit-fill-available;
max-height: 100vh;
overflow-x: auto;
overflow-y: hidden;
}
.dropdown-toggle { outline: 0; }
min-height: 100vh;
min-height: -webkit-fill-available;
}
main {
height: 100vh;
height: -webkit-fill-available;
max-height: 100vh;
overflow-x: auto;
overflow-y: hidden;
}
</style>

View File

@@ -1,14 +1,44 @@
<script>
import axios from "axios";
import { onMount } from "svelte";
let user = {};
onMount (async() => {
const response = await fetch('http://transcendance:8080/api/v2/user');
const data = await response.json();
console.log("PROFIL SVELTE");
const {data} = await axios.get('http://transcendance:8080/api/v2/user');
console.log(data.username);
console.log(data);
user = data;
});
const profile = {
</script>
<body>
<main class="form-signin w-100 m-auto">
<div class="container">
<div class="row">
<div class="col-12">
<h1>Profil</h1>
<ul>
<li>username : {user.username}</li>
</ul>
</div>
</div>
</div>
</main>
</body>
<style>
body {
display: flex;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
}
.form-signin {
max-width: 330px;
padding: 15px;
}
</style>