-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
3,123 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Deploy to Railway | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
paths-ignore: | ||
- 'README.md' | ||
|
||
env: | ||
AZURE_WEBAPP_NAME: bookify | ||
NODE_VERSION: '20.x' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Source | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
cache: 'npm' | ||
|
||
- name: Create .env file | ||
run: | | ||
echo "SQLITE_DB=${{ secrets.SQLITE_DB }}" >> .env | ||
echo "TYPEORM_CLI=${{ secrets.TYPEORM_CLI }}" >> .env | ||
echo "APP_PORT=${{ secrets.APP_PORT }}" >> .env | ||
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env | ||
echo "OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}" >> .env | ||
echo "OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}" >> .env | ||
echo "OAUTH_REDIRECT_URL=${{ secrets.OAUTH_REDIRECT_URL }}" >> .env | ||
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env | ||
echo "${{ secrets.ROOMS }}" > ./src/config/rooms.ts | ||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Run database migrations | ||
run: npm run migration:run | ||
|
||
- name: Build project | ||
run: npm run build | ||
|
||
- name: Upload artifact for deployment job | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: node-app | ||
path: . | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
environment: | ||
name: 'production' | ||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
|
||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: node-app | ||
|
||
- name: Install Railway | ||
run: npm i -g @railway/cli | ||
|
||
- name: Deploy | ||
run: railway up --service bookify | ||
env: | ||
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Deploy to Azure App Service | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- 'README.md' | ||
|
||
env: | ||
AZURE_WEBAPP_NAME: bookify | ||
NODE_VERSION: '20.x' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Source | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VERSION }} | ||
cache: 'npm' | ||
|
||
- name: Create .env file | ||
run: | | ||
echo "SQLITE_DB=${{ secrets.SQLITE_DB }}" >> .env | ||
echo "TYPEORM_CLI=${{ secrets.TYPEORM_CLI }}" >> .env | ||
echo "APP_PORT=${{ secrets.APP_PORT }}" >> .env | ||
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env | ||
echo "OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}" >> .env | ||
echo "OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}" >> .env | ||
echo "OAUTH_REDIRECT_URL=${{ secrets.OAUTH_REDIRECT_URL }}" >> .env | ||
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env | ||
echo "${{ secrets.ROOMS }}" > ./src/config/rooms.ts | ||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Run database migrations | ||
run: npm run migration:run | ||
|
||
- name: Build project | ||
run: npm run build | ||
|
||
- name: Upload artifact for deployment job | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: node-app | ||
path: . | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
environment: | ||
name: 'production' | ||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
|
||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: node-app | ||
|
||
- name: Deploy to Azure App Service | ||
uses: azure/webapps-deploy@v2 | ||
with: | ||
app-name: ${{ env.AZURE_WEBAPP_NAME }} | ||
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} | ||
package: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,112 @@ | ||
![image](https://github.com/user-attachments/assets/c624fbc6-5673-4c85-ae4a-74d298b73089) | ||
|
||
# Get started | ||
1. Place the `.env.development` file or `.env` file in the root dir | ||
2. place the `rooms.ts` file in `src/config` which contains the room specific infos | ||
3. [optional] Place the `dump.sql` file in the root dir if you want to create the database for the first time using docker container | ||
2. To obtain the list of meeting spaces that are allocated for your organization, use the [Google directory API](https://developers.google.com/admin-sdk/directory/reference/rest/v1/resources.calendars/list?apix_params=%7B%22customer%22%3A%22my_customer%22%2C%22maxResults%22%3A20%7D) to obtain the list and format them according to `src/calender/interfaces/room.interface.ts`. Finally place the file as `rooms.ts` file in `src/config`. | ||
3. Run `npm run migration:run` to create the migrations | ||
4. Run the app using: `npm run start:dev` | ||
5. Run the client using `npm run start:client` | ||
|
||
|
||
## How it works | ||
|
||
### List available rooms | ||
|
||
```bash | ||
rooms <min-seat-count> <start-time> <duration> | ||
|
||
# e.g: | ||
# rooms 1 -> shows list of available roo | ||
curl | ||
--location --globoff '{{baseUrl}}/rooms' \ | ||
--header 'Authorization: Bearer <token>' | ||
``` | ||
|
||
### Book room | ||
|
||
```bash | ||
book <min-seat-count> <start-time> <duration> <floor?> | ||
curl | ||
--location --globoff '{{baseUrl}}/room' \ | ||
--header 'Content-Type: application/json' \ | ||
--header 'Authorization: Bearer <token>' \ | ||
--data '{ | ||
"startTime": "2024-08-31T10:30:00+06:00", | ||
"duration": 30, | ||
"seats": 1, | ||
"floor": 1, | ||
"createConference": true, | ||
"title": "Quick meeting API", | ||
"attendees": [] | ||
}' | ||
|
||
# e.g: | ||
# book 1 3:30pm 30m f2 -> finds the closest available room on f2 with a min room capactiy of 1. | ||
``` | ||
|
||
### Update room | ||
|
||
```bash | ||
rooms --booked | ||
|
||
room --id=1 duration=+30m | ||
# todo | ||
``` | ||
|
||
|
||
### Delete room | ||
|
||
```bash | ||
|
||
rooms --booked | ||
unbook --id=1 | ||
``` | ||
|
||
curl | ||
--location --globoff --request DELETE '{{baseUrl}}/room' \ | ||
--header 'Content-Type: application/json' \ | ||
--header 'Authorization: Bearer <token>' \ | ||
--data '{ | ||
"eventId": "4r4bddp2bfkgg1tic1vh84sit8" | ||
}' | ||
|
||
``` | ||
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix_params=%7B%22resource%22%3A%7B%22timeMin%22%3A%222024-08-27T00%3A00%3A00%2B02%3A00%22%2C%22timeMax%22%3A%222024-09-27T23%3A59%3A59%2B02%3A00%22%2C%22items%22%3A%5B%7B%22id%22%3A%22Ada%20Bit%2010%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22c_1888flqi3ecr4gb0k9armpk8k9ics%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22RESOURCE_ID_3%40resource.calendar.google.com%22%7D%5D%7D%7D | ||
in the playground paste this request: | ||
{ | ||
"timeMin": "2024-08-27T00:00:00+02:00", | ||
"timeMax": "2024-09-27T23:59:59+02:00", | ||
"timeZone": "Asia/Dhaka", | ||
"items": [ | ||
{ | ||
"id": "Ada Bit [email protected]" | ||
}, | ||
{ | ||
"id": "[email protected]" | ||
}, | ||
{ | ||
"id": "[email protected]" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Commands | ||
## Todo | ||
|
||
```bash | ||
npm run start:database | ||
``` | ||
- add some sort of mutex or a buffer to prevent race conditions | ||
|
||
# Database setup | ||
|
||
## Starting from scratch | ||
## Github actions | ||
|
||
A database dump file is required. Paste the dump file (`dump.sql`) in the root directory and run the following commands to create a docker container and initialize the database with the dump file. | ||
The following env secrets needs to be configured in the github repository: | ||
|
||
```bash | ||
npm run start:database | ||
APP_PORT= | ||
AZURE_WEBAPP_PUBLISH_PROFILE= | ||
ROOMS= | ||
SQLITE_DB= | ||
TYPEORM_CLI= | ||
``` | ||
|
||
## Note | ||
|
||
Make sure you have the `.env` file. Not the `.env.development`, as the docker env variables are loaded from `.env` by default. | ||
## Deployment | ||
|
||
### Entering docker container's mysql | ||
Make sure to create the following environment secrets in the Azure App service: | ||
|
||
```sh | ||
docker exec -it <containerid> sh # to enter a container's bash | ||
mysql -uroot -proot # to enter mysql | ||
```bash | ||
APP_PORT= | ||
AZURE_WEBAPP_PUBLISH_PROFILE= | ||
JWT_SECRET= | ||
OAUTH_CLIENT_ID= | ||
OAUTH_CLIENT_SECRET= | ||
OAUTH_REDIRECT_URL= | ||
SQLITE_DB= | ||
TYPEORM_CLI= | ||
APP_DOMAIN= | ||
``` | ||
|
||
### MySql workbench | ||
When connecting the database with a workbench, make sure to turn the following values (if required): | ||
|
||
- allowPublicKeyRetrieval=true | ||
- useSSL=false | ||
### Sqlite file restore & backup | ||
|
||
More: https://stackoverflow.com/a/50438872 | ||
From the Azure portal, head over to SSH and copy the sqlite file from `/home/site/wwwroot/bookify.sqlite` to `/home/bookify.sqlite`. | ||
|
||
## Importing database dump for existing container | ||
To backup the file, you can use an FTP client such as FileZilla. Head over to the App Service's Deployment Center and ensure FTP is enabled. Note the `FTP Hostname`, `Username`, and `Password`. | ||
|
||
Assuming you have the dump file `dump.sql` in the root dir, the following steps must be followed: | ||
``` | ||
Run steps (1-3) if you are running it with docker container: | ||
## Commands | ||
1. Find the docker container id using `docker ps` | ||
2. Copy the dump file into the docker container: `docker cp dump.sql <container_id>:/dump.sql` | ||
3. Enter into the docker container's shell: `docker exec -it <container_id> /bin/bash` | ||
4. Run this command: `mysql -u<user_name> -p<password> oj_db < dump.sql` where `user_name`=root and `password`=root | ||
### Entering docker container's mysql | ||
```sh | ||
docker exec -it <containerid> sh # to enter a container's bash | ||
mysql -uroot -proot # to enter mysql | ||
``` | ||
|
||
## Migrations | ||
### Migrations | ||
|
||
Once you get into production you'll need to synchronize model changes into the database. Typically, it is unsafe to use `synchronize: true` for schema synchronization on production once you get data in your database. Here is where migrations come to help. | ||
|
||
|
@@ -180,3 +172,14 @@ TypeORM is able to automatically generate migration files with schema changes yo | |
npm run migration:generate | ||
``` | ||
You don't need to write the queries on your own. The rule of thumb for generating migrations is that you generate them after **each** change you made to your models. | ||
|
||
|
||
## Reference | ||
|
||
- [Google Free busy API](https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix_params=%7B%22resource%22%3A%7B%22timeMin%22%3A%222024-08-27T00%3A00%3A00%2B02%3A00%22%2C%22timeMax%22%3A%222024-09-27T23%3A59%3A59%2B02%3A00%22%2C%22items%22%3A%5B%7B%22id%22%3A%22Ada%20Bit%2010%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22c_1888flqi3ecr4gb0k9armpk8k9ics%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22RESOURCE_ID_3%40resource.calendar.google.com%22%7D%5D%7D%7D ) | ||
|
||
- [Resources API](https://developers.google.com/admin-sdk/directory/reference/rest/v1/resources.calendars/list?apix_params=%7B%22customer%22%3A%22my_customer%22%2C%22maxResults%22%3A20%7D) | ||
|
||
- [Hosting on Azure App Service](https://docs.github.com/en/actions/use-cases-and-examples/deploying/deploying-nodejs-to-azure-app-service) | ||
|
||
- [Azure file system](https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system) |
Oops, something went wrong.