#Dagger is not updating .npmrc file

1 messages · Page 1 of 1 (latest)

gentle geode
#

Hello , I am stuck with below one issue for couple of weeks with no solution in mind. Any help is highly appreciated.
Here is my situation.
I have a python:3.11-slim docker image with necessary python packages stored in AWS ECR which is used as the base for setting up npm. Currently I use Jenkins job to call the dagger.
stage('Run Dagger Pipeline') {
steps {
script {
sh "bash pipelines/scripts/run_dagger.sh"
}
}
The issue is that I tried to execute the npm config , its not updating the .npmrc file. I have printed the contents before and after calling the command. Its same. Not sure what is going wrong. I have attached the reference code. (Line number 34 and 39 in the npm_build.py file I'm referring to) Please help.

heady lantern
#

Hi! Oof, sorry you're stuck for a couple weeks, glad you've asked for help!

Those calls are immutable, they don't share state. So when you do:

npmrc = await adp.with_exec(['cat', '.npmrc']).stdout()

xxx = await adp.with_exec([...]).stdout()

npmrc = await adp.with_exec(['cat', '.npmrc']).stdout()

Those commands are all getting forked off the same adp base container. As a matter of fact, the second cat .npmrc there should get the cached value from the first one because they produce the exact same API call.

The proper way to chain with multiple await like that, is to save the new container in a variable, before calling stdout, and using that on the next call:

# ok here because you're just debugging, don't want this exec in the container
npmrc = await adp.with_exec(['cat', '.npmrc']).stdout()

# keep replacing container with added changes
adp = adp.with_exec("npm config set --userconfig ./.npmrc registry https://xx/npm-hosted/".split(" "))
print(f"npm conf registry: {await adp.stdout()}")

adp = adp.with_exec("npm config set --userconfig ./.npmrc email xx@xx.com".split(" "))
print(f"npm conf email: {await adp.stdout()}")

adp = adp.with_exec("npm config set --userconfig ./.npmrc //xxx/npm-hosted/:_auth xxxx".split(" "))
print(f"npm conf auth : {await adp.stdout()}")

# debug
npmrc = await adp.with_exec(['cat', '.npmrc']).stdout()

Now both npmrc lines look the same but they're not because the adp instance has changed, with the added with_execs.