fabric8-ui / fabric8-planner

https://fabric8-ui.github.io/fabric8-planner/
Apache License 2.0
26 stars 62 forks source link

Inconsistencies in locally generated and docker-hub F8UI deploy images #2368

Open debloper opened 6 years ago

debloper commented 6 years ago
  1. /usr/share/nginx/html contains a _config directory in CI images, whereas local builds have config directory
  2. The environment variables in _config/fabric8-ui.env.js are blank string in docker-hub images, where local one has weird values to them.

In locally built depoly image:

window.Fabric8UIEnv = {
  "kubernetesMode": "{{ .Env.KUBERNETES_MODE }}",
  "analyticsWriteKey": "{{ .Env.ANALYTICS_WRITE_KEY }}",
  "branding": "{{ .Env.BRANDING }}",
  "forgeApiUrl": "{{ .Env.FABRIC8_FORGE_API_URL }}",
  "openshiftConsoleUrl": "{{ .Env.OPENSHIFT_CONSOLE_URL }}",
  "openshiftProxiedApiServer": "{{ .Env.PROXIED_K8S_API_SERVER }}",
  "pipelinesNamespace": "{{ .Env.FABRIC8_PIPELINES_NAMESPACE }}",
  "recommenderApiUrl": "{{ .Env.FABRIC8_RECOMMENDER_API_URL }}",
  "ssoApiUrl": "{{ .Env.FABRIC8_SSO_API_URL }}",
  "statusApiUrl": "{{ .Env.FABRIC8_STATUS_API_URL }}",
  "witApiUrl": "{{ .Env.FABRIC8_WIT_API_URL }}",
  "authApiUrl": "{{ .Env.FABRIC8_AUTH_API_URL }}",  
  "tenantApiUrl": "{{ .Env.FABRIC8_TENANT_API_URL }}"
};

compared to, docker-hub deploy image:

window.Fabric8UIEnv = {
  "kubernetesMode": "",
  "analyticsWriteKey": "",
  "branding": "",
  "forgeApiUrl": "",
  "openshiftConsoleUrl": "",
  "openshiftProxiedApiServer": "",
  "pipelinesNamespace": "",
  "recommenderApiUrl": "",
  "ssoApiUrl": "",
  "statusApiUrl": "",
  "witApiUrl": "",
  "authApiUrl": "",  
  "tenantApiUrl": ""
};
debloper commented 6 years ago

In order to work out a list of necessary and sufficient env_vars for the deploy image to run, we need a few reference points to understand the pipeline where it seems to work.

In the 2 CI pipelines used in fabric8-ui repo, i.e. CICO and F8CI, they're as follows:

  1. CICO https://github.com/fabric8-ui/fabric8-ui/blob/master/cico_run_tests.sh results in:

    {
    host: 'localhost',
    port: 8080,
    ENV: 'production',
    HMR: false,
    FABRIC8_FORGE_API_URL: undefined,
    FABRIC8_WIT_API_URL: undefined,
    FABRIC8_REALM: undefined,
    FABRIC8_SSO_API_URL: undefined,
    FABRIC8_AUTH_API_URL: undefined,
    FABRIC8_RECOMMENDER_API_URL: 'http://api-bayesian.dev.rdu2c.fabric8.io/api/v1/',
    FABRIC8_FORGE_URL: undefined,
    FABRIC8_PIPELINES_NAMESPACE: undefined,
    PUBLIC_PATH: '/',
    BUILD_NUMBER: undefined,
    BUILD_TIMESTAMP: undefined,
    BUILD_VERSION: '0.0.0-development',
    FABRIC8_BRANDING: 'fabric8'
    }
  2. F8CI https://github.com/fabric8-ui/fabric8-ui/blob/master/release.groovy#L6-L11 results in:

    {
    host: 'localhost',
    port: 8080,
    ENV: 'production',
    HMR: false,
    FABRIC8_FORGE_API_URL: 'https://forge.api.prod-preview.openshift.io',
    FABRIC8_WIT_API_URL: 'https://api.prod-preview.openshift.io/api/',
    FABRIC8_REALM: 'fabric8',
    FABRIC8_SSO_API_URL: 'https://sso.prod-preview.openshift.io/',
    FABRIC8_AUTH_API_URL: 'https://auth.prod-preview.openshift.io/api/',
    FABRIC8_RECOMMENDER_API_URL: 'https://api-bayesian.dev.rdu2c.fabric8.io/api/v1/',
    FABRIC8_FORGE_URL: undefined,
    FABRIC8_PIPELINES_NAMESPACE: undefined,
    PUBLIC_PATH: '/',
    BUILD_NUMBER: undefined,
    BUILD_TIMESTAMP: undefined,
    BUILD_VERSION: '0.0.0-development',
    FABRIC8_BRANDING: 'fabric8'
    }

    It's important to notice, the artifacts built on CICO aren't meant to run the app, and the app is never validated to run as well. It's only purpose is to run the tests, and it does just that. Meaning, the configs from this cite can't be used as reference as it doesn't build into a functional app.

F8CI, on the other hand, is meant to build a functional app and it pushes the generated image to registry as well as deploys it to stage. However, it does so with some undocumented & hard-to-discover behind-the-scene-magic (which may or may not be) resulting in the image that doesn't work out of the box, as it'd commonly be expected to.

debloper commented 6 years ago

From the list of configs (not env-vars) used by the app, some don't need explicit evaluation (defaults), some aren't necessary to get the app running (optionals), only some are necessary (required).

Following is a draft grouping of configs to classify them based off of this:

NOTE: still unresolved whether the required configs mentioned here are sufficient for the app to run.

jarifibrahim commented 6 years ago

@debloper There aren't any inconsistencies between the config file and _config directory. Here's how it works in the container, The line https://github.com/fabric8-ui/fabric8-ui-openshift-nginx/blob/master/root/template.sh#L8 transforms each file in config directory into its respective file in the _config directory. The difference between the files is that the sed command translates the variable placeholders ({{ VAR }}) into environment variables (${VAR}).

The next line https://github.com/fabric8-ui/fabric8-ui-openshift-nginx/blob/master/root/template.sh#L9, actually substitutes the environment variable values in the file.

When you run fabric8-ui image as docker run fabric8-ui, you'll see

Templating /usr/share/nginx/html/config/fabric8-ui.env.js and saving as /usr/share/nginx/html/_config/fabric8-ui.env.js

----------------
window.Fabric8UIEnv = {
  "kubernetesMode": "",
  "analyticsWriteKey": "",
  "branding": "",
  "forgeApiUrl": "",
  "openshiftConsoleUrl": "",
  "openshiftProxiedApiServer": "",
  "pipelinesNamespace": "",
  "recommenderApiUrl": "",
  "ssoApiUrl": "",
  "statusApiUrl": "",
  "witApiUrl": "",
  "authApiUrl": "",  
  "tenantApiUrl": ""
};

But if you run this as docker run -e FABRIC8_WIT_API_URL="https://api.prod-preview.openshift.io" -e FABRIC8_AUTH_API_URL="https://auth.prod-preview.openshift.io" fabric8-ui You'll see

Templating /usr/share/nginx/html/config/fabric8-ui.env.js and saving as /usr/share/nginx/html/_config/fabric8-ui.env.js

----------------
window.Fabric8UIEnv = {
  "kubernetesMode": "",
  "analyticsWriteKey": "",
  "branding": "",
  "forgeApiUrl": "",
  "openshiftConsoleUrl": "",
  "openshiftProxiedApiServer": "",
  "pipelinesNamespace": "",
  "recommenderApiUrl": "",
  "ssoApiUrl": "",
  "statusApiUrl": "",
  "witApiUrl": "https://api.prod-preview.openshift.io",
  "authApiUrl": "https://auth.prod-preview.openshift.io",  
  "tenantApiUrl": ""
};
----------------

From the list of configs (not env-vars) used by the app, some don't need explicit evaluation (defaults), some aren't necessary to get the app running (optional), only some are necessary (required).

All the environment variables are optional as the defaults are set.

debloper commented 6 years ago

The point of this issue was, it wasn't happening as the way it should. You're explaining how it should.

Now, there can be two things right now:

Can't tell which one is it, and at thins point it might just be worth more to just ignore this whole planner-as-a-library-built-with-f8ui-creating-devops-bugs-whack-a-mole-nightmare and move on to standalone planner devops and focus more on making it better than what we have right now.