Skip to content

Commit

Permalink
Folder restructure and CI/CD (#78)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Feb 1, 2021
1 parent aedf779 commit 0102ba3
Show file tree
Hide file tree
Showing 52 changed files with 329 additions and 373 deletions.
5 changes: 0 additions & 5 deletions .firebaserc

This file was deleted.

33 changes: 0 additions & 33 deletions .github/workflows/docs.yml

This file was deleted.

26 changes: 16 additions & 10 deletions .github/workflows/gcp-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name: Build and Deploy to Google Compute Engine

name: Build and Deploy to Server
on:
push:
branches:
- development

release:
types:
- created
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GCE_INSTANCE: server-central-vm
GCE_INSTANCE_ZONE: us-central1-a


jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
Expand All @@ -21,7 +18,7 @@ jobs:
uses: actions/checkout@v2

# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
- uses: google-github-actions/setup-gcloud@master
with:
version: '290.0.1'
service_account_key: ${{ secrets.GKE_KEY }}
Expand All @@ -31,11 +28,20 @@ jobs:
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
- name: Ignored Files Reveal
run: |-
echo "${{ secrets.ENV_CONFIG }}" > ./sources/env_encoded.txt
- run: |-
echo "${{ secrets.ADMIN_SDK }}" > ./sources/project-elaichi_encoded.txt
- run: |-
cd ./sources && base64 --decode -i env_encoded.txt > .env
- run: |-
cd ./sources && base64 --decode -i project-elaichi_encoded.txt > project-elaichi.json
#Build the Docker image
- name: Build
run: |-
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image" .
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image" ./sources
#Push the Docker image to Google Container Registry
- name: Publish
run: |-
Expand Down
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

sources/node_modules
sources/db
sources/coverage
project-elaichi.json
package-lock.json
.env
sources/.node_repl_history
sources/.npm/
coverage
.vs/
.bash_history
.bash_logout
Expand All @@ -12,11 +17,7 @@ sources/coverage
.gnupg/
.mongorc.js
.mysql_history
sources/.node_repl_history
sources/.npm/
.profile
.ssh/
.viminfo
sources/.env
.gitconfig
project-elaichi.json
.gitconfig
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions sources/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions sources/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:alpine

WORKDIR /app

COPY package.json /app

# COPY ./project-elaichi.json /app

RUN npm install --production --force

COPY . /app

RUN npm install pm2 -g

CMD ["pm2-runtime","start","index.js","-i","max"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @format */

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

class AccessLevelAPI extends DataSource {
Expand Down Expand Up @@ -58,15 +58,6 @@ class AccessLevelAPI extends DataSource {
await foundUser.save();
await foundClub.save();
return await foundAccessLevel.deleteOne();
}

async deleteAccessLevelFromUser(id){
const foundAccessLevel= await AccessLevels.findById(id);
const userId = foundAccessLevel.user;
const foundUser = await Users.findById(userId);
foundUser.clubAccess = foundUser.clubAccess.filter((access)=>access._id!=id)
await foundUser.save();
return await foundAccessLevel.deleteOne();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ var accessLevelSchema = new mongoose.Schema({
timestamps: true
});

module.exports = mongoose.model('AccessLevel', accessLevelSchema);
module.exports = mongoose.models.AccessLevel||mongoose.model('AccessLevel', accessLevelSchema);
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @format */

const queries = {};
const ERRORS = require('../errors');
const {resultResolver,resolverHelper}=require('../helpers/apollo');
const ERRORS = require('../../errors');
const {resultResolver,resolverHelper}=require('../../helpers/apollo');

const mutations = {
addAccessLevel: (parent, { accessLevel }, { dataSources, permissions, error }, info) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/** @format */

const Clubs = require('../models/club.js');
const Users = require('../models/user.js');
const Events = require('../models/event.js');
const AccessLevel = require('../models/accessLevel.js');
const Clubs = require('./club.model.js');
const Users = require('../users/user.model.js');
const Events = require('../events/event.model.js');
const AccessLevel = require('../accessLevels/accessLevel.model.js');
const { DataSource } = require('apollo-datasource');
const AccessLevelAPI = require('./accessLevels.js');
const { INVALID_INPUT } = require('../errors/index.js');
const AccessLevelAPI = require('../accessLevels/accessLevel.datasources.js');
const { INVALID_INPUT } = require('../../errors/index.js');

class ClubAPI extends DataSource {
constructor() {
Expand Down Expand Up @@ -150,4 +150,4 @@ class ClubAPI extends DataSource {
}
}

module.exports = ClubAPI;
module.exports = ClubAPI;
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ var clubSchema = new mongoose.Schema({
timestamps: true
});

module.exports = mongoose.model('Club', clubSchema);
module.exports = mongoose.models.Club||mongoose.model('Club', clubSchema);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @format */
const ERRORS = require('../errors');
const {resolverHelper,resultResolver} = require("../helpers/apollo");
const ERRORS = require('../../errors');
const {resolverHelper,resultResolver} = require("../../helpers/apollo");

const queries = {
// clubs: (parent, args, { dataSources }, info) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ var currentStorySchema = new mongoose.Schema({
// currentStorySchema.index({ createdAt: { type: Date, expires: 86400 }}); // schema level


module.exports = mongoose.model('currentStory', currentStorySchema);
module.exports = mongoose.models.currentStory||mongoose.model('currentStory', currentStorySchema);
File renamed without changes.
17 changes: 17 additions & 0 deletions sources/apollo/errorClass/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @format */

const PERMISSION_DENIED = {
__typename: 'ErrorClass',
message: `Permission Denied.`,
code: `ERROR101`,
};

const INVALID_INPUT = {
__typename: 'ErrorClass',
code: `ERROR102`,
}

module.exports = {
PERMISSION_DENIED,
INVALID_INPUT
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/** @format */

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

class EventAPI extends DataSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ var eventSchema = new mongoose.Schema({
timestamps: true
});

module.exports = mongoose.model('Event', eventSchema);
module.exports = mongoose.models.Event||mongoose.model('Event', eventSchema);
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ var permissionSchema = new mongoose.Schema({
timestamps: true
});

module.exports = mongoose.model('Permission', permissionSchema);
module.exports = mongoose.models.Club||mongoose.model('Permission', permissionSchema);
33 changes: 33 additions & 0 deletions sources/apollo/resolvers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** @format */

const User = require('./users/user.resolver.js');
const Event = require('./events/event.resolver.js');
const Club = require('./clubs/club.resolver.js');
const Venue = require('./venues/venue.resolver.js');
const AccessLevel = require('./accessLevels/accessLevel.resolver.js');
const Story = require('./stories/story.resolver.js');
const { GraphQLDateTime } =require ("graphql-iso-date");

const FieldResolver = {};
const Query = {};
const Mutation = {};

const schemas = [User, Event, Club, AccessLevel,Story];
schemas.forEach((s) => {
Object.assign(FieldResolver, s.fieldResolvers);
Object.assign(Query, s.queries);
Object.assign(Mutation, s.mutations);
});

//Custom Resolver for Date object
const CustomScalarResolver = {
Date: GraphQLDateTime
};

const exportResolvers = {
Query,
Mutation
};
Object.assign(exportResolvers, FieldResolver);
Object.assign(exportResolvers, CustomScalarResolver);
module.exports = exportResolvers;
File renamed without changes.
14 changes: 7 additions & 7 deletions sources/schema.js → sources/apollo/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

const User = require('./schema/user');
const Event = require('./schema/event');
const Club = require('./schema/club');
const Venue = require('./schema/venue');
const Story = require('./schema/story');
const Access = require('./schema/accessLevel');
const ErrorClass = require('./schema/error');
const User = require('./users/user.schema.js');
const Event = require('./events/event.schema.js');
const Club = require('./clubs/club.schema.js');
const Venue = require('./venues/venue.schema.js');
const Story = require('./stories/story.schema.js');
const Access = require('./accessLevels/accessLevel.schema.js');
const ErrorClass = require('./errorClass/error.schema.js');
const {GraphQLDateTime} = require('graphql-iso-date');

const types = [];
Expand Down
16 changes: 8 additions & 8 deletions sources/server.js → sources/apollo/server.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { ApolloServer, gql, ApolloError, AuthenticationError } = require('apollo-server');
const UserAPI = require('./datasources/users.js');
const ClubAPI = require('./datasources/clubs.js');
const EventAPI = require('./datasources/events.js');
const VenueAPI = require('./datasources/venues.js');
const AccessLevelAPI = require('./datasources/accessLevels.js');
const StoryAPI = require('./datasources/stories.js');
const UserAPI = require('./users/user.datasources.js');
const ClubAPI = require('./clubs/club.datasources.js');
const EventAPI = require('./events/event.datasources.js');
const VenueAPI = require('./venues/venue.datasources.js');
const AccessLevelAPI = require('./accessLevels/accessLevel.datasources.js');
const StoryAPI = require('./stories/story.datasources.js');
const typeDefs = require('./schema.js');
const resolvers = require('./resolvers.js');
const {firebaseApp}=require("./helpers/firebase");
const {populatePermissions } = require("./helpers/permissions");
const {firebaseApp}=require("../helpers/firebase");
const {populatePermissions } = require("../helpers/permissions");


//Datasources
Expand Down
Loading

0 comments on commit 0102ba3

Please sign in to comment.