0

When I use the COPY command in my Dockerfile to overwrite a particular file (in this case I'm trying to change the alert in the SQLAlchemy Editor when it gets saved, just one of the changes I want to perform), the change is visible in the code and the docker container shell, but is not displayed when I run the code.

In the docker file I have added the copy command line, before the RUN command which was already in our dockerfile.

...
COPY actions.js /usr/local/lib/python3.6/site-packages/superset/static/assets/src/SqlLab/actions.js
RUN chmod +x /superset-init.sh

The file itself that I am trying to copy across is placed in the same directory as the Dockerfile as is required and the following changes are made (not extensive, this is just to pick up that the changes are actually being processed)

Before:

export function saveQuery(query) {
  const url = '/savedqueryviewapi/api/create';
  $.ajax({
    type: 'POST',
    url,
    data: query,
    success: () => notify.success(t('Your query was saved')),
    error: () => notify.error(t('Your query could not be saved')),
    dataType: 'json',
  });
  return { type: SAVE_QUERY };
}

After:

export function saveQuery(query) {
  const url = '/savedqueryviewapi/api/create';
  $.ajax({
    type: 'POST',
    url,
    data: query,
    success: () => notify.success(t('Your query was saved and stored')),
    error: () => notify.error(t('Your query could not be saved')),
    dataType: 'json',
  });
  return { type: SAVE_QUERY };
}

As mentioned I've tried to copy the code over using the docker COPY command, but this has not worked. It worked when copying over standard HTML files, but not these JS files.

COPY COMMAND

COPY actions.js /usr/local/lib/python3.6/site-packages/superset/static/assets/src/SqlLab/actions.js

If this works the alert should change and any other changes I make to the JS functions should be visible.

UPDATE

The solution may lie in adding nvm, node and npm to my dockerfile, so that changes to my Javascript files are watched.

Brent
  • 177
  • 2
  • 9
  • Can you explain further what you've done? Keep in mind that this copy process is run only **once** on building the container, not each time you run it – Nico Haase Jun 18 '19 at 14:55
  • Yes, I have taken that into account. I rebuild almost every time to ensure that changes are noted, and then even rebuilding with no cache once in a while as well. I'll add what more I've done in the main question. – Brent Jun 18 '19 at 14:57
  • Could you add what `superset-init.sh` does or its content? – Gonzalo Matheu Jun 18 '19 at 15:11
  • I can only describe what is done in ```superset-init.sh``` : 1. Sets container shell entry. 2. Checks the deployment environment. 3. Gets configuration files and Sets ENV vars. 4. Updates Favicon 5. Starts up Superset. – Brent Jun 18 '19 at 15:25
  • enter the container with `docker exec -it theidofyourcontainer sh` and check if the file is there and contains what you expect it to contain (you can get the id of the container using `docker ps`) – flagg19 Jun 18 '19 at 15:42
  • @flagg19 Thanks, however I have already checked and the change is present in container. The problem I am having as I described above is the actual outputting of the code when the app is running. – Brent Jun 18 '19 at 18:10
  • @Brent then maybe the file you are copying is not the one used by your application, maybe the container has multiple python versions? do some experiments like deleting that file inside `/superset-init.sh`, if it still works then that's clearly not the file being used – flagg19 Jun 19 '19 at 07:17

2 Answers2

0

So if the file in the container is ok (as you've said in the comment above) and you still can't see the changes on the app, then I can think of just one possible cause : have you cleared the cache or re-build the app in order to take it into account ?
Check the source code of the actual running app and you'll be fixed.

Marc ABOUCHACRA
  • 3,155
  • 12
  • 19
  • If by 'check the source code' you mean using ```docker ps and exec``` to go into the container, then I have tried this. I have also cleared the cache and rebuilt several times, none of these attempts saw the changes becoming visible. – Brent Jun 19 '19 at 10:16
0

Adding the following lines to my Dockerfile brought the changes through to the frontend.

RUN apt-get update && apt-get install -y \
  nano \
  curl \
...
# Install nodejs for custom build
# https://superset.incubator.apache.org/installation.html#making-your-own-build
# https://nodejs.org/en/download/package-manager/

RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
    && apt-get install -y nodejs

RUN cd ../usr/local/lib/python3.6/site-packages/superset/static/assets \
    && npm install \
    && npm ci \
    && npm run build \
    && rm -rf node_modules

As I understand, the issue was that the changes to my frontend were not being compiled. Add these lines in the build compiles the changes made to the JS or JSX files.

I added these additions by looking at the Dockerfile here: https://github.com/apache/incubator-superset/blob/master/contrib/docker/Dockerfile

I also had to add the package.json file, because the one that was present had invalid package lines.

COPY package.json /usr/local/lib/python3.6/site-packages/superset/static/assets/package.json
Brent
  • 177
  • 2
  • 9