Skip to content

Commit 0102ba3

Browse files
DesignrKnightroshankshawHarishTeens
authored
Folder restructure and CI/CD (#78)
* Added a restructured directory apollo * fix failing tests * delete unused files after restructure * clean up - remove unused dependecies - edit package.json - gitignore package-lock * delete unused else statement * Edit .gitignore * Combine resolvers component files in apollo directory * Add trigger for deploy branch * GoogleCloudPlatform/github-actions/setup-gcloud has been deprecated. * update docker build from ./sources * Update Dockerfile * Add secrets for .env and admin sdk * Update gcp-deploy.yml * Update gcp-deploy.yml * Update gcp-deploy.yml * Update Dockerfile * Update docker-compose.yml * Update Dockerfile * Update Dockerfile * Delete docs.yml * Update gcp-deploy.yml * Update .dockerignore * Update gcp-deploy.yml * Update gcp-deploy.yml * Update gcp-deploy.yml * Update gcp-deploy.yml * Update index.js * Update gcp-deploy.yml * Update gcp-deploy.yml * Update gcp-deploy.yml Co-authored-by: roshankshaw <[email protected]> Co-authored-by: HarishTeens <[email protected]> Co-authored-by: Harish <[email protected]>
1 parent aedf779 commit 0102ba3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+329
-373
lines changed

.firebaserc

-5
This file was deleted.

.github/workflows/docs.yml

-33
This file was deleted.

.github/workflows/gcp-deploy.yml

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
name: Build and Deploy to Google Compute Engine
2-
1+
name: Build and Deploy to Server
32
on:
4-
push:
5-
branches:
6-
- development
7-
3+
release:
4+
types:
5+
- created
86
env:
97
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
108
GCE_INSTANCE: server-central-vm
119
GCE_INSTANCE_ZONE: us-central1-a
1210

13-
1411
jobs:
1512
setup-build-publish-deploy:
1613
name: Setup, Build, Publish, and Deploy
@@ -21,7 +18,7 @@ jobs:
2118
uses: actions/checkout@v2
2219

2320
# Setup gcloud CLI
24-
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
21+
- uses: google-github-actions/setup-gcloud@master
2522
with:
2623
version: '290.0.1'
2724
service_account_key: ${{ secrets.GKE_KEY }}
@@ -31,11 +28,20 @@ jobs:
3128
# helper for authentication
3229
- run: |-
3330
gcloud --quiet auth configure-docker
34-
31+
- name: Ignored Files Reveal
32+
run: |-
33+
echo "${{ secrets.ENV_CONFIG }}" > ./sources/env_encoded.txt
34+
- run: |-
35+
echo "${{ secrets.ADMIN_SDK }}" > ./sources/project-elaichi_encoded.txt
36+
- run: |-
37+
cd ./sources && base64 --decode -i env_encoded.txt > .env
38+
- run: |-
39+
cd ./sources && base64 --decode -i project-elaichi_encoded.txt > project-elaichi.json
40+
3541
#Build the Docker image
3642
- name: Build
3743
run: |-
38-
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image" .
44+
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image" ./sources
3945
#Push the Docker image to Google Container Registry
4046
- name: Publish
4147
run: |-

.gitignore

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
sources/node_modules
33
sources/db
4-
sources/coverage
4+
project-elaichi.json
5+
package-lock.json
6+
.env
7+
sources/.node_repl_history
8+
sources/.npm/
9+
coverage
510
.vs/
611
.bash_history
712
.bash_logout
@@ -12,11 +17,7 @@ sources/coverage
1217
.gnupg/
1318
.mongorc.js
1419
.mysql_history
15-
sources/.node_repl_history
16-
sources/.npm/
1720
.profile
1821
.ssh/
1922
.viminfo
20-
sources/.env
21-
.gitconfig
22-
project-elaichi.json
23+
.gitconfig

Dockerfile

-15
This file was deleted.

docker-compose.yml

-6
This file was deleted.

sources/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

sources/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:alpine
2+
3+
WORKDIR /app
4+
5+
COPY package.json /app
6+
7+
# COPY ./project-elaichi.json /app
8+
9+
RUN npm install --production --force
10+
11+
COPY . /app
12+
13+
RUN npm install pm2 -g
14+
15+
CMD ["pm2-runtime","start","index.js","-i","max"]

sources/datasources/accessLevels.js sources/apollo/accessLevels/accessLevel.datasources.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @format */
22

3-
const AccessLevels = require('../models/accessLevel.js');
4-
const Clubs = require('../models/club.js');
5-
const Users = require('../models/user.js');
3+
const AccessLevels = require('./accessLevel.model.js');
4+
const Clubs = require('../clubs/club.model.js');
5+
const Users = require('../users/user.model.js');
66
const { DataSource } = require('apollo-datasource');
77

88
class AccessLevelAPI extends DataSource {
@@ -58,15 +58,6 @@ class AccessLevelAPI extends DataSource {
5858
await foundUser.save();
5959
await foundClub.save();
6060
return await foundAccessLevel.deleteOne();
61-
}
62-
63-
async deleteAccessLevelFromUser(id){
64-
const foundAccessLevel= await AccessLevels.findById(id);
65-
const userId = foundAccessLevel.user;
66-
const foundUser = await Users.findById(userId);
67-
foundUser.clubAccess = foundUser.clubAccess.filter((access)=>access._id!=id)
68-
await foundUser.save();
69-
return await foundAccessLevel.deleteOne();
7061
}
7162
}
7263

sources/models/accessLevel.js sources/apollo/accessLevels/accessLevel.model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ var accessLevelSchema = new mongoose.Schema({
1717
timestamps: true
1818
});
1919

20-
module.exports = mongoose.model('AccessLevel', accessLevelSchema);
20+
module.exports = mongoose.models.AccessLevel||mongoose.model('AccessLevel', accessLevelSchema);

sources/resolvers/accessLevel.js sources/apollo/accessLevels/accessLevel.resolver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @format */
22

33
const queries = {};
4-
const ERRORS = require('../errors');
5-
const {resultResolver,resolverHelper}=require('../helpers/apollo');
4+
const ERRORS = require('../../errors');
5+
const {resultResolver,resolverHelper}=require('../../helpers/apollo');
66

77
const mutations = {
88
addAccessLevel: (parent, { accessLevel }, { dataSources, permissions, error }, info) => {

sources/datasources/clubs.js sources/apollo/clubs/club.datasources.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/** @format */
22

3-
const Clubs = require('../models/club.js');
4-
const Users = require('../models/user.js');
5-
const Events = require('../models/event.js');
6-
const AccessLevel = require('../models/accessLevel.js');
3+
const Clubs = require('./club.model.js');
4+
const Users = require('../users/user.model.js');
5+
const Events = require('../events/event.model.js');
6+
const AccessLevel = require('../accessLevels/accessLevel.model.js');
77
const { DataSource } = require('apollo-datasource');
8-
const AccessLevelAPI = require('./accessLevels.js');
9-
const { INVALID_INPUT } = require('../errors/index.js');
8+
const AccessLevelAPI = require('../accessLevels/accessLevel.datasources.js');
9+
const { INVALID_INPUT } = require('../../errors/index.js');
1010

1111
class ClubAPI extends DataSource {
1212
constructor() {
@@ -150,4 +150,4 @@ class ClubAPI extends DataSource {
150150
}
151151
}
152152

153-
module.exports = ClubAPI;
153+
module.exports = ClubAPI;

sources/models/club.js sources/apollo/clubs/club.model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ var clubSchema = new mongoose.Schema({
4040
timestamps: true
4141
});
4242

43-
module.exports = mongoose.model('Club', clubSchema);
43+
module.exports = mongoose.models.Club||mongoose.model('Club', clubSchema);

sources/resolvers/club.js sources/apollo/clubs/club.resolver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @format */
2-
const ERRORS = require('../errors');
3-
const {resolverHelper,resultResolver} = require("../helpers/apollo");
2+
const ERRORS = require('../../errors');
3+
const {resolverHelper,resultResolver} = require("../../helpers/apollo");
44

55
const queries = {
66
// clubs: (parent, args, { dataSources }, info) => {
File renamed without changes.

sources/models/currentStory.js sources/apollo/currentStories/currentStory.model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ var currentStorySchema = new mongoose.Schema({
1919
// currentStorySchema.index({ createdAt: { type: Date, expires: 86400 }}); // schema level
2020

2121

22-
module.exports = mongoose.model('currentStory', currentStorySchema);
22+
module.exports = mongoose.models.currentStory||mongoose.model('currentStory', currentStorySchema);
File renamed without changes.

sources/apollo/errorClass/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @format */
2+
3+
const PERMISSION_DENIED = {
4+
__typename: 'ErrorClass',
5+
message: `Permission Denied.`,
6+
code: `ERROR101`,
7+
};
8+
9+
const INVALID_INPUT = {
10+
__typename: 'ErrorClass',
11+
code: `ERROR102`,
12+
}
13+
14+
module.exports = {
15+
PERMISSION_DENIED,
16+
INVALID_INPUT
17+
};

sources/datasources/events.js sources/apollo/events/event.datasources.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/** @format */
22

3-
const Events = require('../models/event.js');
4-
const Users = require('../models/user.js');
5-
const Clubs = require('../models/club.js');
6-
const Venues = require('../models/venue.js');
7-
const AccessLevel = require('../models/accessLevel.js');
3+
const Events = require('./event.model.js');
4+
const Users = require('../users/user.model.js');
5+
const Clubs = require('../clubs/club.model.js');
6+
const Venues = require('../venues/venue.model.js');
7+
const AccessLevel = require('../accessLevels/accessLevel.model.js');
88
const { DataSource } = require('apollo-datasource');
99

1010
class EventAPI extends DataSource {

sources/models/event.js sources/apollo/events/event.model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ var eventSchema = new mongoose.Schema({
3131
timestamps: true
3232
});
3333

34-
module.exports = mongoose.model('Event', eventSchema);
34+
module.exports = mongoose.models.Event||mongoose.model('Event', eventSchema);
File renamed without changes.
File renamed without changes.

sources/models/permission.js sources/apollo/permissions/permission.model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ var permissionSchema = new mongoose.Schema({
88
timestamps: true
99
});
1010

11-
module.exports = mongoose.model('Permission', permissionSchema);
11+
module.exports = mongoose.models.Club||mongoose.model('Permission', permissionSchema);

sources/apollo/resolvers.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** @format */
2+
3+
const User = require('./users/user.resolver.js');
4+
const Event = require('./events/event.resolver.js');
5+
const Club = require('./clubs/club.resolver.js');
6+
const Venue = require('./venues/venue.resolver.js');
7+
const AccessLevel = require('./accessLevels/accessLevel.resolver.js');
8+
const Story = require('./stories/story.resolver.js');
9+
const { GraphQLDateTime } =require ("graphql-iso-date");
10+
11+
const FieldResolver = {};
12+
const Query = {};
13+
const Mutation = {};
14+
15+
const schemas = [User, Event, Club, AccessLevel,Story];
16+
schemas.forEach((s) => {
17+
Object.assign(FieldResolver, s.fieldResolvers);
18+
Object.assign(Query, s.queries);
19+
Object.assign(Mutation, s.mutations);
20+
});
21+
22+
//Custom Resolver for Date object
23+
const CustomScalarResolver = {
24+
Date: GraphQLDateTime
25+
};
26+
27+
const exportResolvers = {
28+
Query,
29+
Mutation
30+
};
31+
Object.assign(exportResolvers, FieldResolver);
32+
Object.assign(exportResolvers, CustomScalarResolver);
33+
module.exports = exportResolvers;
File renamed without changes.

sources/schema.js sources/apollo/schema.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
const { gql } = require('apollo-server');
44

5-
const User = require('./schema/user');
6-
const Event = require('./schema/event');
7-
const Club = require('./schema/club');
8-
const Venue = require('./schema/venue');
9-
const Story = require('./schema/story');
10-
const Access = require('./schema/accessLevel');
11-
const ErrorClass = require('./schema/error');
5+
const User = require('./users/user.schema.js');
6+
const Event = require('./events/event.schema.js');
7+
const Club = require('./clubs/club.schema.js');
8+
const Venue = require('./venues/venue.schema.js');
9+
const Story = require('./stories/story.schema.js');
10+
const Access = require('./accessLevels/accessLevel.schema.js');
11+
const ErrorClass = require('./errorClass/error.schema.js');
1212
const {GraphQLDateTime} = require('graphql-iso-date');
1313

1414
const types = [];

sources/server.js sources/apollo/server.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const { ApolloServer, gql, ApolloError, AuthenticationError } = require('apollo-server');
2-
const UserAPI = require('./datasources/users.js');
3-
const ClubAPI = require('./datasources/clubs.js');
4-
const EventAPI = require('./datasources/events.js');
5-
const VenueAPI = require('./datasources/venues.js');
6-
const AccessLevelAPI = require('./datasources/accessLevels.js');
7-
const StoryAPI = require('./datasources/stories.js');
2+
const UserAPI = require('./users/user.datasources.js');
3+
const ClubAPI = require('./clubs/club.datasources.js');
4+
const EventAPI = require('./events/event.datasources.js');
5+
const VenueAPI = require('./venues/venue.datasources.js');
6+
const AccessLevelAPI = require('./accessLevels/accessLevel.datasources.js');
7+
const StoryAPI = require('./stories/story.datasources.js');
88
const typeDefs = require('./schema.js');
99
const resolvers = require('./resolvers.js');
10-
const {firebaseApp}=require("./helpers/firebase");
11-
const {populatePermissions } = require("./helpers/permissions");
10+
const {firebaseApp}=require("../helpers/firebase");
11+
const {populatePermissions } = require("../helpers/permissions");
1212

1313

1414
//Datasources

0 commit comments

Comments
 (0)