I have a local NPM/Yarn repository "verdaccio" running in a docker container, bound to my host machine at http://0.0.0.0:4873/.
I am trialling skaffold with minikube.
My Dockerfile config requires two build args:
ARG NPM_TOKEN
ARG PACKAGE_REPO_DOMAIN
Which are used in my .yarnrc.yml file:
yarnPath: .yarn/releases/yarn-3.2.0.cjs
nodeLinker: "node-modules"
npmRegistryServer: "http://${PACKAGE_REPO_DOMAIN}:4873/"
httpRetry: 10
httpTimeout: 100000
# networkConcurrency: 2
unsafeHttpWhitelist:
- "0.0.0.0"
- localhost
- verdaccio
- host.minikube.internal
- host.docker.internal
npmRegistries:
"http://${PACKAGE_REPO_DOMAIN}:4873":
npmAlwaysAuth: true
npmAuthToken: ${NPM_TOKEN}
The configured domain is host.minikube.internal
. Below is my skaffold yaml, notice I bound network to "host":
apiVersion: skaffold/v2beta28
kind: Config
build:
local:
push: false
artifacts:
- image: my-app
docker:
dockerfile: ./my-app/Dockerfile
target: dev
network: "host"
buildArgs:
NPM_TOKEN: "***REDACTED***"
PACKAGE_REPO_DOMAIN: "host.minikube.internal"
context: ../
sync:
manual:
- src: 'my-app/**/*.*'
dest: ./my-app
- src: './shared'
dest: './shared'
- src: '.yarn'
dest: '.yarn'
deploy:
helm:
releases:
- name: my-app
chartPath: ../../infrastructure/helm/charts/my-app
artifactOverrides:
image: my-app
imageStrategy:
fqn: {}
When running skaffold build
then it works and builds the image fine. However when running either skaffold dev
or skaffold run
then yarn install
hangs when building. This means that yarn's failing to reach the verdaccio local npm repository. I don't understand why though - surely it's still being built within the minikube environment and should use host.minikube.internal -> localhost ?
NB: I have remembered to also run this before skaffold (still fails):
skaffold config set --global local-cluster true
eval $(minikube -p minikube docker-env)
Edit
I have since made a minimum reproduction here: https://github.com/gitn00b1337/skaffold-verdaccio
Requires yarn, minikube + helm.
CD into the project, then:
$ sudo chmod -R a+rw ./verdaccio/storage
$ yarn install
$ minikube start
$ docker-compose up (seperate terminal)
$ skaffold config set --kube-context minikube local-cluster true
$ eval $(minikube -p minikube docker-env)
$ skaffold build # works
$ skaffold run # fails
On our project we had to do the following to make verdaccio work:
Add a new user:
npm adduser --registry http://localhost:4873/
Create an .npmrc
file in the shared module and in the service that imports the module with the following:
@my-app:registry=http://localhost:4873
strict-ssl=false
Publish the shared module verdaccio using yarn build && yarn publish
and then you should be able to see it in your browser if you navigate to
http://localhost:4873
Then install the shared module in the service using yarn install <shared-module>
.
I think the reason your setup is hanging is either its missing the .nmprc
file or its needs strict-ssl=false
Once you add that then hopefully when you do skaffold run
it will deploy to minikube