Skip to content

Commit

Permalink
test with readonly fs
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsgstrabo committed May 13, 2024
1 parent 30b9341 commit 9528dff
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 30 deletions.
13 changes: 12 additions & 1 deletion docker-compose-host-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
web:
image: node:20.9-alpine
container_name: radix-web_container
stdin_open: true # because of https://github.com/facebook/create-react-app/issues/8688
read_only: true
working_dir: /app
command: [ "sh", "-c", "npm install --prefer-offline --no-audit && chown -R node:node node_modules && npm start" ]
volumes:
Expand All @@ -14,6 +14,9 @@ services:
- type: volume
source: node-modules
target: /app/node_modules
- type: volume
target: /root
tmpfs: {}
networks:
- radix
environment:
Expand All @@ -32,6 +35,7 @@ services:
proxy:
image: nginxinc/nginx-unprivileged:1.25.2-alpine
container_name: radix-proxy_container
read_only: true
depends_on:
web:
condition: service_healthy
Expand All @@ -48,6 +52,12 @@ services:
- type: bind
source: ./proxy/run_nginx.sh
target: /run_nginx.sh
- type: volume
target: /etc/nginx/conf.d
tmpfs: {}
- type: volume
target: /tmp
tmpfs: {}
command: [ "/bin/sh", "-c", ". run_nginx.sh" ]
networks:
- radix
Expand All @@ -57,6 +67,7 @@ services:
auth:
image: quay.io/oauth2-proxy/oauth2-proxy:v7.6.0
container_name: radix-auth_container
read_only: true
environment:
# See the `radixconfig.yaml` file for a description of these settings
- OAUTH2_PROXY_CLIENT_ID=5687b237-eda3-4ec3-a2a1-023e85a2bd84
Expand Down
16 changes: 12 additions & 4 deletions docker-compose-host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ services:
web:
image: node:20.9-alpine
container_name: radix-web_container
stdin_open: true # because of https://github.com/facebook/create-react-app/issues/8688
read_only: true
working_dir: /app
command: [ "sh", "-c", "npm install --prefer-offline --no-audit && chown -R node:node node_modules && npm start" ]
volumes:
- type: bind
source: .
target: /app
# - type: volume
# source: node-modules
# target: /app/node_modules
- type: volume
target: /root
tmpfs: {}
network_mode: host
ports:
- "3000:3000"
Expand All @@ -22,6 +22,7 @@ services:
proxy:
image: nginxinc/nginx-unprivileged:1.25.2-alpine
container_name: radix-proxy_container
read_only: true
environment:
- DYNATRACE_API_TOKEN=${DYNATRACE_API_TOKEN}
volumes:
Expand All @@ -31,6 +32,12 @@ services:
- type: bind
source: ./proxy/run_nginx.sh
target: /run_nginx.sh
- type: volume
target: /etc/nginx/conf.d
tmpfs: {}
- type: volume
target: /tmp
tmpfs: {}
command: [ "/bin/sh", "-c", ". run_nginx.sh" ]
network_mode: host
ports:
Expand All @@ -39,6 +46,7 @@ services:
auth:
image: quay.io/oauth2-proxy/oauth2-proxy:v7.6.0
container_name: radix-auth_container
read_only: true
environment:
# See the `radixconfig.yaml` file for a description of these settings
- OAUTH2_PROXY_CLIENT_ID=5687b237-eda3-4ec3-a2a1-023e85a2bd84
Expand Down
13 changes: 12 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
web:
image: node:20.9-alpine
container_name: radix-web_container
stdin_open: true # because of https://github.com/facebook/create-react-app/issues/8688
read_only: true
working_dir: /app
command: [ "sh", "-c", "npm install --prefer-offline --no-audit && chown -R node:node node_modules && npm start" ]
environment:
Expand All @@ -16,6 +16,9 @@ services:
- type: volume
source: node-modules
target: /app/node_modules
- type: volume
target: /root
tmpfs: {}
networks:
- radix
ports:
Expand All @@ -25,6 +28,7 @@ services:
proxy:
image: nginxinc/nginx-unprivileged:1.25.2-alpine
container_name: radix-proxy_container
read_only: true
environment:
- DYNATRACE_API_TOKEN=${DYNATRACE_API_TOKEN}
volumes:
Expand All @@ -34,6 +38,12 @@ services:
- type: bind
source: ./proxy/run_nginx.sh
target: /run_nginx.sh
- type: volume
target: /etc/nginx/conf.d
tmpfs: {}
- type: volume
target: /tmp
tmpfs: {}
command: [ "/bin/sh", "-c", ". run_nginx.sh" ]
networks:
- radix
Expand All @@ -43,6 +53,7 @@ services:
auth:
image: quay.io/oauth2-proxy/oauth2-proxy:v7.6.0
container_name: radix-auth_container
read_only: true
environment:
# See the `radixconfig.yaml` file for a description of these settings
- OAUTH2_PROXY_CLIENT_ID=5687b237-eda3-4ec3-a2a1-023e85a2bd84
Expand Down
16 changes: 1 addition & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
</style>

<title>Radix Web Console</title>
<script type="text/javascript" src="/config/inject-env.js"></script>
</head>
<body>
<noscript>
Expand All @@ -71,20 +72,5 @@

<div id="root"></div>
<script type="module" src="./src/index.ts"></script>
<script>
window.RADIX_API_ENVIRONMENT = "${RADIX_API_ENVIRONMENT}";
window.RADIX_CLUSTER_BASE = "${RADIX_DNS_ZONE}";
window.RADIX_CLUSTERNAME = "${RADIX_CLUSTERNAME}";
window.RADIX_CLUSTER_TYPE = "${RADIX_CLUSTER_TYPE}";
window.RADIX_ENVIRONMENT = "${RADIX_ENVIRONMENT}";
window.CLUSTER_EGRESS_IPS = "${CLUSTER_EGRESS_IPS}";
window.CLUSTER_INGRESS_IPS = "${CLUSTER_INGRESS_IPS}";
window.OAUTH2_CLIENT_ID = "${OAUTH2_CLIENT_ID}";
window.OAUTH2_AUTHORITY = "${OAUTH2_AUTHORITY}";
window.SERVICENOW_PROXY_SCOPES = "${SERVICENOW_PROXY_SCOPES}"
window.SERVICENOW_PROXY_BASEURL = "${SERVICENOW_PROXY_BASEURL}"
window.CMDB_CI_URL = "${CMDB_CI_URL}"
window.CLUSTER_OIDC_ISSUER_URL = "${CLUSTER_OIDC_ISSUER_URL}"
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions proxy/run_nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ envsubst '
${SERVICENOW_PROXY_SCOPES}
${SERVICENOW_PROXY_BASEURL}
${CLUSTER_OIDC_ISSUER_URL}
' </app/index.html >/app/tmp.html
mv /app/tmp.html /app/index.html
' </app/config/inject-env.js >/app/tmp-inject-env.js
mv /app/tmp-inject-env.js /app/config/inject-env.js

# Substitute environment variables in the nginx.conf file using the values in the current container environment
envsubst '
Expand Down
15 changes: 15 additions & 0 deletions public/config/inject-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
window.injectEnv = {
RADIX_API_ENVIRONMENT: '${RADIX_API_ENVIRONMENT}',
RADIX_CLUSTER_BASE: '${RADIX_CLUSTER_BASE}',
RADIX_CLUSTERNAME: '${RADIX_CLUSTERNAME}',
RADIX_CLUSTER_TYPE: '${RADIX_CLUSTER_TYPE}',
RADIX_ENVIRONMENT: '${RADIX_ENVIRONMENT}',
CLUSTER_EGRESS_IPS: '${CLUSTER_EGRESS_IPS}',
CLUSTER_INGRESS_IPS: '${CLUSTER_INGRESS_IPS}',
OAUTH2_CLIENT_ID: '${OAUTH2_CLIENT_ID}',
OAUTH2_AUTHORITY: '${OAUTH2_AUTHORITY}',
SERVICENOW_PROXY_SCOPES: '${SERVICENOW_PROXY_SCOPES}',
SERVICENOW_PROXY_BASEURL: '${SERVICENOW_PROXY_BASEURL}',
CMDB_CI_URL: '${CMDB_CI_URL}',
CLUSTER_OIDC_ISSUER_URL: '${CLUSTER_OIDC_ISSUER_URL}',
};
14 changes: 14 additions & 0 deletions radixconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ spec:
from: release
components:
- name: web
readOnlyFileSystem: true
volumeMounts:
- name: tmp
path: /tmp
emptyDir:
sizeLimit: 1M
- name: nginxconfd
path: /etc/nginx/conf.d
emptyDir:
sizeLimit: 1M
- name: wwwconfig
path: /app/config
emptyDir:
sizeLimit: 1M
src: "."
ports:
- name: http
Expand Down
19 changes: 12 additions & 7 deletions src/utils/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as jsonConfig from '../../config.json';
import jsonConfig from '../../config.json' assert { type: 'json' };

function arrayTransformer(
delimiter = ','
Expand All @@ -17,16 +17,21 @@ const transformers: Partial<
SERVICENOW_PROXY_SCOPES: arrayTransformer(' '),
};

const injectEnvKey = 'injectEnv';

export const configVariables: Readonly<typeof jsonConfig> = Object.freeze(
Object.keys(jsonConfig)
.filter((key) => key !== 'default')
.reduce<typeof jsonConfig>((config, key: keyof typeof jsonConfig) => {
Object.keys(jsonConfig).reduce<typeof jsonConfig>(
(config, key: keyof typeof jsonConfig) => {
const value =
!window[key] || window[key].startsWith('${')
!window[injectEnvKey] ||
!window[injectEnvKey][key] ||
window[injectEnvKey][key].startsWith('${')
? jsonConfig[key]
: window[key];
: window[injectEnvKey][key];

config[key] = transformers[key] ? transformers[key](value) : value;
return config;
}, Object.create({}))
},
Object.create({})
)
);

0 comments on commit 9528dff

Please sign in to comment.