From e4c7d72d7e327c311e3d10bc010c2f977fd52302 Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 02:19:42 -0700 Subject: [PATCH 1/8] fix: Github Actions error fixed --- {backend/.github => .github}/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {backend/.github => .github}/workflows/ci.yml (77%) diff --git a/backend/.github/workflows/ci.yml b/.github/workflows/ci.yml similarity index 77% rename from backend/.github/workflows/ci.yml rename to .github/workflows/ci.yml index 433c1cb..4fe2ac2 100644 --- a/backend/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v2 - name: Install dependencies - run: npm install + run: cd backend && npm install - name: Test - run: npm run test + run: cd backend && npm run test From 4afa61aefaa710ad44242b05825d2226dc2d53ce Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 02:29:02 -0700 Subject: [PATCH 2/8] Continuous integration badge added --- .github/workflows/ci.yml | 2 ++ README.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fe2ac2..31b7f77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ jobs: testing: runs-on: ubuntu-latest + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} steps: - name: Checkout uses: actions/checkout@v2 diff --git a/README.md b/README.md index cfcc9e6..7057397 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ♻️ Fashion +[![Continuous Integration](https://github.com/techstartucalgary/fashion/actions/workflows/ci.yml/badge.svg)](https://github.com/techstartucalgary/fashion/actions/workflows/ci.yml) + ## 📖 Table of Contents - [📝 Contributors](#-contributors) From 0664f6b7fea134bececa096ef3bed13cdc753803 Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 02:56:29 -0700 Subject: [PATCH 3/8] fix: Continuous integration improvements --- .github/actions/docker-compose/action.yml | 11 +++++++++++ .github/workflows/ci.yml | 7 +++++-- docker-compose.yml | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .github/actions/docker-compose/action.yml create mode 100644 docker-compose.yml diff --git a/.github/actions/docker-compose/action.yml b/.github/actions/docker-compose/action.yml new file mode 100644 index 0000000..a5c7dec --- /dev/null +++ b/.github/actions/docker-compose/action.yml @@ -0,0 +1,11 @@ +name: 'Docker-Compose Setup' +description: 'Sets up docker-compose' +runs: + using: 'composite' + steps: + - name: Download Docker-Compose plugin + shell: bash + run: curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose + - name: Make plugin executable + shell: bash + run: sudo chmod +x /usr/local/bin/docker-compose \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31b7f77..09b2480 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,13 +11,16 @@ jobs: testing: runs-on: ubuntu-latest env: - DATABASE_URL: ${{ secrets.DATABASE_URL }} + DATABASE_URL: mysql://root:root@localhost:3306/techstart-fashion steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install dependencies run: cd backend && npm install + - name: Start services + uses: ./.github/actions/docker-compose + - name: Test run: cd backend && npm run test diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..71b453f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.8" +services: + db: + image: mysql + restart: always + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: techstart-fashion + ports: + - 3306:3306 + volumes: + - db:/var/lib/mysql + +volumes: + db: + driver: local From 34bea91d50b3ea6b138eb253538fdd4c55b7c283 Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 03:02:49 -0700 Subject: [PATCH 4/8] fix: Continuous integration improvements --- .github/actions/docker-compose/action.yml | 11 ----------- .github/workflows/ci.yml | 14 ++++++++++++-- docker-compose.yml | 16 ---------------- 3 files changed, 12 insertions(+), 29 deletions(-) delete mode 100644 .github/actions/docker-compose/action.yml delete mode 100644 docker-compose.yml diff --git a/.github/actions/docker-compose/action.yml b/.github/actions/docker-compose/action.yml deleted file mode 100644 index a5c7dec..0000000 --- a/.github/actions/docker-compose/action.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: 'Docker-Compose Setup' -description: 'Sets up docker-compose' -runs: - using: 'composite' - steps: - - name: Download Docker-Compose plugin - shell: bash - run: curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose - - name: Make plugin executable - shell: bash - run: sudo chmod +x /usr/local/bin/docker-compose \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09b2480..4b50f74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,18 @@ jobs: - name: Install dependencies run: cd backend && npm install - - name: Start services - uses: ./.github/actions/docker-compose + - name: Start volume + run: docker volume create db + + - name: Start database + run: docker run -d \ + --name db \ + -e MYSQL_ROOT_PASSWORD=root \ + -e MYSQL_DATABASE=techstart-fashion \ + -p 3306:3306 \ + -v db:/var/lib/mysql \ + --restart always \ + mysql - name: Test run: cd backend && npm run test diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 71b453f..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,16 +0,0 @@ -version: "3.8" -services: - db: - image: mysql - restart: always - environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: techstart-fashion - ports: - - 3306:3306 - volumes: - - db:/var/lib/mysql - -volumes: - db: - driver: local From 5b2b3b0a49126bdc009d082a614fdae7835f0f3a Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 03:05:05 -0700 Subject: [PATCH 5/8] fix: Continuous integration improvements --- .github/workflows/ci.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b50f74..9f8190c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,14 +23,15 @@ jobs: run: docker volume create db - name: Start database - run: docker run -d \ - --name db \ - -e MYSQL_ROOT_PASSWORD=root \ - -e MYSQL_DATABASE=techstart-fashion \ - -p 3306:3306 \ - -v db:/var/lib/mysql \ - --restart always \ - mysql + run: | + docker run -d \ + --name db \ + -e MYSQL_ROOT_PASSWORD=root \ + -e MYSQL_DATABASE=techstart-fashion \ + -p 3306:3306 \ + -v db:/var/lib/mysql \ + --restart always \ + mysql - name: Test run: cd backend && npm run test From 86c1557a2c6be1f7525df4d9f9d73acd4f6daca6 Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 03:22:14 -0700 Subject: [PATCH 6/8] fix: Continuous integration improvements --- backend/package.json | 2 +- backend/src/index.ts | 3 --- backend/src/routers/authentication.router.ts | 4 +++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index 3643095..7aa3dfc 100644 --- a/backend/package.json +++ b/backend/package.json @@ -10,7 +10,7 @@ "start": "NODE_ENV=PROD node dist/src/index.js", "predev": "npx prisma migrate dev --name init && npx prisma generate", "dev": "NODE_ENV=DEV nodemon -e ts --exec \"npm run build && node dist/src/index.js\"", - "pretest": "npx prisma migrate deploy && npx prisma generate", + "pretest": "npx prisma migrate dev --name init && npx prisma generate", "test": "NODE_ENV=TEST npm run build && mocha \"dist/test/**/*.test.js\"" }, "keywords": [], diff --git a/backend/src/index.ts b/backend/src/index.ts index 6e28f84..5d26cca 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -4,12 +4,9 @@ import algorithmRouter from "./routers/algorithm.router.js"; import authenticationRouter from "./routers/authentication.router.js"; import errorHandler from "./middlewares/error.middleware.js"; import { PORT } from "./config/config.js"; -import { PrismaClient } from "@prisma/client"; export const app: Express = express(); -export const prisma = new PrismaClient(); - app.use(cors()); app.use(express.json()); diff --git a/backend/src/routers/authentication.router.ts b/backend/src/routers/authentication.router.ts index 3d7f66d..7f074fc 100644 --- a/backend/src/routers/authentication.router.ts +++ b/backend/src/routers/authentication.router.ts @@ -1,5 +1,5 @@ import { Router } from "express"; -import { prisma } from "../index.js"; +import { PrismaClient } from "@prisma/client"; import UserRepository from "../repositories/user.repository.js"; import AuthenticationService from "../services/authentication.service.js"; import AuthenticationController from "../controllers/authentication.controller.js"; @@ -11,6 +11,8 @@ import { const authenticationRouter = Router(); +const prisma = new PrismaClient(); + const userRepository: UserRepositoryInterface = new UserRepository(prisma); const authenticationService: AuthenticationServiceInterface = From 9c928c7a8b749418a7111009674460382ab53dd1 Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 03:25:11 -0700 Subject: [PATCH 7/8] fix: Continuous integration improvements --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f8190c..50d3e31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,5 +33,8 @@ jobs: --restart always \ mysql + - name: Wait for database + run: docker exec db mysqladmin --silent --wait=30 -uroot -proot ping || exit 1 + - name: Test run: cd backend && npm run test From 2472e592a5498234a979f23ccffe8619bad3e167 Mon Sep 17 00:00:00 2001 From: Axeloooo Date: Sun, 19 Nov 2023 03:32:47 -0700 Subject: [PATCH 8/8] fix: Continuous integration improvements --- .github/workflows/ci.yml | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50d3e31..c43dc1b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,11 +7,25 @@ on: - dev jobs: - testing: runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: techstart-fashion + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h localhost -uroot -proot" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + env: DATABASE_URL: mysql://root:root@localhost:3306/techstart-fashion + steps: - name: Checkout uses: actions/checkout@v3 @@ -19,22 +33,13 @@ jobs: - name: Install dependencies run: cd backend && npm install - - name: Start volume - run: docker volume create db - - - name: Start database - run: | - docker run -d \ - --name db \ - -e MYSQL_ROOT_PASSWORD=root \ - -e MYSQL_DATABASE=techstart-fashion \ - -p 3306:3306 \ - -v db:/var/lib/mysql \ - --restart always \ - mysql - - name: Wait for database - run: docker exec db mysqladmin --silent --wait=30 -uroot -proot ping || exit 1 + run: | + until nc -z localhost 3306; do + echo "Waiting for MySQL to be ready..." + sleep 2 + done + echo "MySQL is ready." - name: Test run: cd backend && npm run test