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

Publish image #9

Open
wants to merge 38 commits into
base: interpretable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
99481eb
allow to run API without Google passeport
lutangar Nov 7, 2022
59a2f4e
allow to run API without Google analytics
lutangar Nov 7, 2022
c4846bd
allow to run API without Facebook passeport
lutangar Nov 7, 2022
7172b39
allow email adresses configuration
lutangar Oct 16, 2022
9919c91
create a simple file storage
lutangar Nov 7, 2022
3800c8d
wip test ci / cd
lutangar Nov 8, 2022
dab3466
test fix
lutangar Nov 9, 2022
92ec053
fix test
lutangar Nov 9, 2022
a85d800
fix test
lutangar Nov 9, 2022
55d55f7
is this ?
lutangar Nov 9, 2022
f4a94ed
or that ?
lutangar Nov 9, 2022
f8fb283
or else ?
lutangar Nov 9, 2022
58125bc
ok thtat ?
lutangar Nov 9, 2022
08488d7
or mayber it ?
lutangar Nov 9, 2022
250cc50
evnt tat ffailing?
lutangar Nov 9, 2022
eb0bad4
evnt tat ffailing?
lutangar Nov 9, 2022
05c6322
change event
lutangar Nov 9, 2022
9c6bec1
tet
lutangar Nov 9, 2022
277ac3c
yarn
lutangar Nov 9, 2022
d86bdad
expose port
lutangar Nov 9, 2022
9bc198f
without reporeter
lutangar Nov 9, 2022
a684cf2
attempt raise timetout ccli
lutangar Nov 9, 2022
342a519
disable tiemouet
lutangar Nov 9, 2022
043e871
ip info token
lutangar Nov 9, 2022
005109f
remove unltmed tiemout
lutangar Nov 9, 2022
1bb57c6
env
lutangar Nov 9, 2022
385b115
ga
lutangar Nov 9, 2022
98bf8a7
humm
lutangar Nov 9, 2022
b57ad36
d
lutangar Nov 9, 2022
3ffe121
dzad
lutangar Nov 9, 2022
489f7cd
login
lutangar Nov 9, 2022
0529cb5
login 1
lutangar Nov 9, 2022
35566b2
login 3
lutangar Nov 9, 2022
6a5b302
restore
lutangar Nov 9, 2022
be03a64
teqs
lutangar Nov 9, 2022
e44b4d3
rly?
lutangar Nov 9, 2022
fec8fee
add veriosn number
lutangar Nov 9, 2022
547a466
udpate buil verison
lutangar Nov 9, 2022
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
4 changes: 3 additions & 1 deletion .env.defaults
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

GOOGLE_APPLICATION_CREDENTIALS=/opt/cboard-api/google-auth.json
GOOGLE_APPLICATION_CREDENTIALS=/opt/cboard-api/google-auth.json
[email protected]
[email protected]
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Node.js CI

on:
push:
branches: [interpretable]
pull_request:
branches: [interpretable]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

services:
mongodb:
image: mongo:4.0
ports:
- 27017:27017

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Run Unitests
run: ./node_modules/.bin/mocha test --recursive --exit
env:
IP_INFO_TOKEN: ${{ secrets.IP_INFO_TOKEN }}
DEFAULT_GA_VIEW: 162469865
MOBILE_GA_VIEW: 205673218
# - name: Run Unitests
# run: MOCHA_FILE=~/junit/test-results.xml ./node_modules/.bin/mocha test --recursive --reporter mocha-junit-reporter --exit
# - name: Archive code coverage results
# uses: actions/upload-artifact@v3
# with:
# name: code-coverage-report
# path: ~/junit/test-results.xml
51 changes: 51 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish Docker image

on:
release:
types: [published]
push:
branches: [publish-image]

jobs:
push_to_registries:
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# - name: Log in to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

-
name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository }}

# images: |
# my-docker-hub-namespace/my-docker-hub-repository
# ghcr.io/${{ github.repository }}

-
name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ config/env/production.js
*.sln
/.vs

test-results.xml
test-results.xml

# Uploaded images
public/uploads/
4 changes: 0 additions & 4 deletions api/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const DEFAULT_LANG = 'en-US';
const DEFAULT_CELL_SIZE = 'medium';
const DEFAULT_GA_VIEW = '162469865';
const MOBILE_GA_VIEW = '205673218';
const DEFAULT_FORMAT = 'cboard';
const APP_LANGS = [
'ar-SA',
Expand Down Expand Up @@ -51,6 +49,4 @@ module.exports = {
DEFAULT_CELL_SIZE: DEFAULT_CELL_SIZE,
APP_LANGS: APP_LANGS,
DEFAULT_FORMAT: DEFAULT_FORMAT,
DEFAULT_GA_VIEW: DEFAULT_GA_VIEW,
MOBILE_GA_VIEW: MOBILE_GA_VIEW
};
8 changes: 6 additions & 2 deletions api/controllers/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { google } = require('googleapis');
const analyticsreporting = google.analyticsreporting('v4');
const constants = require('../constants');
const config = require('../../config');

module.exports = {
batchGet: batchGet,
Expand All @@ -20,7 +21,7 @@ async function batchGet(req, res) {
try {
const reportRequests = req.body.map(requestReport => {
const report = {
viewId: requestReport.mobileView ? constants.MOBILE_GA_VIEW : constants.DEFAULT_GA_VIEW,
viewId: requestReport.mobileView ? config.MOBILE_GA_VIEW : config.DEFAULT_GA_VIEW,
dateRanges: [
{
startDate: requestReport.startDate,
Expand Down Expand Up @@ -99,4 +100,7 @@ async function userActivity(req, res) {
}
}

gapiAuth();

if (config.MOBILE_GA_VIEW || config.DEFAULT_GA_VIEW) {
gapiAuth();
}
5 changes: 2 additions & 3 deletions api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function createUser(req, res) {
let domain = req.headers.origin;
//if origin is private insert default hostname
if (!domain) {
domain = 'https://app.cboard.io'
domain = `https://${process.env.APP_DOMAIN}`
}

nev.sendVerificationEmail(newTempUser.email, domain, URL, function (err, info) {
Expand All @@ -88,7 +88,6 @@ async function createUser(req, res) {
'An email has been sent to you. Please check it to verify your account.'
});
});

// user already exists in temporary collection!
} else {
return res.status(409).json({
Expand Down Expand Up @@ -469,7 +468,7 @@ async function forgotPassword(req, res) {
let domain = req.headers.origin;
//if origin is private insert default hostname
if (!domain) {
domain = 'https://app.cboard.io'
domain = `https://${process.env.APP_DOMAIN}`
}

nev.sendResetPasswordEmail(user.email, domain, user.id, token, function (err) {
Expand Down
5 changes: 3 additions & 2 deletions api/helpers/blob.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const uuidv1 = require('uuid/v1');
const azure = require('azure-storage');
const blobService = azure.createBlobService(
const file = require('./file-storage');
const blobService = process.env.AZURE_STORAGE_CONNECTION_STRING ? azure.createBlobService(
process.env.AZURE_STORAGE_CONNECTION_STRING
);
) : file.createBlobService();

module.exports = {
createBlockBlobFromText
Expand Down
107 changes: 107 additions & 0 deletions api/helpers/file-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const fs = require('fs');
const path = require('path');

// https://github.com/Azure/azure-storage-node/blob/v3.0.100/lib/common/util/util.js#L366-L375
function normalizeArgs(optionsOrCallback, callback) {
let options = {};
if (typeof optionsOrCallback === 'function' && !callback) {
callback = optionsOrCallback;
} else if (optionsOrCallback) {
options = optionsOrCallback;
}

return { callback, options };
}

class FileSystemBlobService {
constructor(fileStorageFolder, baseUrl) {
this.fileStorageFolder = fileStorageFolder;
this.baseUrl = baseUrl;
this.fileStoragePath = path.join(
__dirname,
'../../public/',
fileStorageFolder
);
}

createContainerIfNotExists(container, optionsOrCallback, callbackArgument) {
const { callback } = normalizeArgs(optionsOrCallback, callbackArgument);
const result = { created: false };
const response = { isSuccessful: false };

fs.mkdir(
this.resolveContainerPath(container),
{ recursive: true },
function(e) {
if (e) {
callback(e, result, response);
}

result.created = true;
response.isSuccessful = true;

callback(null, result, response);
}
);
}

createBlockBlobFromText(
container,
fileName,
blob,
optionsOrCallback,
callbackArgument
) {
const { callback } = normalizeArgs(optionsOrCallback, callbackArgument);

fs.writeFile(
path.join(this.resolveContainerPath(container), fileName),
blob,
e => {
if (e) {
callback(e, {}, {});
}
const file = {
container,
name: fileName
};
callback(null, file, {});
}
);
}

getUrl(container, name) {
console.log(
path.join('/', this.fileStorageFolder, container, name),
this.baseUrl
);
const url = new URL(
path.join('/', this.fileStorageFolder, container, name),
this.baseUrl
);
return url.href;
}

resolveContainerPath(container) {
return path.resolve(this.fileStoragePath, container);
}
}

const createBlobService = () => {
const apiUrl = new URL('http://localhost:10010');
if (process.env.DEV_ENV_WITH_HTTPS) {
apiUrl.protocol = 'https';
}
if (process.env.PORT) {
apiUrl.port = process.env.PORT;
}
if (process.env.API_HOST) {
apiUrl.host = process.env.API_HOST;
}

return new FileSystemBlobService('uploads', apiUrl);
};

module.exports = {
createBlobService
};
24 changes: 9 additions & 15 deletions api/mail/email-verification.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var randtoken = require('rand-token'),
nodemailer = require('nodemailer');
nodemailer = require('nodemailer'),
config = require('../../config');

module.exports = function(mongoose) {
var isPositiveInteger = function(x) {
Expand Down Expand Up @@ -43,8 +44,8 @@ module.exports = function(mongoose) {
};
// default options
var options = {
verificationURL: 'https://app.cboard.io/activate/${URL}',
resetPasswordURL: 'https://app.cboard.io/reset/${USERID}/${URL}',
verificationURL: `https://${process.env.APP_DOMAIN}/activate/\${URL}`,
resetPasswordURL: `https://${process.env.APP_DOMAIN}/reset/\${USERID}/\${URL}`,
URLLength: 48,

// mongo-stuff
Expand All @@ -65,24 +66,17 @@ module.exports = function(mongoose) {
}
},
verifyMailOptions: {
from: 'Do Not Reply <[email protected]>',
from: `Do Not Reply <${config.emailTransport.from}>`,
subject: 'Confirm your account',
html:
'<p>Please verify your account by clicking <a href="${URL}">this link</a>. If you are unable to do so, copy and ' +
'paste the following link into your browser:</p><p>${URL}</p>',
text:
'Please verify your account by clicking the following link, or by copying and pasting it into your browser: ${URL}'
},
verifySendMailCallback: function(err, info) {
if (err) {
throw err;
} else {
console.log(info.response);
}
},
shouldSendConfirmation: true,
confirmMailOptions: {
from: 'Do Not Reply<[email protected]>',
from: `Do Not Reply<${config.emailTransport.from}>`,
subject: 'Successfully verified!',
html: '<p>Your account has been successfully verified.</p>',
text: 'Your account has been successfully verified.'
Expand All @@ -95,7 +89,7 @@ module.exports = function(mongoose) {
}
},
resetPasswordEmailOptions: {
from: 'Do Not Reply <[email protected]>',
from: `Do Not Reply <${config.emailTransport.from}>`,
subject: 'Cboard - Password reset',
html:
'<p>A request was submitted to reset the password of your Cboard account. </p> \
Expand All @@ -110,7 +104,7 @@ module.exports = function(mongoose) {
},
hashingFunction: null,
reportPublicBoardEmailOptions:{
from: 'Cboard Support <[email protected]>',
from: `Cboard Support <${config.emailTransport.from}>`,
subject: 'Public Board Report',
html:
'<p>The user ${whistleblowerName} reported that the board ${name} from the user ${author} contains inappropiate contet. </p> \
Expand Down Expand Up @@ -614,7 +608,7 @@ module.exports = function(mongoose) {
.replace('${url}', url)
.replace('${reason}', reason)

mailOptions.to = '[email protected]';
mailOptions.to = config.supportEmail;
if (!callback) {
callback = options.confirmSendMailReportCallback;
}
Expand Down
Loading