To confirm whether the tests specified in skaffold.yaml are run in a container or locally, I printed the node version.
>node --version
v18.12.1
I ran the same command in skaffold.yaml.
apiVersion: skaffold/v4beta2
kind: Config
metadata:
name: microservices-quiz-app
build:
artifacts:
- image: auth-img
context: auth
docker:
dockerfile: Dockerfile
sync:
manual:
- src: src/**/*.js
dest: .
test:
- image: auth-img
context: auth
custom:
- command: node --version
manifests:
rawYaml:
- auth/k8s/*.yml
- ingress-srv.yml
The phrasing in the documentation indicates it is run locally "It will run on the local machine". documentation
If I connect directly to the container built using auth-img after skaffold dev
, I see a different version.
Is there a way to run the tests in a container with the necessary dependencies (e.g. jest, supertest) to run the tests?
Why isn’t Skaffold using the image being tested; are we supposed to not include dev dependencies in the image?
FROM node:18-alpine
# ENV NODE_ENV=production
WORKDIR /app
COPY ["package.json", "package-lock.json*", "./"]
# RUN npm install --production
RUN npm install
COPY . .
# CMD ["npm", "start"]
CMD [ "npm", "run", "dev" ]
2
Answers
We can use docker to run a container using the generated image. Skaffold provides the variable
IMAGE
.Personally, I recommend using multi-stage build. Then you are not locked into a specific tool such as Skaffold.