Skip to content

Commit

Permalink
Allow environment variable injection from containerland into application
Browse files Browse the repository at this point in the history
Fixes #459

Includes:
* Add configuration for disabling/enabling spoofing
  * Set default value to enable spoofing and explicitly set this value in the editor service in docker-compose to retain current behavior
* Add configuration variables for Sinopia server and ES URLs
* Inject environment variables the editor can see and use via Docker in order to disable/enable spoofing and set the Sinopia server URL
* Favor `getResourceTemplate()` over `getResourceTemplateFromServer()` to allow switching behavior (namely where the RTs are coming from) via env vars.
* Reduce number of max warnings for eslint failures
  • Loading branch information
mjgiarlo committed Apr 25, 2019
1 parent 00e1c6d commit aadd9d6
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 80 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ junit.xml
npm-debug.log
static-analysis
setupEnzyme.js
node_modules
23 changes: 22 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
FROM circleci/node:10.11

WORKDIR /opt/sinopia_editor/
# Allow build-time arguments (for, e.g., docker-compose)
ARG SPOOF_SINOPIA_SERVER
ARG TRELLIS_BASE_URL
ARG DEFAULT_PROFILE_SCHEMA_VERSION
ARG SINOPIA_GROUP
ARG SINOPIA_URI
ARG AWS_COGNITO_DOMAIN
ARG COGNITO_CLIENT_ID

# This is the directory the user in the circleci/node image can write to
WORKDIR /home/circleci

# Everything that isn't in .dockerignore ships
COPY . .

# Allow circleci user to run npm build
USER root
RUN /bin/bash -c 'chown -R circleci dist'

# Run app using non-privileged account
USER circleci

# Build the app *within* the container because environment variables are fixed at build-time
RUN npm install
RUN npm run build

# docker daemon maps app's port
EXPOSE 8000

Expand Down
22 changes: 19 additions & 3 deletions __tests__/Config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ const OLD_ENV = process.env

describe('Config', () => {
describe('static default values', () => {

it('sinopia has a default schema version', () => {
expect(Config.defaultProfileSchemaVersion).toEqual('0.0.2')
})

it('sinopia uri has static value', () => {
it('sinopia domain name has static value', () => {
expect(Config.sinopiaDomainName).toEqual('sinopia.io')
})

it('default sinopia group id has static value', () => {
expect(Config.defaultSinopiaGroupId).toEqual('ld4p')
})

it('sinopia url has static value', () => {
expect(Config.sinopiaUrl).toEqual('https://sinopia.io')
})

it('spoof sinopia server has static value', () => {
expect(Config.spoofSinopiaServer).toEqual(true)
})

it('aws client ID has static value', () => {
expect(Config.awsClientID).toEqual('2u6s7pqkc1grq1qs464fsi82at')
})
Expand Down Expand Up @@ -74,7 +81,9 @@ describe('Config', () => {
beforeAll(() => {
process.env = {
DEFAULT_PROFILE_SCHEMA_VERSION: '0.1.0',
SPOOF_SINOPIA_SERVER: 'false',
SINOPIA_URI: 'sinopia.foo',
SINOPIA_GROUP: 'foobar',
TRELLIS_BASE_URL: 'https://sinopia_server.foo',
COGNITO_CLIENT_ID: '1a2b3c',
AWS_COGNITO_DOMAIN: 'sinopia-foo.amazoncognito.com'
Expand All @@ -86,6 +95,10 @@ describe('Config', () => {
expect(Config.defaultProfileSchemaVersion).toEqual('0.1.0')
})

it('default sinopia group id overrides static value', () => {
expect(Config.defaultSinopiaGroupId).toEqual('foobar')
})

it('sinopia url overrides static value', () => {
expect(Config.sinopiaUrl).toEqual('https://sinopia.foo')
})
Expand All @@ -94,6 +107,10 @@ describe('Config', () => {
expect(Config.sinopiaServerBase).toEqual('https://sinopia_server.foo')
})

it('spoof sinopia server overrides static value', () => {
expect(Config.spoofSinopiaServer).toEqual(false)
}
)
it('aws client ID overrides static value', () => {
expect(Config.awsClientID).toEqual('1a2b3c')
})
Expand Down Expand Up @@ -132,5 +149,4 @@ describe('Config', () => {
process.env = OLD_ENV
})
})

})
40 changes: 8 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ services:
editor:
build:
context: .
args:
SPOOF_SINOPIA_SERVER: 'false'
TRELLIS_BASE_URL: http://platform:8080
ports:
- 8000:8000
depends_on:
- pipeline
pipeline:
image: ld4p/sinopia_indexing_pipeline:latest
environment:
INDEX_HOST: search
BROKER_HOST: broker
command: dockerize -wait tcp://broker:61613 -wait tcp://search:9200 -timeout 3m npm start
depends_on:
- broker
- search
- platform
broker:
image: rmohr/activemq
Expand All @@ -41,9 +34,13 @@ services:
- 8080:8080
- 8081:8081
depends_on:
- database
- broker
- database
- migration
broker:
image: rmohr/activemq
ports:
- 61613:61613
database:
image: postgres:latest
environment:
Expand All @@ -53,27 +50,6 @@ services:
PGDATA: /var/lib/postgresql/data/pgdata/mydata
ports:
- 5432:5432
search:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
entrypoint:
- elasticsearch
- -Ehttp.port=9200
- -Ehttp.cors.enabled=true
- -Ehttp.cors.allow-origin=http://searchui:1358,http://localhost:1358,http://127.0.0.1:1358
- -Ehttp.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
- -Ehttp.cors.allow-credentials=true
- -Etransport.host=localhost
- -Ebootstrap.system_call_filter=false
user: elasticsearch
ports:
- 9200:9200
- 9300:9300
searchui:
image: appbaseio/dejavu:latest
ports:
- 1358:1358
depends_on:
- search
migration:
image: ld4p/trellis-ext-db:latest
command: ["/opt/trellis/bin/trellis-db", "db", "migrate", "/opt/trellis/etc/config.yml"]
Expand Down
Loading

0 comments on commit aadd9d6

Please sign in to comment.