Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Docker support for Talawa Admin repository #1453

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .github/workflows/authorized-changes-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ on:
- 'CODEOWNERS'
- 'LICENSE'
- 'setup.ts'
- 'Dockerfile'
- 'docker-compose.yml'
- '.dockerignore'

jobs:
Checking-for-unauthorized-file-changes:
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine
Devesh326 marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /usr/src/app

COPY package* .

RUN npm install --legacy-peer-deps

COPY . .

EXPOSE 3000
Devesh326 marked this conversation as resolved.
Show resolved Hide resolved

CMD ["npm", "run", "serve"]
36 changes: 29 additions & 7 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This document provides instructions on how to set up and start a running instanc
- [Setting up this repository](#setting-up-this-repository)
- [Setting up npm](#setting-up-npm)
- [Setting up Typescript](#setting-up-typescript)
- [Installation With Docker](#installation-using-docker)
- [Installing required packages/dependencies](#installing-required-packagesdependencies)
- [Configuration](#configuration)
- [Creating .env file](#creating-env-file)
Expand All @@ -27,8 +28,8 @@ This document provides instructions on how to set up and start a running instanc
- [Debugging tests](#debugging-tests)
- [Linting code files](#linting-code-files)
- [Husky for Git Hooks](#husky-for-git-hooks)
- [pre-commit hook](#pre-commit-hook)
- [post-merge hook](#post-merge-hook)
- [pre-commit hook](#pre-commit-hook)
- [post-merge hook](#post-merge-hook)

<!-- tocstop -->

Expand Down Expand Up @@ -79,12 +80,34 @@ npm install -g typescript

For more details please refer to the installation guidelines provided in the [official docs](https://www.typescriptlang.org/download).

## Installation Using Docker

> - **Requires Docker and Docker Compose to be installed**

Add the endpoint for accessing talawa-api graphql service to the variable named `REACT_APP_TALAWA_URL` in the `.env` file.

```
REACT_APP_TALAWA_URL="http://HOST-MACHINE-IP-ADDRESS:4000/graphql/"
```

Now use the following command to run docker containers -

```sh
docker compose up
```

OR

```sh
docker-compose up
```

## Installing required packages/dependencies

Run the following command to install the packages and dependencies required by `talawa-admin`:

```
npm install
npm install
```

# Configuration
Expand Down Expand Up @@ -122,7 +145,7 @@ Follow the instructions from section [Setting up REACT_APP_TALAWA_URL in .env fi
Add the endpoint for accessing talawa-api graphql service to the variable named `REACT_APP_TALAWA_URL` in the `.env` file.

```
REACT_APP_TALAWA_URL="http://API-IP-ADRESS:4000/graphql/"
REACT_APP_TALAWA_URL="http://API-IP-ADDRESS:4000/graphql/"
```

If you are a software developer working on your local system, then the URL would be:
Expand Down Expand Up @@ -150,6 +173,7 @@ Copy/paste this `reCAPTCHA site key` to the variable named `REACT_APP_RECAPTCHA_
```
REACT_APP_RECAPTCHA_SITE_KEY="this_is_the_recaptcha_key"
```

## Setting up Compiletime and Runtime logs

Set the `ALLOW_LOGS` to "YES" if you want warnings , info and error messages in your console or leave it blank if you dont need them or want to keep the console clean
Expand All @@ -158,7 +182,7 @@ Set the `ALLOW_LOGS` to "YES" if you want warnings , info and error messages in

It's now time to start Talawa-Admin and get it running

## Running Talawa-Admin
## Running Talawa-Admin without Docker

Run the following command to start `talawa-admin` development server:

Expand Down Expand Up @@ -219,7 +243,6 @@ npm run lint:fix

We are using the package `Husky` to run git hooks that run according to different git workflows.


#### pre-commit hook

We run a pre-commit hook which automatically runs code quality checks each time you make a commit and also fixes some of the issues. This way you don't have to run them manually each time.
Expand All @@ -228,7 +251,6 @@ If you don't want these pre-commit checks running on each commit, you can manual

git commit -m "commit message" --no-verify


#### post-merge hook

We are also running a post-merge(post-pull) hook which will automatically run "npm install --legacy-peer-deps" only if there is any change made to pakage.json file so that the developer has all the required dependencies when pulling files from remote.
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
talawa-admin:
build: .
environment:
- REACT_APP_TALAWA_URL=${REACT_APP_TALAWA_URL}
volumes:
- .:/usr/src/app
ports:
- '3000:3000'
33 changes: 25 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"bootstrap": "^5.3.0",
"customize-cra": "^1.0.0",
"dayjs": "^1.10.7",
"dotenv": "^16.3.1",
"enzyme": "^3.11.0",
"flag-icons": "^6.6.6",
"graphql": "^15.5.1",
Expand All @@ -28,7 +29,7 @@
"i18next": "^21.8.14",
"i18next-browser-languagedetector": "^6.1.4",
"i18next-http-backend": "^1.4.1",
"inquirer": "^8.0.0",
"inquirer": "^8.2.6",
"js-cookie": "^3.0.1",
"lint-staged": "^15.2.0",
"markdown-toc": "^1.2.0",
Expand Down
43 changes: 30 additions & 13 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ async function checkConnection(url: string): Promise<any> {
return isConnected;
}

async function askForTalawaApiUrl(): Promise<string> {
async function askForTalawaApiUrl(
isDockerInstallation: boolean
): Promise<string> {
const { endpoint } = await inquirer.prompt([
{
type: 'input',
name: 'endpoint',
message: 'Enter your talawa-api endpoint:',
default: 'http://localhost:4000/graphql/',
default: isDockerInstallation
? 'http://host-machine-ip-address:4000/graphql/'
: 'http://localhost:4000/graphql/',
},
]);
return endpoint;
Expand Down Expand Up @@ -68,27 +72,40 @@ async function main(): Promise<void> {

let shouldSetTalawaApiUrl: boolean;

if (process.env.REACT_APP_TALAWA_URL) {
const { isDockerInstallation } = await inquirer.prompt({
type: 'confirm',
name: 'isDockerInstallation',
message: 'Are you setting up this project using Docker?',
default: false,
});
if (!isDockerInstallation) {
if (process.env.REACT_APP_TALAWA_URL) {
console.log(
`\nEndpoint for accessing talawa-api graphql service already exists with the value:\n${process.env.REACT_APP_TALAWA_URL}`
);
shouldSetTalawaApiUrl = true;
} else {
const { shouldSetTalawaApiUrlResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetTalawaApiUrlResponse',
message: 'Would you like to set up talawa-api endpoint?',
default: true,
});
shouldSetTalawaApiUrl = shouldSetTalawaApiUrlResponse;
}
} else {
console.log(
`\nEndpoint for accessing talawa-api graphql service already exists with the value:\n${process.env.REACT_APP_TALAWA_URL}`
`\nEnter endpoint for accessing talawa-api graphql:\nhttp://host-machine-ip-address:4000/graphql`
);
shouldSetTalawaApiUrl = true;
} else {
const { shouldSetTalawaApiUrlResponse } = await inquirer.prompt({
type: 'confirm',
name: 'shouldSetTalawaApiUrlResponse',
message: 'Would you like to set up talawa-api endpoint?',
default: true,
});
shouldSetTalawaApiUrl = shouldSetTalawaApiUrlResponse;
}

if (shouldSetTalawaApiUrl) {
let isConnected = false,
endpoint = '';

while (!isConnected) {
endpoint = await askForTalawaApiUrl();
endpoint = await askForTalawaApiUrl(isDockerInstallation);
const url = new URL(endpoint);
isConnected = await checkConnection(url.origin);
}
Expand Down
Loading