Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
refactor: changes to docker config and env variables (#288)
Browse files Browse the repository at this point in the history
* refactor: updating the docker to require env and config files

* refactor: removed the verifyattestation async as no await

* feat: make it work for development

* feat: do not set PUBLIC_URL

* feat: use env variables in task-definition

Co-authored-by: Timo Welde <tjwelde@gmail.com>
  • Loading branch information
Dudleyneedham and tjwelde authored Sep 23, 2020
1 parent 5029811 commit b53a559
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ REACT_APP_SERVICE_HOST=//127.0.0.1:3000
REACT_APP_NODE_HOST=ws://127.0.0.1:9944

REACT_APP_FAUCET_URL=//127.0.0.1:3002

PUBLIC_URL=.
7 changes: 0 additions & 7 deletions .env.devnet

This file was deleted.

7 changes: 0 additions & 7 deletions .env.production

This file was deleted.

1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"error",
"never"
],
"no-underscore-dangle": ["error", { "allow": ["_env_"] }],
"import/extensions": ["error", "ignorePackages", {
"ts": "never",
"tsx": "never",
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ yarn-debug.log*
yarn-error.log*
/src/dist/
*.iml

# Temporary env files
/public/env-config.js
env-config.js
17 changes: 15 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@ EXPOSE 3001
CMD [ "yarn", "start" ]

FROM develop as builder
ARG BUILD_ENV=.env.production
RUN yarn lint
#RUN yarn testCI
RUN yarn env-cmd -f ${BUILD_ENV} node scripts/build.js
RUN yarn build

FROM nginx:alpine as release
COPY --from=builder /app/build/ /usr/share/nginx/html/
COPY --from=builder /app/config/nginx.conf /etc/nginx/conf.d/default.conf

# Copy .env file and shell script to container
WORKDIR /usr/share/nginx/html
COPY ./env.sh .
COPY .env .

# Add bash
RUN apk add --no-cache bash

# Make our shell script executable
RUN chmod +x env.sh

# Start Nginx server
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
16 changes: 0 additions & 16 deletions Dockerfile.devnet

This file was deleted.

1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ services:
- REACT_APP_SERVICE_HOST=//127.0.0.1:3000
- REACT_APP_NODE_HOST=ws://127.0.0.1:9944
- REACT_APP_FAUCET_URL=http://127.0.0.1:3002
- PUBLIC_URL=.
# if you experience issues where the watcher does not trigger rebuilds
# when changing files in src/ the following option may help
#- CHOKIDAR_USEPOLLING=true
Expand Down
30 changes: 30 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

# Recreate config file
rm -rf ./env-config.js
touch ./env-config.js

# Add assignment
echo "window._env_ = {" >> ./env-config.js

# Read each line in .env file
# Each line represents key=value pairs
while read -r line || [[ -n "$line" ]];
do
# Split env variables by character `=`
if printf '%s\n' "$line" | grep -q -e '='; then
varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
fi

# Read value of current variable if exists as Environment variable
value=$(printf '%s\n' "${!varname}")
# Otherwise use value from .env file
[[ -z $value ]] && value=${varvalue}

# Append configuration property to JS file
echo " $varname: \"$value\"," >> ./env-config.js
done < .env


echo "}" >> ./env-config.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "BSD-4-Clause",
"private": true,
"scripts": {
"start": "PORT=3001 node scripts/start.js",
"start": "chmod +x ./env.sh && ./env.sh && cp env-config.js ./public/ && PORT=3001 node scripts/start.js",
"build": "node scripts/build.js",
"build:devnet": "env-cmd -f .env.devnet node scripts/build.js",
"test": "node scripts/test.js --env=jsdom",
Expand Down
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, shrink-to-fit=no, initial-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#000000">

<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->

<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<script src="%PUBLIC_URL%/env-config.js" ></script>
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
Expand Down
2 changes: 1 addition & 1 deletion src/components/IdentityView/IdentityView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type State = {
showPublicIdentityQRCode: boolean
}

const FAUCET_URL = process.env.REACT_APP_FAUCET_URL
const FAUCET_URL = window._env_.REACT_APP_FAUCET_URL

class IdentityView extends React.Component<Props, State> {
private static openKiltFaucet(address: IMyIdentity['identity']['address']) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/BlockchainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BlockchainService {
}

public static getNodeWebsocketUrl(): string {
return `${process.env.REACT_APP_NODE_HOST}`
return `${window._env_.REACT_APP_NODE_HOST}`
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/ContactRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { notifyFailure } from './FeedbackService'
// (for other tests)

class ContactRepository {
public static readonly URL = `${process.env.REACT_APP_SERVICE_HOST}/contacts`
public static readonly URL = `${window._env_.REACT_APP_SERVICE_HOST}/contacts`

public static async findAll(): Promise<IContact[]> {
return fetch(`${ContactRepository.URL}`)
Expand Down
2 changes: 1 addition & 1 deletion src/services/CtypeRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CTypeRepository {
})
}

private static readonly URL = `${process.env.REACT_APP_SERVICE_HOST}/ctype`
private static readonly URL = `${window._env_.REACT_APP_SERVICE_HOST}/ctype`
}

export default CTypeRepository
2 changes: 1 addition & 1 deletion src/services/DidService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ContactRepository from './ContactRepository'
import MessageRepository from './MessageRepository'

class DidService {
public static readonly URL = `${process.env.REACT_APP_SERVICE_HOST}/contacts/did`
public static readonly URL = `${window._env_.REACT_APP_SERVICE_HOST}/contacts/did`

public static async resolveDid(
identifier: string
Expand Down
2 changes: 1 addition & 1 deletion src/services/MessageRepository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface IMessageOutput extends sdk.IMessage {
// (for other tests)

class MessageRepository {
public static readonly URL = `${process.env.REACT_APP_SERVICE_HOST}/messaging`
public static readonly URL = `${window._env_.REACT_APP_SERVICE_HOST}/messaging`

/**
* takes contact or list of contacts
Expand Down
6 changes: 6 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable @typescript-eslint/interface-name-prefix */
interface GlobalVariables {
_env_: any
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
declare interface Window extends GlobalVariables {}
16 changes: 15 additions & 1 deletion task-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@
"containerPort": 80
}
],
"essential": true
"essential": true,
"environment": [
{
"name": "REACT_APP_SERVICE_HOST",
"value": "https://services.devnet.kilt.io:443"
},
{
"name": "REACT_APP_NODE_HOST",
"value": "wss://full-nodes-lb.devnet.kilt.io:443"
},
{
"name": "REACT_APP_FAUCET_URL",
"value": "https://faucet-devnet.kilt.io"
}
]
}
],
"cpu": "512",
Expand Down

0 comments on commit b53a559

Please sign in to comment.