Skip to content

Commit

Permalink
Merge pull request #17 from nwikeodigwe/comment-test
Browse files Browse the repository at this point in the history
Comment test
  • Loading branch information
nwikeodigwe authored Feb 25, 2025
2 parents db54116 + eead091 commit 5131407
Show file tree
Hide file tree
Showing 94 changed files with 13,931 additions and 9,183 deletions.
79 changes: 42 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
name: Relay app CI pipeline
name: CI pipeline

on:
push:
branches:
- main
pull_request:
branches:
- main
- main
workflow_dispatch:

jobs:

build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20, 21]
node-version: [20, 21]

services:
mysql:
image: mysql:latest
Expand All @@ -32,41 +31,47 @@ jobs:
--health-retries=3
env:
CI: true

steps:
- name: Checkout code
uses: actions/checkout@v3
CI: true

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Wait for MySQL to be ready
run: |
until mysqladmin ping -h 127.0.0.1 -u${{ secrets.MYSQL_USER }} -p${{ secrets.MYSQL_PASSWORD }} --silent; do
echo "Waiting for database to connect..."
sleep 2
done
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Create test database
run: |
mysql -h 127.0.0.1 -u${{ secrets.MYSQL_USER }} -p${{ secrets.MYSQL_PASSWORD }} -e "CREATE DATABASE IF NOT EXISTS ${{ secrets.MYSQL_DB }};"
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies and run tests
env:
NODE_ENV: test
DATABASE_URL: "mysql://${{ secrets.MYSQL_USER }}:${{ secrets.MYSQL_PASSWORD }}@localhost:${{ secrets.MYSQL_PORT }}/${{ secrets.MYSQL_DB }}"
FACEBOOK_CLIENT_SECRET: ${{ secrets.FACEBOOK_CLIENT_SECRET }}
FACEBOOK_CLIENT_ID: ${{ secrets.FACEBOOK_CLIENT_ID }}
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
run: |
cd backend
npm install
npx prisma migrate dev
npx jest --verbose --runInBand
- name: Wait for MySQL to be ready
run: |
until mysqladmin ping -h 127.0.0.1 -u${{ secrets.MYSQL_USER }} -p${{ secrets.MYSQL_PASSWORD }} --silent; do
echo "Waiting for database to connect..."
sleep 2
done
- name: Create test database
run: |
mysql -h 127.0.0.1 -u${{ secrets.MYSQL_USER }} -p${{ secrets.MYSQL_PASSWORD }} -e "CREATE DATABASE IF NOT EXISTS ${{ secrets.MYSQL_DB }};"
- name: Install dependencies and run tests
env:
NODE_ENV: test
DATABASE_URI: "mysql://${{ secrets.MYSQL_USER }}:${{ secrets.MYSQL_PASSWORD }}@localhost:${{ secrets.MYSQL_PORT }}/${{ secrets.MYSQL_DB }}"
FACEBOOK_CLIENT_SECRET: ${{ secrets.FACEBOOK_CLIENT_SECRET }}
FACEBOOK_CLIENT_ID: ${{ secrets.FACEBOOK_CLIENT_ID }}
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
JWT_REFRESH_SECRET: ${{ secrets.JWT_REFRESH_SECRET }}
run: |
cd app
npm install
npx prisma migrate dev
npx jest --verbose --runInBand
16 changes: 11 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/backend/node_modules
/backend/dist
/backend/coverage
/app/node_modules
/app/dist
/app/coverage

/app/*.env*
/app/*.log
/app/logs

/.vscode

/mysql

/backend/*.env*
/backend/*.log
9 changes: 9 additions & 0 deletions app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/
coverage/

package-lock.json

*.log
*.env*

.gitignore
File renamed without changes.
19 changes: 19 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:21-alpine

WORKDIR /app

RUN apk add --no-cache openssl libssl3
ENV OPENSSL_DIR=/usr/lib/ssl

COPY package*.json ./

RUN npm install
COPY . .
RUN npm install -g nodemon

RUN adduser -D -u 1010 theia && chown -R theia /app
USER theia

RUN chmod +x entrypoint.sh

EXPOSE 3000
File renamed without changes.
26 changes: 26 additions & 0 deletions app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
MAX_RETRIES=10
RETRY_DELAY=2
RETRY_COUNT=0

echo "Applying database schema..."
if ! npx prisma db push; then
echo "Database schema push failed! Exiting."
exit 1
fi

echo "Running migrations..."
RETRY_COUNT=0

until echo "yes" | npx prisma migrate dev; do
echo "Migration failed. Retrying in $RETRY_DELAY seconds..."
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Migration failed after $MAX_RETRIES attempts. Exiting."
exit 1
fi
sleep $RETRY_DELAY
done

echo "Migrations complete! Starting app..."
exec npm start
4 changes: 4 additions & 0 deletions backend/jest.config.js → app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
cache: true,
clearMocks: true,
resetModules: true,
restoreMocks: true,
preset: "ts-jest",
testEnvironment: "node",
transform: {
Expand Down
Loading

0 comments on commit 5131407

Please sign in to comment.