Skip to content

Commit

Permalink
Merge pull request #52 from WildCodeSchool/CI-INIT
Browse files Browse the repository at this point in the history
Ci init
  • Loading branch information
VincentRssx authored Aug 22, 2024
2 parents 5ba5a30 + c667d93 commit e6f07cb
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 6 deletions.
Empty file added .dockerignore
Empty file.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ postgres-data/
node_modules/
.idea/
.DS_Store
/.env
.env
27 changes: 27 additions & 0 deletions backend/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:lts-alpine as builder

WORKDIR /app

COPY tsconfig.json tsconfig.json
COPY package.json package.json

RUN npm install
RUN npm install -g typescript

COPY src src

RUN tsc

FROM node:lts-alpine

RUN apk --no-cache add curl

WORKDIR /app

COPY --from=builder /app/dist /app/dist

COPY package.json package.json

RUN npm install --production

CMD npm run startprod
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node-dev --poll ./src/index.ts"
"start": "ts-node-dev --poll ./src/index.ts",
"startprod": "node ./dist/index.js"
},
"author": "",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const dataSource = new DataSource({
port: 5432,
username: "postgres",
password: "postgres",
database: "wild-transfer",
database: "postgres",
synchronize: true,
logging: ["error", "query", "schema"],
entities: [
Expand Down
65 changes: 65 additions & 0 deletions docker-compose.build.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
services:
backend:
build:
context: ./backend
dockerfile: Dockerfile.prod
env_file:
- .env.production
healthcheck:
test: 'curl --fail --request POST --header ''content-type: application/json'' --url ''http://localhost:4000/graphql'' --data ''{"query":"query { __typename }"}'' || exit 1'
interval: 1s
timeout: 2s
retries: 100
depends_on:
db:
condition: service_healthy
frontend:
build: ./frontend
depends_on:
backend:
condition: service_healthy
healthcheck:
test: "curl --fail --request GET --url 'http://localhost:5173' || exit 1"
interval: 1s
timeout: 2s
retries: 100
db:
image: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 1s
timeout: 2s
retries: 100
environment:
POSTGRES_PASSWORD: postgres
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
- ./postgres-data/data:/var/lib/postgresql/data
adminer:
image: adminer
ports:
- "8080:8080"
files:
build:
context: ./files
dockerfile: Dockerfile.prod
healthcheck:
test: "curl --fail --request GET --url 'http://localhost:3000' || exit 1"
interval: 1s
timeout: 2s
retries: 100
env_file:
- ./files/.env
apigateway:
image: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
backend:
condition: service_healthy
frontend:
condition: service_healthy
files:
condition: service_healthy
ports:
- "7002:80"
31 changes: 31 additions & 0 deletions files/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:lts-alpine as builder

RUN apk --no-cache add curl

WORKDIR /app
RUN mkdir UPLOADS_DIR

COPY tsconfig.json tsconfig.json

COPY package.json package.json

RUN npm i
RUN npm install -g typescript

COPY src src

RUN tsc

FROM node:lts-alpine

RUN apk --no-cache add curl

WORKDIR /app

COPY --from=builder /app/dist /app/dist

COPY package.json package.json

RUN npm install --production

CMD npm run startprod
3 changes: 2 additions & 1 deletion files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node-dev ./src/index.ts"
"start": "ts-node-dev ./src/index.ts",
"startprod": "node ./dist/index.js"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion files/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"start": "docker compose up --build",
"e2e": "docker compose -f docker-compose.e2e.yml up --build --exit-code-from e2e"
"e2e": "docker compose -f docker-compose.e2e.yml up --build --exit-code-from e2e",
"build_prod_and_start": "docker compose -f docker-compose.build.prod.yml up --build"
},
"author": "",
"license": "ISC",
Expand Down

0 comments on commit e6f07cb

Please sign in to comment.