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

Closes Issue #1932: Added environment variables to prod's Docker file #2027

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions config/env.development
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ IMAGE_URL=http://localhost/v1/image
USERS_PORT=6666

# Users Service URL
USERS_URL=http://localhost/v1/user
FIRESTORE_EMULATOR_HOST=localhost:8088
USERS_URL=http://localhost/v1/users
FIRESTORE_EMULATOR_HOST=firebase:8088
chrispinkney marked this conversation as resolved.
Show resolved Hide resolved


################################################################################
# Posts Service
Expand Down
13 changes: 0 additions & 13 deletions config/env.production
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,6 @@ MOCK_REDIS=
# Users Service
################################################################################

# Firebase's private api key. Used to authenticate telescope with firebase
# See https://firebase.google.com/docs/admin/setup#initialize-sdk to obtain the key
FIREBASE_TYPE=
FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_CLIENT_ID=
FIREBASE_AUTH_URI=
FIREBASE_TOKEN_URI=
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=
FIREBASE_CLIENT_X509_CERT_URL=

# Users Service Port (default is 6666)
USERS_PORT=6666

Expand Down
14 changes: 1 addition & 13 deletions config/env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,13 @@ MOCK_REDIS=
# Users Service
################################################################################

# Firebase's private api key. Used to authenticate telescope with firebase
# See https://firebase.google.com/docs/admin/setup#initialize-sdk to obtain the key
FIREBASE_TYPE=
FIREBASE_PROJECT_ID=
FIREBASE_PRIVATE_KEY_ID=
FIREBASE_PRIVATE_KEY=
FIREBASE_CLIENT_EMAIL=
FIREBASE_CLIENT_ID=
FIREBASE_AUTH_URI=
FIREBASE_TOKEN_URI=
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=
FIREBASE_CLIENT_X509_CERT_URL=

# Users Service Port (Default is 6666)
USERS_PORT=6666

# Users Service URL
USERS_URL=https://dev.api.telescope.cdot.systems/v1/users


################################################################################
# Feed Discovery Service
################################################################################
Expand Down
4 changes: 4 additions & 0 deletions docker/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ services:
elasticsearch:
ports:
- '9200:9200'

users:
environment:
- FIRESTORE_EMULATOR_HOST
4 changes: 3 additions & 1 deletion docker/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ services:
restart: unless-stopped
environment:
- NODE_ENV=production
- USERS_PORT
chrispinkney marked this conversation as resolved.
Show resolved Hide resolved
# TODO
# - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
# - ELASTIC_APM_SERVICE_NAME=user
# - ELASTIC_APM_SERVER_URL=http://apm:8200
volumes:
# This will take care of copying the serviceAccountKey.json file needed by firestore.js
- ../../config/firebase:/app

##############################################################################
# Third-Party Dependencies and Support Services
Expand Down
11 changes: 6 additions & 5 deletions src/api/users/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ npm install:users-service
# normal mode
npm start

# running firestore emulator locally
# running firestore emulator and users microservice locally
npm run services:start firebase users

# dev mode with automatic restarts
npm run services:start firebase
npm start
cd src/api/users
npm run dev

# test runner (must be used in conjunction with the firebase service)
npm run jest:e2e (or npm run jest:e2e src\api\users\test\e2e)

# dev mode with automatic restarts
npm run dev
```

By default the server is running on <http://localhost:6666/>.
Expand Down
7 changes: 3 additions & 4 deletions src/api/users/jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const path = require('path');
const baseConfig = require('../../../jest.config.base');
require('dotenv').config({
path: path.join(__dirname, '../../../config/env.development'),
});

// override to pass e2e tests
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8088';
humphd marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
...baseConfig,
Expand Down
3 changes: 2 additions & 1 deletion src/api/users/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js"
"dev": "cross-env FIRESTORE_EMULATOR_HOST=localhost:8088 nodemon src/server.js"
},
"dependencies": {
"@senecacdot/satellite": "^1.x",
Expand All @@ -13,6 +13,7 @@
},
"devDependencies": {
"@firebase/rules-unit-testing": "^1.2.2",
"cross-env": "^5.2.1",
"dotenv": "^6.2.0",
"firebase-tools": "^9.6.1",
"nodemon": "^2.0.7",
Expand Down
55 changes: 15 additions & 40 deletions src/api/users/src/services/firestore.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
/* eslint-disable global-require */
/* eslint-disable import/no-unresolved */

const admin = require('firebase-admin');
const { logger } = require('@senecacdot/satellite');

const {
FIREBASE_TYPE,
FIREBASE_PROJECT_ID,
FIREBASE_PRIVATE_KEY_ID,
FIREBASE_PRIVATE_KEY,
FIREBASE_CLIENT_EMAIL,
FIREBASE_CLIENT_ID,
FIREBASE_AUTH_URI,
FIREBASE_TOKEN_URI,
FIREBASE_AUTH_PROVIDER_X509_CERT_URL,
FIREBASE_CLIENT_X509_CERT_URL,
} = process.env;

// If a private key exists in env.development, run in online mode
// else run in emulator mode
if (
(FIREBASE_PRIVATE_KEY,
chrispinkney marked this conversation as resolved.
Show resolved Hide resolved
FIREBASE_PROJECT_ID,
FIREBASE_PRIVATE_KEY_ID,
FIREBASE_PRIVATE_KEY,
FIREBASE_CLIENT_EMAIL,
FIREBASE_CLIENT_ID,
FIREBASE_AUTH_URI,
FIREBASE_TOKEN_URI,
FIREBASE_AUTH_PROVIDER_X509_CERT_URL,
FIREBASE_CLIENT_X509_CERT_URL)
) {
try {
// Docker is responsible for putting this file in the root of the container
admin.initializeApp({
credential: admin.credential.cert({
type: FIREBASE_TYPE,
project_id: FIREBASE_PROJECT_ID,
private_key_id: FIREBASE_PRIVATE_KEY_ID,
private_key: FIREBASE_PRIVATE_KEY,
client_email: FIREBASE_CLIENT_EMAIL,
client_id: FIREBASE_CLIENT_ID,
auth_uri: FIREBASE_AUTH_URI,
token_uri: FIREBASE_TOKEN_URI,
auth_provider_x509_cert_url: FIREBASE_AUTH_PROVIDER_X509_CERT_URL,
client_x509_cert_url: FIREBASE_CLIENT_X509_CERT_URL,
}),
credential: admin.credential.cert(require('../../serviceAccountKey.json')),
});

logger.debug('Server running in online mode');
chrispinkney marked this conversation as resolved.
Show resolved Hide resolved
} else {
} catch (err) {
if (process.env.NODE_ENV === 'production') {
logger.error({ err }, 'Unable to load Firebase config');
process.exit(1);
}

// In development, fall-back to use the emulator
admin.initializeApp({
projectId: 'telescope',
credential: admin.credential.applicationDefault(),
});

logger.debug('Server running in emulator mode');
}

Expand Down